Skip to content

Commit

Permalink
test: Improved config format test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Mar 9, 2022
1 parent b9613c1 commit 91d7501
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { join } = require('path');
const { access } = require('fs').promises;
const { build } = require('./lib/cli');
const { subject } = require('./lib/output');

Expand All @@ -17,33 +19,27 @@ describe('config files', () => {
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!'
)
);
expect(await access(join(dir, 'build/index.html'))).toBeUndefined();
expect(
await access(join(dir, 'build/custom/index.html'))
).toBeUndefined();
});

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: `prerenderUrls/${moduleFormat}/${dataFormat}`,
});

expect(logSpy).not.toHaveBeenCalledWith(
expect.stringContaining(
'Failed to load prerenderUrls file, using default!'
)
);
expect(await access(join(dir, 'build/index.html'))).toBeUndefined();
expect(
await access(join(dir, 'build/custom/index.html'))
).toBeUndefined();
});
});
});
Expand All @@ -55,17 +51,11 @@ describe('config files', () => {
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, {
config: `preactConfig/${moduleFormat}/${dataFormat}`,
});

expect(logSpy).not.toHaveBeenCalledWith(
expect.stringContaining(
'Failed to load preact-cli config file, using default!'
)
);
expect(await access(join(dir, 'build/bundle.js'))).toBeUndefined();
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module.exports = function () {};
module.exports = function (config) {
config.output.filename = '[name].js';
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module.exports = {
webpack() {},
webpack(config) {
config.output.filename = '[name].js';
},
};
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export default function () {}
export default function (config) {
config.output.filename = '[name].js';
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export default {
webpack() {},
webpack(config) {
config.output.filename = '[name].js';
},
};

0 comments on commit 91d7501

Please sign in to comment.