-
-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Adds test suite for config files
- Loading branch information
1 parent
03a2dec
commit 7e8c7df
Showing
27 changed files
with
1,507 additions
and
1,311 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
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
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,84 @@ | ||
const { build } = require('./lib/cli'); | ||
const { subject } = require('./lib/output'); | ||
|
||
const formats = ['cjs', 'esm']; | ||
|
||
const prerenderUrlFiles = [ | ||
'array.js', | ||
'stringified-array.js', | ||
'function-returning-array.js', | ||
'function-returning-stringified-array.js', | ||
]; | ||
|
||
const preactConfigFiles = [ | ||
'function.js', | ||
'object.js' | ||
]; | ||
|
||
describe('config files', () => { | ||
describe('prerender-urls', () => { | ||
it(`should load the 'prerender-urls.json' file`, async () => { | ||
let dir = await subject('multiple-config-files'); | ||
|
||
const logSpy = jest.spyOn(process.stdout, 'write'); | ||
|
||
await build(dir); | ||
|
||
expect(logSpy).not.toHaveBeenCalledWith( | ||
expect.stringContaining('Failed to load prerenderUrls file, using default!') | ||
); | ||
}); | ||
|
||
formats.forEach(moduleFormat => { | ||
prerenderUrlFiles.forEach(dataFormat => { | ||
it(`should load the '${dataFormat}' file in ${moduleFormat}`, async () => { | ||
let dir = await subject('multiple-config-files'); | ||
|
||
const logSpy = jest.spyOn(process.stdout, 'write'); | ||
|
||
await build(dir, { prerenderUrls: `prerender/${moduleFormat}/${dataFormat}` }); | ||
|
||
expect(logSpy).not.toHaveBeenCalledWith( | ||
expect.stringContaining('Failed to load prerenderUrls file, using default!') | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
formats.forEach(moduleFormat => { | ||
it(`should fail to load malformed prerender-urls data in ${moduleFormat}`, async () => { | ||
let dir = await subject('multiple-config-files'); | ||
|
||
const logSpy = jest.spyOn(process.stdout, 'write'); | ||
|
||
await build(dir, { prerenderUrls: `prerender/${moduleFormat}/returns-bad-json.js` }); | ||
|
||
expect(logSpy).toHaveBeenCalledWith( | ||
expect.stringContaining('Failed to load prerenderUrls file, using default!') | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('preact.config', () => { | ||
formats.forEach(moduleFormat => { | ||
preactConfigFiles.forEach(dataFormat => { | ||
it(`should load the '${dataFormat}' file in ${moduleFormat}`, async () => { | ||
let dir = await subject('multiple-config-files'); | ||
|
||
await expect( | ||
build(dir, { config: `preactConfig/${moduleFormat}/${dataFormat}` }) | ||
).resolves.not.toThrow(); | ||
}); | ||
}); | ||
|
||
it(`should fail to load malformed config data in ${moduleFormat}`, async () => { | ||
let dir = await subject('multiple-config-files'); | ||
|
||
await expect(build(dir, { config: `preactConfig/${moduleFormat}/returns-bad-config.js` })) | ||
.rejects | ||
.toThrow('Failed to load preact-cli config!'); | ||
}); | ||
}); | ||
}); | ||
}); |
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
19 changes: 19 additions & 0 deletions
19
packages/cli/tests/subjects/multiple-config-files/index.js
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,19 @@ | ||
import { h, Component } from 'preact'; | ||
import { Router } from 'preact-router'; | ||
import Home from './routes/home'; | ||
|
||
export default class App extends Component { | ||
handleRoute = e => { | ||
this.currentUrl = e.url; | ||
}; | ||
|
||
render(props) { | ||
return ( | ||
<div id="app"> | ||
<Router url={props.url} onChange={this.handleRoute} {...props}> | ||
<Home path="/" /> | ||
</Router> | ||
</div> | ||
); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/cli/tests/subjects/multiple-config-files/package.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,4 @@ | ||
{ | ||
"private": true, | ||
"name": "preact-config" | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/cli/tests/subjects/multiple-config-files/preactConfig/cjs/function.js
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,3 @@ | ||
module.exports = function (config, env, helpers) { | ||
|
||
}; |
3 changes: 3 additions & 0 deletions
3
packages/cli/tests/subjects/multiple-config-files/preactConfig/cjs/object.js
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,3 @@ | ||
module.exports = { | ||
webpack(config, env, helpers) {} | ||
}; |
2 changes: 2 additions & 0 deletions
2
packages/cli/tests/subjects/multiple-config-files/preactConfig/cjs/returns-bad-config.js
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,2 @@ | ||
module.exports = { | ||
webpack(config, env, helpers) {} |
3 changes: 3 additions & 0 deletions
3
packages/cli/tests/subjects/multiple-config-files/preactConfig/esm/function.js
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,3 @@ | ||
export default function (config, env, helpers) { | ||
|
||
}; |
3 changes: 3 additions & 0 deletions
3
packages/cli/tests/subjects/multiple-config-files/preactConfig/esm/object.js
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,3 @@ | ||
export default { | ||
webpack (config, env, helpers) {} | ||
}; |
2 changes: 2 additions & 0 deletions
2
packages/cli/tests/subjects/multiple-config-files/preactConfig/esm/returns-bad-config.js
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,2 @@ | ||
export default { | ||
webpack (config, env, helpers) {} |
8 changes: 8 additions & 0 deletions
8
packages/cli/tests/subjects/multiple-config-files/prerender-urls.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,8 @@ | ||
[ | ||
{ | ||
"url": "/" | ||
}, | ||
{ | ||
"url": "/custom" | ||
} | ||
] |
8 changes: 8 additions & 0 deletions
8
packages/cli/tests/subjects/multiple-config-files/prerender/cjs/array.js
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,8 @@ | ||
module.exports = [ | ||
{ | ||
"url": "/" | ||
}, | ||
{ | ||
"url": "/custom" | ||
} | ||
]; |
8 changes: 8 additions & 0 deletions
8
packages/cli/tests/subjects/multiple-config-files/prerender/cjs/function-returning-array.js
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,8 @@ | ||
module.exports = () => [ | ||
{ | ||
"url": "/" | ||
}, | ||
{ | ||
"url": "/custom" | ||
} | ||
]; |
8 changes: 8 additions & 0 deletions
8
...ests/subjects/multiple-config-files/prerender/cjs/function-returning-stringified-array.js
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,8 @@ | ||
module.exports = () => `[ | ||
{ | ||
"url": "/" | ||
}, | ||
{ | ||
"url": "/custom" | ||
} | ||
]`; |
8 changes: 8 additions & 0 deletions
8
packages/cli/tests/subjects/multiple-config-files/prerender/cjs/returns-bad-json.js
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,8 @@ | ||
module.exports = () => `[ | ||
{ | ||
"url": "/" | ||
}, | ||
{ | ||
"url": "/custom" | ||
} | ||
`; |
8 changes: 8 additions & 0 deletions
8
packages/cli/tests/subjects/multiple-config-files/prerender/cjs/stringified-array.js
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,8 @@ | ||
module.exports = `[ | ||
{ | ||
"url": "/" | ||
}, | ||
{ | ||
"url": "/custom" | ||
} | ||
]`; |
8 changes: 8 additions & 0 deletions
8
packages/cli/tests/subjects/multiple-config-files/prerender/esm/array.js
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,8 @@ | ||
export default [ | ||
{ | ||
"url": "/" | ||
}, | ||
{ | ||
"url": "/custom" | ||
} | ||
]; |
8 changes: 8 additions & 0 deletions
8
packages/cli/tests/subjects/multiple-config-files/prerender/esm/function-returning-array.js
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,8 @@ | ||
export default () => [ | ||
{ | ||
"url": "/" | ||
}, | ||
{ | ||
"url": "/custom" | ||
} | ||
]; |
8 changes: 8 additions & 0 deletions
8
...ests/subjects/multiple-config-files/prerender/esm/function-returning-stringified-array.js
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,8 @@ | ||
export default () => `[ | ||
{ | ||
"url": "/" | ||
}, | ||
{ | ||
"url": "/custom" | ||
} | ||
]`; |
8 changes: 8 additions & 0 deletions
8
packages/cli/tests/subjects/multiple-config-files/prerender/esm/returns-bad-json.js
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,8 @@ | ||
export default () => `[ | ||
{ | ||
"url": "/" | ||
}, | ||
{ | ||
"url": "/custom" | ||
} | ||
`; |
8 changes: 8 additions & 0 deletions
8
packages/cli/tests/subjects/multiple-config-files/prerender/esm/stringified-array.js
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,8 @@ | ||
export default `[ | ||
{ | ||
"url": "/" | ||
}, | ||
{ | ||
"url": "/custom" | ||
} | ||
]`; |
3 changes: 3 additions & 0 deletions
3
packages/cli/tests/subjects/multiple-config-files/routes/home.css
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,3 @@ | ||
.home { | ||
background: red; | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/cli/tests/subjects/multiple-config-files/routes/home.js
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,3 @@ | ||
import './home.css'; | ||
|
||
export default () => <div>Home</div>; |
Oops, something went wrong.