index.js (1752B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 const path = require("path"); 6 const util = require("util"); 7 const _ = require("lodash"); 8 const webpack = require("webpack"); 9 10 const TARGET_NAME = "webpack4"; 11 12 module.exports = exports = async function(tests, dirname) { 13 const fixtures = []; 14 for (const [name, input] of tests) { 15 if (/babel-/.test(name)) { 16 continue; 17 } 18 19 const testFnName = _.camelCase(`${TARGET_NAME}-${name}`); 20 const evalMaps = name.match(/-eval/); 21 22 console.log(`Building ${TARGET_NAME} test ${name}`); 23 24 const scriptPath = path.join(dirname, "output", TARGET_NAME, `${name}.js`); 25 await util.promisify(webpack)({ 26 mode: "development", 27 context: path.dirname(input), 28 entry: `./${path.basename(input)}`, 29 output: { 30 path: path.dirname(scriptPath), 31 filename: path.basename(scriptPath), 32 33 devtoolModuleFilenameTemplate: `${TARGET_NAME}://./${name}/[resource-path]`, 34 35 libraryTarget: "var", 36 library: testFnName, 37 libraryExport: "default" 38 }, 39 devtool: evalMaps ? "eval-source-map" : "source-map", 40 module: { 41 rules: [ 42 { 43 test: /\.tsx?$/, 44 exclude: /node_modules/, 45 loader: require.resolve("ts-loader"), 46 options: {} 47 } 48 ].filter(Boolean) 49 } 50 }); 51 52 fixtures.push({ 53 name, 54 testFnName, 55 scriptPath, 56 assets: [scriptPath, evalMaps ? null : `${scriptPath}.map`].filter( 57 Boolean 58 ) 59 }); 60 } 61 62 return { 63 target: TARGET_NAME, 64 fixtures 65 }; 66 };