This repository has been archived by the owner on Jan 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5688c70
commit a40e6b4
Showing
28 changed files
with
899 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Run `WRITE_EXPECTED_ROUTES=1 yarn test` to rewrite expected `routes.json` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
Empty file.
Empty file.
6 changes: 6 additions & 0 deletions
6
lib/plugins/fs-routes/__test__/presets/ignore-garbage/routes.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
{ | ||
"path": "/page", | ||
"component": "#base/page.vue" | ||
} | ||
] |
Empty file.
Empty file.
Empty file.
Empty file.
24 changes: 24 additions & 0 deletions
24
lib/plugins/fs-routes/__test__/presets/nested-children/routes.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[ | ||
{ | ||
"path": "/foo", | ||
"component": "#base/foo.vue", | ||
"children": [ | ||
{ | ||
"path": "bar", | ||
"component": "#base/foo/bar.vue", | ||
"children": [ | ||
{ | ||
"path": "baz", | ||
"component": "#base/foo/bar/baz.vue", | ||
"children": [ | ||
{ | ||
"path": "qux", | ||
"component": "#base/foo/bar/baz/qux.vue" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |
1 change: 1 addition & 0 deletions
1
lib/plugins/fs-routes/__test__/presets/nested/foo/bar/baz/qux.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
{ | ||
"path": "/foo/bar/baz/qux", | ||
"component": "#base/foo/bar/baz/qux.vue" | ||
} | ||
] |
Empty file.
Empty file.
30 changes: 30 additions & 0 deletions
30
lib/plugins/fs-routes/__test__/presets/typical/routes.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[ | ||
{ | ||
"path": "/", | ||
"component": "#base/index.vue" | ||
}, | ||
{ | ||
"path": "/foo", | ||
"component": "#base/foo.vue" | ||
}, | ||
{ | ||
"path": "/user", | ||
"component": "#base/user.vue", | ||
"children": [ | ||
{ | ||
"path": ":user", | ||
"component": "#base/user/[user].vue", | ||
"children": [ | ||
{ | ||
"path": "", | ||
"component": "#base/user/[user]/index.vue" | ||
}, | ||
{ | ||
"path": "friends", | ||
"component": "#base/user/[user]/friends.vue" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const path = require('path') | ||
const fs = require('fs-extra') | ||
const { collectRoutes } = require('../routes-template') | ||
|
||
async function testCollectRoutes(dir, opts) { | ||
const fullDir = path.resolve(__dirname, dir) | ||
const routes = await collectRoutes({ | ||
dir: fullDir, | ||
componentPrefix: '#base', | ||
basePath: '/', | ||
options: { | ||
match: /\.vue$/ | ||
}, | ||
...opts | ||
}) | ||
const expectedRoutesFile = path.join(fullDir, 'routes.json') | ||
if (process.env.WRITE_EXPECTED_ROUTES) { | ||
await fs.writeFile(expectedRoutesFile, JSON.stringify(routes, null, 2)) | ||
} else { | ||
expect(routes).toEqual(await fs.readJson(expectedRoutesFile)) | ||
} | ||
} | ||
|
||
describe('Presets', () => { | ||
for (const preset of fs.readdirSync(path.resolve(__dirname, 'presets'))) { | ||
test(preset, () => testCollectRoutes(path.join('presets', preset))) | ||
} | ||
}) | ||
|
||
test('Typescript', () => | ||
testCollectRoutes('special/typescript', { | ||
options: { | ||
match: /\.(vue|ts)$/ | ||
} | ||
})) | ||
|
||
test('Custom base path', () => | ||
testCollectRoutes('special/custom-base-path', { | ||
basePath: '/some' | ||
})) |
Empty file.
6 changes: 6 additions & 0 deletions
6
lib/plugins/fs-routes/__test__/special/custom-base-path/routes.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
{ | ||
"path": "/some/foo", | ||
"component": "#base/foo.vue" | ||
} | ||
] |
Empty file.
Empty file.
10 changes: 10 additions & 0 deletions
10
lib/plugins/fs-routes/__test__/special/typescript/routes.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[ | ||
{ | ||
"path": "/", | ||
"component": "#base/index.vue" | ||
}, | ||
{ | ||
"path": "/page", | ||
"component": "#base/page.ts" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.