Skip to content

Commit

Permalink
test(plugin-webpack): minimal test (#1061)
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m authored Sep 25, 2020
1 parent 590cbfd commit 3e9de92
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"jest": "^26.2.2",
"lerna": "^3.22.1",
"prettier": "^2.0.5",
"strip-ansi": "^6.0.0",
"typescript": "^4.0.0"
},
"prettier": {
Expand Down
68 changes: 68 additions & 0 deletions plugins/plugin-webpack/test/__snapshots__/plugin.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`@snowpack/plugin-webpack minimal - all options: console.log 1`] = `
Asset Size Chunks Chunk Names
asset-manifest.json XXX bytes [emitted]
index-0.js XXX bytes 0 [emitted] index
index-0.js.map XXX bytes 0 [emitted] [dev] index
webpack-runtime-1.js 1.5 KiB 1 [emitted] webpack-runtime
webpack-runtime-1.js.map 8.06 KiB 1 [emitted] [dev] webpack-runtime
`;

exports[`@snowpack/plugin-webpack minimal - all options: fs.writeFile 1`] = `
FILE: stubs/minimal/asset-manifest.json
{
"index.js": "/index-0.js",
"index.js.map": "/index-0.js.map",
"webpack-runtime.js": "/webpack-runtime-1.js",
"webpack-runtime.js.map": "/webpack-runtime-1.js.map"
}
--------------------------------------------------------------------------------
FILE: stubs/minimal/index-0.js
(window.webpackJsonp=window.webpackJsonp||[]).push([[0],[function(o,n){console.log("test")}],[[0,1]]]);
//# sourceMappingURL=index-0.js.map
--------------------------------------------------------------------------------
FILE: stubs/minimal/index-0.js.map
{"version":3,"sources":["webpack:///./index.js"],"names":["console","log"],"mappings":"uEAAAA,QAAQC,IAAI,U","file":"index-0.js","sourcesContent":["console.log('test');\\n"],"sourceRoot":""}
--------------------------------------------------------------------------------
FILE: stubs/minimal/webpack-runtime-1.js
!function(e){function r(r){for(var n,l,f=r[0],i=r[1],a=r[2],c=0,s=[];c<f.length;c++)l=f[c],Object.prototype.hasOwnProperty.call(o,l)&&o[l]&&s.push(o[l][0]),o[l]=0;for(n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n]);for(p&&p(r);s.length;)s.shift()();return u.push.apply(u,a||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,f=1;f<t.length;f++){var i=t[f];0!==o[i]&&(n=!1)}n&&(u.splice(r--,1),e=l(l.s=t[0]))}return e}var n={},o={1:0},u=[];function l(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,l),t.l=!0,t.exports}l.m=e,l.c=n,l.d=function(e,r,t){l.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},l.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},l.t=function(e,r){if(1&r&&(e=l(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(l.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)l.d(t,n,function(r){return e[r]}.bind(null,n));return t},l.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return l.d(r,"a",r),r},l.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},l.p="/";var f=window.webpackJsonp=window.webpackJsonp||[],i=f.push.bind(f);f.push=r,f=f.slice();for(var a=0;a<f.length;a++)r(f[a]);var p=i;t()}([]);
//# sourceMappingURL=webpack-runtime-1.js.map
--------------------------------------------------------------------------------
FILE: stubs/minimal/webpack-runtime-1.js.map
{"version":3,"sources":["webpack:///webpack/bootstrap"],"names":["webpackJsonpCallback","data","moduleId","chunkId","chunkIds","moreModules","executeModules","i","resolves","length","Object","prototype","hasOwnProperty","call","installedChunks","push","modules","parentJsonpFunction","shift","deferredModules","apply","checkDeferredModules","result","deferredModule","fulfilled","j","depId","splice","__webpack_require__","s","installedModules","1","exports","module","l","m","c","d","name","getter","o","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","p","jsonpArray","window","oldJsonpFunction","slice"],"mappings":"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","file":"webpack-runtime-1.js","sourcesContent":[" \\t// install a JSONP callback for chunk loading\\n \\tfunction webpackJsonpCallback(data) {\\n \\t\\tvar chunkIds = data[0];\\n \\t\\tvar moreModules = data[1];\\n \\t\\tvar executeModules = data[2];\\n\\n \\t\\t// add \\"moreModules\\" to the modules object,\\n \\t\\t// then flag all \\"chunkIds\\" as loaded and fire callback\\n \\t\\tvar moduleId, chunkId, i = 0, resolves = [];\\n \\t\\tfor(;i < chunkIds.length; i++) {\\n \\t\\t\\tchunkId = chunkIds[i];\\n \\t\\t\\tif(Object.prototype.hasOwnProperty.call(installedChunks, chunkId) && installedChunks[chunkId]) {\\n \\t\\t\\t\\tresolves.push(installedChunks[chunkId][0]);\\n \\t\\t\\t}\\n \\t\\t\\tinstalledChunks[chunkId] = 0;\\n \\t\\t}\\n \\t\\tfor(moduleId in moreModules) {\\n \\t\\t\\tif(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {\\n \\t\\t\\t\\tmodules[moduleId] = moreModules[moduleId];\\n \\t\\t\\t}\\n \\t\\t}\\n \\t\\tif(parentJsonpFunction) parentJsonpFunction(data);\\n\\n \\t\\twhile(resolves.length) {\\n \\t\\t\\tresolves.shift()();\\n \\t\\t}\\n\\n \\t\\t// add entry modules from loaded chunk to deferred list\\n \\t\\tdeferredModules.push.apply(deferredModules, executeModules || []);\\n\\n \\t\\t// run deferred modules when all chunks ready\\n \\t\\treturn checkDeferredModules();\\n \\t};\\n \\tfunction checkDeferredModules() {\\n \\t\\tvar result;\\n \\t\\tfor(var i = 0; i < deferredModules.length; i++) {\\n \\t\\t\\tvar deferredModule = deferredModules[i];\\n \\t\\t\\tvar fulfilled = true;\\n \\t\\t\\tfor(var j = 1; j < deferredModule.length; j++) {\\n \\t\\t\\t\\tvar depId = deferredModule[j];\\n \\t\\t\\t\\tif(installedChunks[depId] !== 0) fulfilled = false;\\n \\t\\t\\t}\\n \\t\\t\\tif(fulfilled) {\\n \\t\\t\\t\\tdeferredModules.splice(i--, 1);\\n \\t\\t\\t\\tresult = __webpack_require__(__webpack_require__.s = deferredModule[0]);\\n \\t\\t\\t}\\n \\t\\t}\\n\\n \\t\\treturn result;\\n \\t}\\n\\n \\t// The module cache\\n \\tvar installedModules = {};\\n\\n \\t// object to store loaded and loading chunks\\n \\t// undefined = chunk not loaded, null = chunk preloaded/prefetched\\n \\t// Promise = chunk loading, 0 = chunk loaded\\n \\tvar installedChunks = {\\n \\t\\t1: 0\\n \\t};\\n\\n \\tvar deferredModules = [];\\n\\n \\t// The require function\\n \\tfunction __webpack_require__(moduleId) {\\n\\n \\t\\t// Check if module is in cache\\n \\t\\tif(installedModules[moduleId]) {\\n \\t\\t\\treturn installedModules[moduleId].exports;\\n \\t\\t}\\n \\t\\t// Create a new module (and put it into the cache)\\n \\t\\tvar module = installedModules[moduleId] = {\\n \\t\\t\\ti: moduleId,\\n \\t\\t\\tl: false,\\n \\t\\t\\texports: {}\\n \\t\\t};\\n\\n \\t\\t// Execute the module function\\n \\t\\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\\n\\n \\t\\t// Flag the module as loaded\\n \\t\\tmodule.l = true;\\n\\n \\t\\t// Return the exports of the module\\n \\t\\treturn module.exports;\\n \\t}\\n\\n\\n \\t// expose the modules object (__webpack_modules__)\\n \\t__webpack_require__.m = modules;\\n\\n \\t// expose the module cache\\n \\t__webpack_require__.c = installedModules;\\n\\n \\t// define getter function for harmony exports\\n \\t__webpack_require__.d = function(exports, name, getter) {\\n \\t\\tif(!__webpack_require__.o(exports, name)) {\\n \\t\\t\\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\\n \\t\\t}\\n \\t};\\n\\n \\t// define __esModule on exports\\n \\t__webpack_require__.r = function(exports) {\\n \\t\\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\\n \\t\\t\\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\\n \\t\\t}\\n \\t\\tObject.defineProperty(exports, '__esModule', { value: true });\\n \\t};\\n\\n \\t// create a fake namespace object\\n \\t// mode & 1: value is a module id, require it\\n \\t// mode & 2: merge all properties of value into the ns\\n \\t// mode & 4: return value when already ns object\\n \\t// mode & 8|1: behave like require\\n \\t__webpack_require__.t = function(value, mode) {\\n \\t\\tif(mode & 1) value = __webpack_require__(value);\\n \\t\\tif(mode & 8) return value;\\n \\t\\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\\n \\t\\tvar ns = Object.create(null);\\n \\t\\t__webpack_require__.r(ns);\\n \\t\\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\\n \\t\\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\\n \\t\\treturn ns;\\n \\t};\\n\\n \\t// getDefaultExport function for compatibility with non-harmony modules\\n \\t__webpack_require__.n = function(module) {\\n \\t\\tvar getter = module && module.__esModule ?\\n \\t\\t\\tfunction getDefault() { return module['default']; } :\\n \\t\\t\\tfunction getModuleExports() { return module; };\\n \\t\\t__webpack_require__.d(getter, 'a', getter);\\n \\t\\treturn getter;\\n \\t};\\n\\n \\t// Object.prototype.hasOwnProperty.call\\n \\t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\\n\\n \\t// __webpack_public_path__\\n \\t__webpack_require__.p = \\"/\\";\\n\\n \\tvar jsonpArray = window[\\"webpackJsonp\\"] = window[\\"webpackJsonp\\"] || [];\\n \\tvar oldJsonpFunction = jsonpArray.push.bind(jsonpArray);\\n \\tjsonpArray.push = webpackJsonpCallback;\\n \\tjsonpArray = jsonpArray.slice();\\n \\tfor(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]);\\n \\tvar parentJsonpFunction = oldJsonpFunction;\\n\\n\\n \\t// run deferred modules from other chunks\\n \\tcheckDeferredModules();\\n"],"sourceRoot":""}
`;

exports[`@snowpack/plugin-webpack minimal - all options: fs.writeFileSync 1`] = `
FILE: stubs/minimal/index.html
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Minimal test</title></head><body><script src="/webpack-runtime-1.js"></script><script src="/index-0.js"></script></body></html>
`;
exports[`@snowpack/plugin-webpack minimal - no options: console.log 1`] = `
Asset Size Chunks Chunk Names
js/index.67855721cb4d5774d8dd.js XXX bytes 0 [emitted] [immutable] index
js/webpack-runtime.8705824766b06b056b73.js 1.46 KiB 1 [emitted] [immutable] webpack-runtime
`;
exports[`@snowpack/plugin-webpack minimal - no options: fs.writeFile 1`] = `
FILE: stubs/minimal/js/index.67855721cb4d5774d8dd.js
(window.webpackJsonp=window.webpackJsonp||[]).push([[0],[function(o,n){console.log("test")}],[[0,1]]]);
--------------------------------------------------------------------------------
FILE: stubs/minimal/js/webpack-runtime.8705824766b06b056b73.js
!function(e){function r(r){for(var n,l,f=r[0],i=r[1],a=r[2],c=0,s=[];c<f.length;c++)l=f[c],Object.prototype.hasOwnProperty.call(o,l)&&o[l]&&s.push(o[l][0]),o[l]=0;for(n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n]);for(p&&p(r);s.length;)s.shift()();return u.push.apply(u,a||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,f=1;f<t.length;f++){var i=t[f];0!==o[i]&&(n=!1)}n&&(u.splice(r--,1),e=l(l.s=t[0]))}return e}var n={},o={1:0},u=[];function l(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,l),t.l=!0,t.exports}l.m=e,l.c=n,l.d=function(e,r,t){l.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},l.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},l.t=function(e,r){if(1&r&&(e=l(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(l.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)l.d(t,n,function(r){return e[r]}.bind(null,n));return t},l.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return l.d(r,"a",r),r},l.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},l.p="/";var f=window.webpackJsonp=window.webpackJsonp||[],i=f.push.bind(f);f.push=r,f=f.slice();for(var a=0;a<f.length;a++)r(f[a]);var p=i;t()}([]);
`;
exports[`@snowpack/plugin-webpack minimal - no options: fs.writeFileSync 1`] = `
FILE: stubs/minimal/index.html
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Minimal test</title></head><body><script src="/js/webpack-runtime.8705824766b06b056b73.js"></script><script src="/js/index.67855721cb4d5774d8dd.js"></script></body></html>
`;
78 changes: 78 additions & 0 deletions plugins/plugin-webpack/test/plugin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const path = require('path');
const fs = require('fs');

const plugin = require('../plugin');
const {getSnowpackPluginOutputSnapshotSerializer} = require('./serializer');

describe('@snowpack/plugin-webpack', () => {
beforeEach(() => {
expect.addSnapshotSerializer(getSnowpackPluginOutputSnapshotSerializer(__dirname));

const originalWriteFileSync = fs.writeFileSync;
fs.writeFileSync = jest
.fn()
.mockName('fs.writeFileSync')
.mockImplementation((path, ...args) => {
if (path.startsWith(__dirname)) return;

// write files outside of the current folder
originalWriteFileSync(path, ...args);
});

const originalWriteFile = fs.writeFile;
fs.writeFile = jest
.fn()
.mockName('fs.writeFile')
.mockImplementation((path, ...args) => {
if (path.startsWith(__dirname)) {
const callback = args.pop();
callback();
return;
}

// write files outside of the current folder
originalWriteFile(path, ...args);
});

console.log = jest.fn().mockName('console.log');
});

it('minimal - no options', async () => {
const pluginInstance = plugin({
buildOptions: {},
});

await pluginInstance.optimize({
buildDirectory: path.resolve(__dirname, 'stubs/minimal/'),
});

expect(fs.writeFileSync).toMatchSnapshot('fs.writeFileSync');
expect(fs.writeFile).toMatchSnapshot('fs.writeFile');
expect(console.log).toMatchSnapshot('console.log');
});

it('minimal - all options', async () => {
const pluginInstance = plugin(
{
buildOptions: {},
},
{
sourceMap: true,
outputPattern: {
js: '[name]-[id].js',
},
extendConfig: (config) => config,
manifest: true,
htmlMinifierOptions: true,
},
);

await pluginInstance.optimize({
buildDirectory: path.resolve(__dirname, 'stubs/minimal/'),
});

expect(fs.writeFileSync).toMatchSnapshot('fs.writeFileSync');
expect(fs.writeFile).toMatchSnapshot('fs.writeFile');
expect(console.log).toMatchSnapshot('console.log');
});
});
71 changes: 71 additions & 0 deletions plugins/plugin-webpack/test/serializer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
module.exports = {
getSnowpackPluginOutputSnapshotSerializer,
};

const {format} = require('util');

const strpAnsi = require('strip-ansi');

/**
* Serializer of written files as well as console.log output.
*
* Both file contents and log output is normalized to account for differences
* in UNIX and Windows systems.
*
* @param string basePath all files written outside this path will be ignored (usually set to __dirname)
*/
function getSnowpackPluginOutputSnapshotSerializer(basePath) {
return {
serialize(value) {
if (value.getMockName() === 'console.log') {
return value.mock.calls
.map(toSingleArgument)
.map(toNoralizedByteSize)
.map(removeColors)
.join('\n');
}

const calls = value.mock.calls
.filter(isLocal)
.map(toPathAndStringContent.bind(null, basePath));
return calls
.sort((a, b) => {
return a[0] < b[0] ? -1 : 1;
})
.map(([path, content]) => {
return `FILE: ${path}\n${content}`;
})
.join(
'\n\n--------------------------------------------------------------------------------\n\n',
);
},

test(value) {
return value && value.mock;
},
};
}

function toPathAndStringContent(basePath, [path, content]) {
const shortPath = path.replace(basePath, '').substr(1);
// unix-ify folder separators for Windows
const normalizedPath = shortPath.replace(/\\/g, '/');
// unix-ify new lines
const normalizedContent = content.toString().replace(/(\\r\\n)/g, '\\n');
return [normalizedPath, normalizedContent];
}

function toSingleArgument([output, ...args]) {
return format(output, ...args);
}
function toNoralizedByteSize(output) {
return output.replace(/(\s{2,})\d+ bytes/g, '$1XXX bytes');
}

function removeColors(output) {
return strpAnsi(output);
}

function isLocal(call) {
return call[0].startsWith(__dirname);
}
10 changes: 10 additions & 0 deletions plugins/plugin-webpack/test/stubs/minimal/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Minimal test</title>
</head>
<body>
<script type="module" src="index.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions plugins/plugin-webpack/test/stubs/minimal/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('test');
4 changes: 4 additions & 0 deletions plugins/plugin-webpack/test/stubs/minimal/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "plugin-webpack-test-minimal",
"main": "src/index.js"
}

1 comment on commit 3e9de92

@vercel
Copy link

@vercel vercel bot commented on 3e9de92 Sep 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.