Skip to content

Commit fc41556

Browse files
author
Orta Therox
authoredOct 9, 2020
Merge pull request #131 from microsoft/webpack_5
Adds tests for webpack 5
2 parents b9ec816 + ae54860 commit fc41556

File tree

10 files changed

+86
-36
lines changed

10 files changed

+86
-36
lines changed
 

‎.github/workflows/CI.yml

+2-36
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,6 @@ jobs:
1818
with:
1919
node-version: ${{ matrix.node-version }}
2020

21-
- name: Setup Testing Infra
22-
run: |
23-
cd test
24-
npm install
21+
- name: Run tests
22+
run: node ./test/runTests.js
2523

26-
- name: "CommonJS Test"
27-
run: |
28-
cd test/cjs
29-
npm run test
30-
31-
- name: "ES Modules Test"
32-
run: |
33-
cd test/esm-node-native
34-
npm run test
35-
if: ${{ matrix.node-version == '14.x' }}
36-
37-
- name: "Validate ES Modules == CommonJS"
38-
run: |
39-
cd test/validateModuleExportsMatchCommonJS
40-
npm run test
41-
if: ${{ matrix.node-version == '14.x' }}
42-
43-
- name: "Rollup Tree-shaking Test"
44-
run: |
45-
cd test/rollup-modules
46-
npm run test
47-
48-
- name: "Webpack Tree-shaking Test"
49-
run: |
50-
cd test/webpack-modules
51-
npm run test
52-
53-
- name: "Snowpack Tree-shaking Test"
54-
run: |
55-
cd test/snowpack-modules
56-
npm run test
57-
if: ${{ matrix.node-version == '14.x' }}

‎test/esm-node-native/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
"type": "module",
33
"scripts": {
44
"test": "node index.js"
5+
},
6+
"engines": {
7+
"node": "14"
58
}
69
}

‎test/runTests.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const { spawnSync } = require("child_process");
2+
const fs = require("fs");
3+
const path = require("path");
4+
const mainVersion = Number(process.version.replace("v","").split(".")[0])
5+
6+
// Loop through all the folders and run `npm test`
7+
8+
const blocklist = ["validateModuleExportsMatchCommonJS", "node_modules"];
9+
const filesInTest = fs.readdirSync(__dirname);
10+
const tests = filesInTest
11+
.filter((f) => fs.statSync(path.join(__dirname, f)).isDirectory())
12+
.filter((f) => !blocklist.includes(f));
13+
14+
// Support setting up the test node modules
15+
if (!filesInTest.includes("node_modules")) {
16+
console.log("Installing Deps...");
17+
spawnSync("npm", ["install"], { cwd: __dirname });
18+
console.log("Installed");
19+
}
20+
21+
const chalk = require("chalk").default;
22+
for (const test of tests) {
23+
console.log("---> " + chalk.bold(test));
24+
25+
const pgkJSON = require(path.join(__dirname, test, "package.json"));
26+
27+
// Allow skipping things which need a minimum of node 14 (es modules)
28+
if (pgkJSON.engines && pgkJSON.engines.node) {
29+
const minVersion = Number(pgkJSON.engines.node)
30+
if (minVersion > mainVersion) {
31+
console.log("Skipping")
32+
continue
33+
}
34+
}
35+
36+
// The webpack 5 tests have unique deps
37+
if (pgkJSON.dependencies || pgkJSON.devDependencies) {
38+
const nodeModsInstalled = fs.existsSync(path.join(__dirname, test, "node_modules"));
39+
if (!nodeModsInstalled) {
40+
spawnSync("npm", ["install"], { cwd: path.join(__dirname, test) });
41+
}
42+
}
43+
44+
// Run the test command
45+
const results = spawnSync("npm", ["test"], { cwd: path.join(__dirname, test) });
46+
console.log(results.stdout.toString())
47+
if (results.status) {
48+
console.log(chalk.bold.red("Error running test: ") + chalk.bold(test))
49+
console.log(results.stderr.toString())
50+
console.log(chalk.bold.red("^^^ Error running test: ") + chalk.bold(test))
51+
process.exitCode = results.status
52+
}
53+
}
54+

‎test/snowpack-modules/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33

44
"scripts": {
55
"test": "../node_modules/.bin/snowpack build; node build/index.js"
6+
},
7+
"engines": {
8+
"node": "14"
69
}
710
}
File renamed without changes.
File renamed without changes.

‎test/webpack-5-modules/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { __awaiter } from "tslib";
2+
if (typeof __awaiter !== "function") throw new Error("Missing expected helper __awaiter");

‎test/webpack-5-modules/package.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"scripts": {
3+
"test": "webpack && node build/main.js"
4+
},
5+
"devDependencies": {
6+
"tslib": "file:../..",
7+
"webpack": "5.0.0-rc.4",
8+
"webpack-cli": "3.3.12"
9+
}
10+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const path = require('path');
2+
3+
/** @type {import("webpack").Configuration} */
4+
const config = {
5+
mode: "production",
6+
entry: "./index",
7+
output: {
8+
path: path.join(process.cwd(), 'build')
9+
}
10+
}
11+
12+
module.exports = config

0 commit comments

Comments
 (0)
Please sign in to comment.