Skip to content

Commit 91d7501

Browse files
committed
test: Improved config format test suite
1 parent b9613c1 commit 91d7501

File tree

5 files changed

+23
-25
lines changed

5 files changed

+23
-25
lines changed

packages/cli/tests/config.test.js renamed to packages/cli/tests/config-formats.test.js

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const { join } = require('path');
2+
const { access } = require('fs').promises;
13
const { build } = require('./lib/cli');
24
const { subject } = require('./lib/output');
35

@@ -17,33 +19,27 @@ describe('config files', () => {
1719
it(`should load the 'prerender-urls.json' file`, async () => {
1820
let dir = await subject('multiple-config-files');
1921

20-
const logSpy = jest.spyOn(process.stdout, 'write');
21-
2222
await build(dir);
2323

24-
expect(logSpy).not.toHaveBeenCalledWith(
25-
expect.stringContaining(
26-
'Failed to load prerenderUrls file, using default!'
27-
)
28-
);
24+
expect(await access(join(dir, 'build/index.html'))).toBeUndefined();
25+
expect(
26+
await access(join(dir, 'build/custom/index.html'))
27+
).toBeUndefined();
2928
});
3029

3130
formats.forEach(moduleFormat => {
3231
prerenderUrlFiles.forEach(dataFormat => {
3332
it(`should load the '${dataFormat}' file in ${moduleFormat}`, async () => {
3433
let dir = await subject('multiple-config-files');
3534

36-
const logSpy = jest.spyOn(process.stdout, 'write');
37-
3835
await build(dir, {
3936
prerenderUrls: `prerenderUrls/${moduleFormat}/${dataFormat}`,
4037
});
4138

42-
expect(logSpy).not.toHaveBeenCalledWith(
43-
expect.stringContaining(
44-
'Failed to load prerenderUrls file, using default!'
45-
)
46-
);
39+
expect(await access(join(dir, 'build/index.html'))).toBeUndefined();
40+
expect(
41+
await access(join(dir, 'build/custom/index.html'))
42+
).toBeUndefined();
4743
});
4844
});
4945
});
@@ -55,17 +51,11 @@ describe('config files', () => {
5551
it(`should load the '${dataFormat}' file in ${moduleFormat}`, async () => {
5652
let dir = await subject('multiple-config-files');
5753

58-
const logSpy = jest.spyOn(process.stdout, 'write');
59-
6054
await build(dir, {
6155
config: `preactConfig/${moduleFormat}/${dataFormat}`,
6256
});
6357

64-
expect(logSpy).not.toHaveBeenCalledWith(
65-
expect.stringContaining(
66-
'Failed to load preact-cli config file, using default!'
67-
)
68-
);
58+
expect(await access(join(dir, 'build/bundle.js'))).toBeUndefined();
6959
});
7060
});
7161
});
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
module.exports = function () {};
1+
module.exports = function (config) {
2+
config.output.filename = '[name].js';
3+
};
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module.exports = {
2-
webpack() {},
2+
webpack(config) {
3+
config.output.filename = '[name].js';
4+
},
35
};
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export default function () {}
1+
export default function (config) {
2+
config.output.filename = '[name].js';
3+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export default {
2-
webpack() {},
2+
webpack(config) {
3+
config.output.filename = '[name].js';
4+
},
35
};

0 commit comments

Comments
 (0)