Skip to content

Commit ff0fd42

Browse files
Test @babel/runtime behavior with Webpack and old Node.js
1 parent 0dffed9 commit ff0fd42

16 files changed

Lines changed: 1711 additions & 122 deletions

File tree

‎.eslintignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ packages/babel-parser/test/expressions
2626
eslint/*/lib
2727
eslint/*/node_modules
2828
eslint/*/test/fixtures
29+
30+
test/runtime-integration/*/output.js

‎.github/workflows/ci.yml‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,52 @@ jobs:
269269
run: make test-flow
270270
- name: Run TypeScript Tests
271271
run: make test-typescript
272+
273+
runtime-interop:
274+
name: Test @babel/runtime integrations
275+
needs: build
276+
runs-on: ubuntu-latest
277+
steps:
278+
- name: Checkout code
279+
uses: actions/checkout@v2
280+
- name: Use Node.js latest
281+
uses: actions/setup-node@v2-beta
282+
with:
283+
node-version: "*"
284+
- name: Get yarn cache directory path
285+
id: yarn-cache-dir-path
286+
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
287+
- uses: actions/cache@v2
288+
with:
289+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
290+
key: yarn-${{ hashFiles('yarn.lock') }}
291+
- name: Install
292+
run: yarn install
293+
- name: Test bundlers
294+
run: yarn test:runtime:bundlers
295+
- name: Test Node.js
296+
run: yarn test:runtime:node
297+
- name: Use Node.js 12.17
298+
uses: actions/setup-node@v2-beta
299+
with:
300+
node-version: 12.17
301+
- name: Test Node.js
302+
run: yarn test:runtime:node
303+
- name: Use Node.js 12.17
304+
uses: actions/setup-node@v2-beta
305+
with:
306+
node-version: 13.0
307+
- name: Test Node.js
308+
run: yarn test:runtime:node
309+
- name: Use Node.js 13.0
310+
uses: actions/setup-node@v2-beta
311+
with:
312+
node-version: 13.2
313+
- name: Test Node.js
314+
run: yarn test:runtime:node
315+
- name: Use Node.js 13.2
316+
uses: actions/setup-node@v2-beta
317+
with:
318+
node-version: 13.7
319+
- name: Test Node.js 13.7
320+
run: yarn test:runtime:node

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,5 @@ packages/babel-standalone/babel.min.js
7979

8080
tsconfig.json
8181
tsconfig.tsbuildinfo
82+
83+
/test/runtime-integration/*/output.js

‎package.json‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"lint": "make lint",
1313
"test": "make test",
1414
"version": "yarn --immutable-cache && git add yarn.lock",
15-
"test:esm": "node test/esm/index.js"
15+
"test:esm": "node test/esm/index.js",
16+
"test:runtime:bundlers": "node test/runtime-integration/bundlers.cjs",
17+
"test:runtime:node": "node test/runtime-integration/node.cjs"
1618
},
1719
"devDependencies": {
1820
"@babel/cli": "^7.12.0",
@@ -73,7 +75,8 @@
7375
"codemods/*",
7476
"eslint/*",
7577
"packages/*",
76-
"test/esm"
78+
"test/esm",
79+
"test/runtime-integration/*"
7780
],
7881
"resolutions": {
7982
"browserslist": "npm:4.14.5",
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const cp = require("child_process");
2+
const path = require("path");
3+
const fs = require("fs");
4+
5+
const expectedPath = path.join(__dirname, "expected.txt");
6+
const expected = fs.readFileSync(expectedPath, "utf8");
7+
8+
{
9+
console.log("Building with webpack 4");
10+
cp.execSync("yarn webpack", {
11+
cwd: path.join(__dirname, "webpack-4"),
12+
});
13+
console.log("Testing the webpack 4 bundle");
14+
const out = cp.execSync("node ./webpack-4/output.js", { encoding: "utf8" });
15+
16+
if (expected === out) {
17+
console.log("OK");
18+
} else if (process.env.OVERWRITE) {
19+
fs.writeFileSync(expectedPath, out);
20+
console.log("UPDATED");
21+
} else {
22+
console.error("FAILED\n");
23+
console.error(out);
24+
}
25+
}
26+
27+
{
28+
console.log("Building with webpack 5");
29+
cp.execSync("yarn webpack", {
30+
cwd: path.join(__dirname, "webpack-5"),
31+
});
32+
console.log("Testing the webpack 5 bundle");
33+
const out = cp.execSync("node ./webpack-5/output.js", { encoding: "utf8" });
34+
35+
if (expected === out) {
36+
console.log("OK");
37+
} else {
38+
console.error("FAILED\n");
39+
console.error(out);
40+
}
41+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
================== import - auto ====================
2+
typeof inheritsLoose: function
3+
A.__proto__ === B true
4+
================= import - esm ======================
5+
typeof toArray: function
6+
arr: 1,2,3
7+
================= require - auto ====================
8+
typeof objectWithoutProperties: function
9+
typeof objectWithoutProperties.default: undefined
10+
obj: { b: 2, [Symbol(Symbol.toStringTag)]: 5 }

‎test/runtime-integration/node.cjs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const cp = require("child_process");
2+
const path = require("path");
3+
const fs = require("fs");
4+
5+
const expectedPath = path.join(__dirname, "expected.txt");
6+
const expected = fs.readFileSync(expectedPath, "utf8");
7+
8+
{
9+
console.log(`Testing with Node.js ${process.version}`);
10+
const out = cp.execSync("node --experimental-modules ./src/main.mjs", {
11+
encoding: "utf8",
12+
});
13+
14+
if (expected === out) {
15+
console.log("OK");
16+
} else if (process.env.OVERWRITE) {
17+
fs.writeFileSync(expectedPath, out);
18+
console.log("UPDATED");
19+
} else {
20+
console.error("FAILED\n\n");
21+
console.error(out);
22+
}
23+
console.log("\n");
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
2+
3+
console.log("================== import - auto ====================");
4+
console.log("typeof inheritsLoose:", typeof inheritsLoose);
5+
6+
function A() {}
7+
function B() {}
8+
inheritsLoose(A, B);
9+
10+
console.log("A.__proto__ === B", A.__proto__ === B);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import toArray from "@babel/runtime/helpers/esm/toArray";
2+
3+
console.log("================= import - esm ======================");
4+
console.log("typeof toArray:", typeof toArray);
5+
6+
const arr = toArray(new Set([1, 2, 3]));
7+
8+
console.log("arr:", arr.toString());
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import "./import-auto.mjs";
2+
import "./import-esm.mjs";
3+
import "./require-auto.cjs";

0 commit comments

Comments
 (0)