Skip to content

Commit

Permalink
test(webpack-plugin): Test report output
Browse files Browse the repository at this point in the history
  • Loading branch information
vio committed Feb 17, 2024
1 parent eacddbb commit 4ad9c34
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 104 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
const path = require('path');
const webpack4 = require('webpack4'); // eslint-disable-line
const MemoryFS = require('memory-fs');
const { advanceTo } = require('jest-date-mock');

jest.mock('webpack', () => require('./node_modules/webpack4')); // eslint-disable-line

const config = require('./app/webpack.config');

advanceTo(new Date(2020, 10, 30));

jest.setTimeout(10 * 1000);

describe('webpack plugin package', () => {
test('webpack4', (done) => {
const fs = new MemoryFS();

expect.assertions(3);

const compiler = webpack4(config);
compiler.outputFileSystem = new MemoryFS();
compiler.outputFileSystem = fs;

compiler.run((error, stats) => {
expect(error).toEqual(null);
expect(stats.hasErrors()).toBe(false);
expect(stats.toJson({ source: false, assets: true }).assets).toMatchSnapshot();
const report = fs.readFileSync(path.join(__dirname, './dist/bundle-stats.html'), 'utf-8');
expect(report).toBeTruthy();
done();
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
const path = require('path');
const webpack5 = require('webpack');
const MemoryFS = require('memory-fs');
const { advanceTo } = require('jest-date-mock');
const { set } = require('lodash');

const config = require('./app/webpack.config');

advanceTo(new Date(2020, 10, 30));

jest.setTimeout(10 * 1000);

describe('webpack plugin package', () => {
test('webpack5', (done) => {
const fs = new MemoryFS();
expect.assertions(3);

const compiler = webpack5(config);
compiler.outputFileSystem = new MemoryFS();
compiler.outputFileSystem = fs;

compiler.run((error, stats) => {
expect(error).toEqual(null);
expect(stats.hasErrors()).toBe(false);

// Set bundle-stats.html size to 0 to ignore size changes
const { assets } = stats.toJson({ source: false, assets: true });
set(assets, '[0].size', 0);
set(assets, '[0].info.size', 0);

expect(assets).toMatchSnapshot();
const report = fs.readFileSync(path.join(__dirname, './dist/bundle-stats.html'), 'utf-8');
expect(report).toBeTruthy();
done();
});
});
Expand Down

0 comments on commit 4ad9c34

Please sign in to comment.