From 584f7d9aab840b516cb25ba9813ee74b7fc58ad7 Mon Sep 17 00:00:00 2001 From: Fabian Ehrentraud Date: Sat, 20 Jul 2019 08:16:17 +0200 Subject: [PATCH] feat: moved postTransformPublicPath tests to own file --- ...ostTransformPublicPath-option.test.js.snap | 82 +++++++++ .../publicPath-option.test.js.snap | 81 -------- test/postTransformPublicPath-option.test.js | 173 ++++++++++++++++++ test/publicPath-option.test.js | 172 ----------------- 4 files changed, 255 insertions(+), 253 deletions(-) create mode 100644 test/__snapshots__/postTransformPublicPath-option.test.js.snap create mode 100644 test/postTransformPublicPath-option.test.js diff --git a/test/__snapshots__/postTransformPublicPath-option.test.js.snap b/test/__snapshots__/postTransformPublicPath-option.test.js.snap new file mode 100644 index 0000000..17e1e99 --- /dev/null +++ b/test/__snapshots__/postTransformPublicPath-option.test.js.snap @@ -0,0 +1,82 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`when applied with \`postTransformPublicPath\` option matches snapshot for appending to input parameter value 1`] = ` +Object { + "assets": Array [ + "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + ], + "source": "module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\" + \\"/test\\";", +} +`; + +exports[`when applied with \`postTransformPublicPath\` option matches snapshot for returned input parameter value without modification 1`] = ` +Object { + "assets": Array [ + "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + ], + "source": "module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", +} +`; + +exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{Function}\` value matches snapshot for appending to input parameter value 1`] = ` +Object { + "assets": Array [ + "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + ], + "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\" + \\"?test=test\\";", +} +`; + +exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{Function}\` value matches snapshot for prefixing with __webpack_public_path__ 1`] = ` +Object { + "assets": Array [ + "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + ], + "source": "module.exports = __webpack_public_path__ + \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", +} +`; + +exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{Function}\` value matches snapshot for prefixing with string 1`] = ` +Object { + "assets": Array [ + "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + ], + "source": "module.exports = \\"path_prefix/\\" + \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", +} +`; + +exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{Function}\` value matches snapshot for returned input parameter value without modification 1`] = ` +Object { + "assets": Array [ + "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + ], + "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", +} +`; + +exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{String}\` value matches snapshot for appending to input parameter value 1`] = ` +Object { + "assets": Array [ + "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + ], + "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\" + \\"?test=test\\";", +} +`; + +exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{String}\` value matches snapshot for prefixing with __webpack_public_path__ 1`] = ` +Object { + "assets": Array [ + "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + ], + "source": "module.exports = __webpack_public_path__ + \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", +} +`; + +exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{String}\` value matches snapshot for returned input parameter value without modification 1`] = ` +Object { + "assets": Array [ + "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", + ], + "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", +} +`; diff --git a/test/__snapshots__/publicPath-option.test.js.snap b/test/__snapshots__/publicPath-option.test.js.snap index 8de4858..676eeba 100644 --- a/test/__snapshots__/publicPath-option.test.js.snap +++ b/test/__snapshots__/publicPath-option.test.js.snap @@ -1,86 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`when applied with \`postTransformPublicPath\` option matches snapshot for appending to input parameter value 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\" + \\"/test\\";", -} -`; - -exports[`when applied with \`postTransformPublicPath\` option matches snapshot for returned input parameter value without modification 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; - -exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{Function}\` value matches snapshot for appending to input parameter value 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\" + \\"?test=test\\";", -} -`; - -exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{Function}\` value matches snapshot for prefixing with __webpack_public_path__ 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; - -exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{Function}\` value matches snapshot for prefixing with string 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"path_prefix/\\" + \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; - -exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{Function}\` value matches snapshot for returned input parameter value without modification 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; - -exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{String}\` value matches snapshot for appending to input parameter value 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\" + \\"?test=test\\";", -} -`; - -exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{String}\` value matches snapshot for prefixing with __webpack_public_path__ 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = __webpack_public_path__ + \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; - -exports[`when applied with \`publicPath\` and \`postTransformPublicPath\` option \`{String}\` value matches snapshot for returned input parameter value without modification 1`] = ` -Object { - "assets": Array [ - "9c87cbf3ba33126ffd25ae7f2f6bbafb.png", - ], - "source": "module.exports = \\"public_path/9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\";", -} -`; - exports[`when applied with \`publicPath\` option matches snapshot for \`{Function}\` value 1`] = ` Object { "assets": Array [ diff --git a/test/postTransformPublicPath-option.test.js b/test/postTransformPublicPath-option.test.js new file mode 100644 index 0000000..d673e02 --- /dev/null +++ b/test/postTransformPublicPath-option.test.js @@ -0,0 +1,173 @@ +import webpack from './helpers/compiler'; + +describe('when applied with `postTransformPublicPath` option', () => { + it('matches snapshot for returned input parameter value without modification', async () => { + const config = { + loader: { + test: /(png|jpg|svg)/, + options: { + postTransformPublicPath: (p) => p, + }, + }, + }; + + const stats = await webpack('fixture.js', config); + const [module] = stats.toJson().modules; + const { assets, source } = module; + + expect({ assets, source }).toMatchSnapshot(); + }); + + it('matches snapshot for appending to input parameter value', async () => { + const config = { + loader: { + test: /(png|jpg|svg)/, + options: { + postTransformPublicPath: (p) => `${p} + "/test"`, + }, + }, + }; + + const stats = await webpack('fixture.js', config); + const [module] = stats.toJson().modules; + const { assets, source } = module; + + expect({ assets, source }).toMatchSnapshot(); + }); +}); + +describe('when applied with `publicPath` and `postTransformPublicPath` option', () => { + describe('`{String}` value', () => { + it('matches snapshot for returned input parameter value without modification', async () => { + const config = { + loader: { + test: /(png|jpg|svg)/, + options: { + publicPath: 'public_path/', + postTransformPublicPath: (p) => p, + }, + }, + }; + + const stats = await webpack('fixture.js', config); + const [module] = stats.toJson().modules; + const { assets, source } = module; + + expect({ assets, source }).toMatchSnapshot(); + }); + + it('matches snapshot for appending to input parameter value', async () => { + const config = { + loader: { + test: /(png|jpg|svg)/, + options: { + publicPath: 'public_path/', + postTransformPublicPath: (p) => `${p} + "?test=test"`, + }, + }, + }; + + const stats = await webpack('fixture.js', config); + const [module] = stats.toJson().modules; + const { assets, source } = module; + + expect({ assets, source }).toMatchSnapshot(); + }); + + it('matches snapshot for prefixing with __webpack_public_path__', async () => { + const config = { + loader: { + test: /(png|jpg|svg)/, + options: { + publicPath: 'public_path/', + postTransformPublicPath: (p) => `__webpack_public_path__ + ${p}`, + }, + }, + }; + + const stats = await webpack('fixture.js', config); + const [module] = stats.toJson().modules; + const { assets, source } = module; + + expect({ assets, source }).toMatchSnapshot(); + }); + }); + + describe('`{Function}` value', () => { + it('matches snapshot for returned input parameter value without modification', async () => { + const config = { + loader: { + test: /(png|jpg|svg)/, + options: { + publicPath(url) { + return `public_path/${url}`; + }, + postTransformPublicPath: (p) => p, + }, + }, + }; + + const stats = await webpack('fixture.js', config); + const [module] = stats.toJson().modules; + const { assets, source } = module; + + expect({ assets, source }).toMatchSnapshot(); + }); + + it('matches snapshot for appending to input parameter value', async () => { + const config = { + loader: { + test: /(png|jpg|svg)/, + options: { + publicPath(url) { + return `public_path/${url}`; + }, + postTransformPublicPath: (p) => `${p} + "?test=test"`, + }, + }, + }; + + const stats = await webpack('fixture.js', config); + const [module] = stats.toJson().modules; + const { assets, source } = module; + + expect({ assets, source }).toMatchSnapshot(); + }); + + it('matches snapshot for prefixing with string', async () => { + const config = { + loader: { + test: /(png|jpg|svg)/, + options: { + publicPath: 'public_path/', + postTransformPublicPath: (p) => `"path_prefix/" + ${p}`, + }, + }, + }; + + const stats = await webpack('fixture.js', config); + const [module] = stats.toJson().modules; + const { assets, source } = module; + + expect({ assets, source }).toMatchSnapshot(); + }); + + it('matches snapshot for prefixing with __webpack_public_path__', async () => { + const config = { + loader: { + test: /(png|jpg|svg)/, + options: { + publicPath: 'public_path/', + postTransformPublicPath: (p) => `__webpack_public_path__ + ${p}`, + }, + }, + }; + + const stats = await webpack('fixture.js', config); + const [module] = stats.toJson().modules; + const { assets, source } = module; + + expect({ assets, source }).toMatchSnapshot(); + }); + }); +}); diff --git a/test/publicPath-option.test.js b/test/publicPath-option.test.js index 44ecbe1..6980fb2 100644 --- a/test/publicPath-option.test.js +++ b/test/publicPath-option.test.js @@ -127,175 +127,3 @@ describe('when applied with `publicPath` option', () => { expect({ assets, source }).toMatchSnapshot(); }); }); - -describe('when applied with `postTransformPublicPath` option', () => { - it('matches snapshot for returned input parameter value without modification', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - postTransformPublicPath: (p) => p, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); - }); - - it('matches snapshot for appending to input parameter value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - postTransformPublicPath: (p) => `${p} + "/test"`, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); - }); -}); - -describe('when applied with `publicPath` and `postTransformPublicPath` option', () => { - describe('`{String}` value', () => { - it('matches snapshot for returned input parameter value without modification', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath: 'public_path/', - postTransformPublicPath: (p) => p, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); - }); - - it('matches snapshot for appending to input parameter value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath: 'public_path/', - postTransformPublicPath: (p) => `${p} + "?test=test"`, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); - }); - - it('matches snapshot for prefixing with __webpack_public_path__', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath: 'public_path/', - postTransformPublicPath: (p) => `__webpack_public_path__ + ${p}`, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); - }); - }); - - describe('`{Function}` value', () => { - it('matches snapshot for returned input parameter value without modification', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath(url) { - return `public_path/${url}`; - }, - postTransformPublicPath: (p) => p, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); - }); - - it('matches snapshot for appending to input parameter value', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath(url) { - return `public_path/${url}`; - }, - postTransformPublicPath: (p) => `${p} + "?test=test"`, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); - }); - - it('matches snapshot for prefixing with string', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath: 'public_path/', - postTransformPublicPath: (p) => `"path_prefix/" + ${p}`, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); - }); - - it('matches snapshot for prefixing with __webpack_public_path__', async () => { - const config = { - loader: { - test: /(png|jpg|svg)/, - options: { - publicPath: 'public_path/', - postTransformPublicPath: (p) => `__webpack_public_path__ + ${p}`, - }, - }, - }; - - const stats = await webpack('fixture.js', config); - const [module] = stats.toJson().modules; - const { assets, source } = module; - - expect({ assets, source }).toMatchSnapshot(); - }); - }); -});