-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Parameterize the test suite to run tests on multiple webpack versions with describe.each * Run the (failing) tests on Webpack 5 * Switch the tests to test by reading from the memory filesystem which works on both Webpack 4 and Webpack 5 The Sources returned in the stats.compilation on Webpack 5 don't support reading their contents. So, let's just read the written output, which is a slightly more thorough test anyways. The snapshots didn't need to be updated so I think this is working well. * Add Webpack 5 support Uses the new processAssets compiler hook to avoid deprecation warnings and undefined methods. * refactor: added getFile util method for tests * refactor: minor filter addition and WP5/4 comments * chore: added peerDependencies that specify Webpack 4 and 5 requirement * chore: changed webpack4 to webpack to satisfy peerdeps * refactor: minify-plugin organization * fix: flatMap to assert input is array * feat: added hash update * feat: add minimize to stats in webpack5 * style: prettier Co-authored-by: Harry Brundage <harry.brundage@gmail.com>
- Loading branch information
1 parent
3517c7e
commit c651c4f
Showing
9 changed files
with
2,015 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,93 @@ | ||
const webpack = require('webpack') | ||
const build = require('./build') | ||
const { ESBuildMinifyPlugin } = require('../src') | ||
const webpack4 = require('webpack') | ||
const webpack5 = require('webpack5') | ||
const { build, getFile } = require('./utils') | ||
const fixtures = require('./fixtures') | ||
|
||
describe('Loader', () => { | ||
test('js', async () => { | ||
const stats = await build(fixtures.js) | ||
describe.each([ | ||
['Webpack 4', webpack4], | ||
['Webpack 5', webpack5], | ||
])('%s', (_name, webpack) => { | ||
describe('Loader', () => { | ||
test('js', async () => { | ||
const stats = await build(webpack, fixtures.js) | ||
|
||
const { assets } = stats.compilation | ||
expect(assets['index.js'].source()).toMatchSnapshot() | ||
}) | ||
|
||
test('tsx', async () => { | ||
const stats = await build(fixtures.tsx, (config) => { | ||
config.module.rules.push({ | ||
test: /\.tsx$/, | ||
loader: 'esbuild-loader', | ||
options: { | ||
loader: 'tsx', | ||
}, | ||
}) | ||
expect(getFile(stats, '/dist/index.js')).toMatchSnapshot() | ||
}) | ||
|
||
const { assets } = stats.compilation | ||
expect(assets['index.js'].source()).toMatchSnapshot() | ||
}) | ||
}) | ||
test('tsx', async () => { | ||
const stats = await build(webpack, fixtures.tsx, (config) => { | ||
config.module.rules.push({ | ||
test: /\.tsx$/, | ||
loader: 'esbuild-loader', | ||
options: { | ||
loader: 'tsx', | ||
}, | ||
}) | ||
}) | ||
|
||
// Targets | ||
test('target', async () => { | ||
const stats = await build(fixtures.target, (config) => { | ||
config.module.rules[0].options = { | ||
target: 'es2015', | ||
} | ||
expect(getFile(stats, '/dist/index.js')).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
const { assets } = stats.compilation | ||
expect(assets['index.js'].source()).toMatchSnapshot() | ||
}) | ||
|
||
describe('Source-map', () => { | ||
test('source-map eval', async () => { | ||
const stats = await build(fixtures.js, (config) => { | ||
config.devtool = 'eval-source-map' | ||
// Targets | ||
test('target', async () => { | ||
const stats = await build(webpack, fixtures.target, (config) => { | ||
config.module.rules[0].options = { | ||
target: 'es2015', | ||
} | ||
}) | ||
|
||
const { assets } = stats.compilation | ||
expect(assets['index.js'].source()).toMatchSnapshot() | ||
expect(getFile(stats, '/dist/index.js')).toMatchSnapshot() | ||
}) | ||
|
||
test('source-map inline', async () => { | ||
const stats = await build(fixtures.js, (config) => { | ||
config.devtool = 'inline-source-map' | ||
describe('Source-map', () => { | ||
test('source-map eval', async () => { | ||
const stats = await build(webpack, fixtures.js, (config) => { | ||
config.devtool = 'eval-source-map' | ||
}) | ||
|
||
const { assets } = stats.compilation | ||
expect(getFile(stats, '/dist/index.js')).toMatchSnapshot() | ||
}) | ||
|
||
const { assets } = stats.compilation | ||
expect(assets['index.js'].source()).toMatchSnapshot() | ||
}) | ||
test('source-map inline', async () => { | ||
const stats = await build(webpack, fixtures.js, (config) => { | ||
config.devtool = 'inline-source-map' | ||
}) | ||
|
||
test('source-map file', async () => { | ||
const stats = await build(fixtures.js, (config) => { | ||
config.devtool = 'source-map' | ||
const { assets } = stats.compilation | ||
expect(getFile(stats, '/dist/index.js')).toMatchSnapshot() | ||
}) | ||
|
||
const { assets } = stats.compilation | ||
expect(assets['index.js'].source()).toMatchSnapshot() | ||
expect(assets['index.js.map'].source()).toMatchSnapshot() | ||
}) | ||
test('source-map file', async () => { | ||
const stats = await build(webpack, fixtures.js, (config) => { | ||
config.devtool = 'source-map' | ||
}) | ||
|
||
test('source-map plugin', async () => { | ||
const stats = await build(fixtures.js, (config) => { | ||
delete config.devtool | ||
config.plugins.push(new webpack.SourceMapDevToolPlugin({})) | ||
const { assets } = stats.compilation | ||
expect(getFile(stats, '/dist/index.js')).toMatchSnapshot() | ||
expect(getFile(stats, '/dist/index.js.map')).toMatchSnapshot() | ||
}) | ||
|
||
const { assets } = stats.compilation | ||
expect(assets['index.js'].source()).toMatchSnapshot() | ||
test('source-map plugin', async () => { | ||
const stats = await build(webpack, fixtures.js, (config) => { | ||
delete config.devtool | ||
config.plugins.push(new webpack.SourceMapDevToolPlugin({})) | ||
}) | ||
|
||
expect(getFile(stats, '/dist/index.js')).toMatchSnapshot() | ||
}) | ||
}) | ||
}) | ||
|
||
test('webpack magic comments', async () => { | ||
const stats = await build(fixtures.webpackMagicComments) | ||
test('webpack magic comments', async () => { | ||
const stats = await build(webpack, fixtures.webpackMagicComments) | ||
|
||
const { assets } = stats.compilation | ||
expect(assets['index.js'].source()).toMatchSnapshot() | ||
expect(assets).toHaveProperty(['named-chunk-foo.js']) | ||
expect(assets['named-chunk-foo.js'].source()).toMatchSnapshot() | ||
expect(assets).toHaveProperty(['named-chunk-bar.js']) | ||
expect(assets['named-chunk-bar.js'].source()).toMatchSnapshot() | ||
const { assets } = stats.compilation | ||
expect(getFile(stats, '/dist/index.js')).toMatchSnapshot() | ||
expect(assets).toHaveProperty(['named-chunk-foo.js']) | ||
expect(getFile(stats, '/dist/named-chunk-foo.js')).toMatchSnapshot() | ||
expect(assets).toHaveProperty(['named-chunk-bar.js']) | ||
expect(getFile(stats, '/dist/named-chunk-bar.js')).toMatchSnapshot() | ||
}) | ||
}) |
Oops, something went wrong.