Skip to content

Commit

Permalink
Add tests for compression:none + compression:brotli, make tests idemp…
Browse files Browse the repository at this point in the history
…otent
  • Loading branch information
developit committed Jan 29, 2021
1 parent b921279 commit 29043cb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
18 changes: 17 additions & 1 deletion test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`size-plugin should display the size of a multiple output files 1`] = `
"
bundle.js ⏤ [32m1.07 kB[39m (+598 B)
bundle.js ⏤ [1m[32m1.07 kB[39m[22m ([31m+1.07 kB[39m)
1.*****.chunk.js ⏤ 102 B (+102 B)
2.*****.chunk.js ⏤ 137 B (+137 B)
"
Expand All @@ -29,3 +29,19 @@ exports[`size-plugin should show size deltas for subsequent builds 1`] = `
2.*****.chunk.js ⏤ 303 B (+166 B)
"
`;

exports[`size-plugin should support {compression:"brotli"} 1`] = `
"
bundle.js ⏤ 922 B (+922 B)
1.*****.chunk.js ⏤ 75 B (+75 B)
2.*****.chunk.js ⏤ 108 B (+108 B)
"
`;

exports[`size-plugin should support {compression:"none"} 1`] = `
"
bundle.js ⏤ 2.19 kB (+2.19 kB)
1.*****.chunk.js ⏤ 99 B (+99 B)
2.*****.chunk.js ⏤ 146 B (+146 B)
"
`;
21 changes: 18 additions & 3 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function clearDist () {
await fs.remove(path.resolve(process.cwd(), 'size-plugin.json'));
}

beforeAll(clearDist);
beforeEach(clearDist);
afterAll(clearDist);

const consoleLog = jest.spyOn(console, 'log');
Expand Down Expand Up @@ -61,6 +61,9 @@ describe('size-plugin', () => {
});

it('should show size deltas for subsequent builds', async () => {
await compile('fixtures/splits/index.js', withSizePlugin);
consoleLog.mockReset();

const info = await compile('fixtures/splits/index-alt.js', withSizePlugin);
expect(info.assets).toHaveLength(3);

Expand All @@ -70,8 +73,6 @@ describe('size-plugin', () => {
});

it('should respect output.filename / output.chunkFilename', async () => {
await clearDist();

const info = await compile('fixtures/splits/index.js', config => {
withSizePlugin(config);
config.output.filename = 'js-[name].[contenthash].js';
Expand All @@ -85,4 +86,18 @@ describe('size-plugin', () => {

expect(consoleLog.mock.calls[0][0]).toMatchSnapshot();
});

it('should support {compression:"none"}', async () => {
await compile('fixtures/splits/index.js', config => {
config.plugins.push(new SizePlugin({ compression: 'none' }));
});
expect(consoleLog.mock.calls[0][0]).toMatchSnapshot();
});

it('should support {compression:"brotli"}', async () => {
await compile('fixtures/splits/index.js', config => {
config.plugins.push(new SizePlugin({ compression: 'brotli' }));
});
expect(consoleLog.mock.calls[0][0]).toMatchSnapshot();
});
});

0 comments on commit 29043cb

Please sign in to comment.