From de1e5bfd31d664ee0bfc6eff165e1ecb6ce71d06 Mon Sep 17 00:00:00 2001 From: Vio Date: Sat, 17 Feb 2024 16:17:28 +0100 Subject: [PATCH] test(webpack-plugin): Replace snapshot testing with file output test --- .../webpack-plugin-webpack-4.test.js.snap | 28 ---------- .../webpack-plugin-webpack-5.test.js.snap | 53 ------------------- .../package/webpack-plugin-webpack-4.test.js | 14 ++--- .../package/webpack-plugin-webpack-5.test.js | 19 ++----- 4 files changed, 12 insertions(+), 102 deletions(-) delete mode 100644 packages/webpack-plugin/test/package/__snapshots__/webpack-plugin-webpack-4.test.js.snap delete mode 100644 packages/webpack-plugin/test/package/__snapshots__/webpack-plugin-webpack-5.test.js.snap diff --git a/packages/webpack-plugin/test/package/__snapshots__/webpack-plugin-webpack-4.test.js.snap b/packages/webpack-plugin/test/package/__snapshots__/webpack-plugin-webpack-4.test.js.snap deleted file mode 100644 index f17c48fb8a..0000000000 --- a/packages/webpack-plugin/test/package/__snapshots__/webpack-plugin-webpack-4.test.js.snap +++ /dev/null @@ -1,28 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`webpack plugin package webpack4 1`] = ` -[ - { - "chunkNames": [], - "chunks": [], - "emitted": true, - "info": {}, - "isOverSizeLimit": undefined, - "name": "bundle-stats.html", - "size": 0, - }, - { - "chunkNames": [ - "main", - ], - "chunks": [ - 0, - ], - "emitted": true, - "info": {}, - "isOverSizeLimit": undefined, - "name": "main.js", - "size": 956, - }, -] -`; diff --git a/packages/webpack-plugin/test/package/__snapshots__/webpack-plugin-webpack-5.test.js.snap b/packages/webpack-plugin/test/package/__snapshots__/webpack-plugin-webpack-5.test.js.snap deleted file mode 100644 index aa6f1bc09b..0000000000 --- a/packages/webpack-plugin/test/package/__snapshots__/webpack-plugin-webpack-5.test.js.snap +++ /dev/null @@ -1,53 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`webpack plugin package webpack5 1`] = ` -[ - { - "auxiliaryChunkIdHints": [], - "auxiliaryChunkNames": [], - "auxiliaryChunks": [], - "cached": false, - "chunkIdHints": [], - "chunkNames": [], - "chunks": [], - "comparedForEmit": false, - "emitted": true, - "filteredRelated": undefined, - "info": { - "development": true, - "size": 0, - }, - "isOverSizeLimit": false, - "name": "bundle-stats.html", - "related": {}, - "size": 0, - "type": "asset", - }, - { - "auxiliaryChunkIdHints": [], - "auxiliaryChunkNames": [], - "auxiliaryChunks": [], - "cached": false, - "chunkIdHints": [], - "chunkNames": [ - "main", - ], - "chunks": [ - 590, - ], - "comparedForEmit": false, - "emitted": true, - "filteredRelated": undefined, - "info": { - "javascriptModule": false, - "minimized": true, - "size": 27, - }, - "isOverSizeLimit": false, - "name": "main.js", - "related": {}, - "size": 27, - "type": "asset", - }, -] -`; diff --git a/packages/webpack-plugin/test/package/webpack-plugin-webpack-4.test.js b/packages/webpack-plugin/test/package/webpack-plugin-webpack-4.test.js index 47db9e186f..5e820994a4 100644 --- a/packages/webpack-plugin/test/package/webpack-plugin-webpack-4.test.js +++ b/packages/webpack-plugin/test/package/webpack-plugin-webpack-4.test.js @@ -1,26 +1,26 @@ +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 +jest.setTimeout(10 * 1000); 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(); }); }); diff --git a/packages/webpack-plugin/test/package/webpack-plugin-webpack-5.test.js b/packages/webpack-plugin/test/package/webpack-plugin-webpack-5.test.js index 25791f58d7..fba6cdd2e7 100644 --- a/packages/webpack-plugin/test/package/webpack-plugin-webpack-5.test.js +++ b/packages/webpack-plugin/test/package/webpack-plugin-webpack-5.test.js @@ -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(); }); });