Skip to content

Commit

Permalink
Test @babel/runtime behavior with Webpack and old Node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Feb 24, 2021
1 parent 0dffed9 commit a3ee405
Show file tree
Hide file tree
Showing 17 changed files with 1,744 additions and 140 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Expand Up @@ -26,3 +26,5 @@ packages/babel-parser/test/expressions
eslint/*/lib
eslint/*/node_modules
eslint/*/test/fixtures

test/runtime-integration/*/output.js
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -269,3 +269,52 @@ jobs:
run: make test-flow
- name: Run TypeScript Tests
run: make test-typescript

runtime-interop:
name: Test @babel/runtime integrations
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Use Node.js latest
uses: actions/setup-node@v2-beta
with:
node-version: "*"
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
- uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: yarn-${{ hashFiles('yarn.lock') }}
- name: Install
run: yarn install
- name: Test bundlers
run: yarn test:runtime:bundlers
- name: Test Node.js
run: yarn test:runtime:node
- name: Use Node.js 12.17
uses: actions/setup-node@v2-beta
with:
node-version: 12.17
- name: Test Node.js
run: yarn test:runtime:node
- name: Use Node.js 12.17
uses: actions/setup-node@v2-beta
with:
node-version: 13.0
- name: Test Node.js
run: yarn test:runtime:node
- name: Use Node.js 13.0
uses: actions/setup-node@v2-beta
with:
node-version: 13.2
- name: Test Node.js
run: yarn test:runtime:node
- name: Use Node.js 13.2
uses: actions/setup-node@v2-beta
with:
node-version: 13.7
- name: Test Node.js 13.7
run: yarn test:runtime:node
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -79,3 +79,5 @@ packages/babel-standalone/babel.min.js

tsconfig.json
tsconfig.tsbuildinfo

/test/runtime-integration/*/output.js
7 changes: 5 additions & 2 deletions package.json
Expand Up @@ -12,7 +12,9 @@
"lint": "make lint",
"test": "make test",
"version": "yarn --immutable-cache && git add yarn.lock",
"test:esm": "node test/esm/index.js"
"test:esm": "node test/esm/index.js",
"test:runtime:bundlers": "node test/runtime-integration/bundlers.cjs",
"test:runtime:node": "node test/runtime-integration/node.cjs"
},
"devDependencies": {
"@babel/cli": "^7.12.0",
Expand Down Expand Up @@ -73,7 +75,8 @@
"codemods/*",
"eslint/*",
"packages/*",
"test/esm"
"test/esm",
"test/runtime-integration/*"
],
"resolutions": {
"browserslist": "npm:4.14.5",
Expand Down
41 changes: 41 additions & 0 deletions test/runtime-integration/bundlers.cjs
@@ -0,0 +1,41 @@
const cp = require("child_process");
const path = require("path");
const fs = require("fs");

const expectedPath = path.join(__dirname, "expected.txt");
const expected = fs.readFileSync(expectedPath, "utf8");

{
console.log("Building with webpack 4");
cp.execSync("yarn webpack", {
cwd: path.join(__dirname, "webpack-4"),
});
console.log("Testing the webpack 4 bundle");
const out = cp.execSync("node ./webpack-4/output.js", { encoding: "utf8" });

if (expected === out) {
console.log("OK");
} else if (process.env.OVERWRITE) {
fs.writeFileSync(expectedPath, out);
console.log("UPDATED");
} else {
console.error("FAILED\n");
console.error(out);
}
}

{
console.log("Building with webpack 5");
cp.execSync("yarn webpack", {
cwd: path.join(__dirname, "webpack-5"),
});
console.log("Testing the webpack 5 bundle");
const out = cp.execSync("node ./webpack-5/output.js", { encoding: "utf8" });

if (expected === out) {
console.log("OK");
} else {
console.error("FAILED\n");
console.error(out);
}
}
10 changes: 10 additions & 0 deletions test/runtime-integration/expected.txt
@@ -0,0 +1,10 @@
================== import - auto ====================
typeof inheritsLoose: function
A.__proto__ === B true
================= import - esm ======================
typeof toArray: function
arr: 1,2,3
================= require - auto ====================
typeof objectWithoutProperties: function
typeof objectWithoutProperties.default: undefined
obj: { b: 2, [Symbol(Symbol.toStringTag)]: 5 }
24 changes: 24 additions & 0 deletions test/runtime-integration/node.cjs
@@ -0,0 +1,24 @@
const cp = require("child_process");
const path = require("path");
const fs = require("fs");

const expectedPath = path.join(__dirname, "expected.txt");
const expected = fs.readFileSync(expectedPath, "utf8");

{
console.log(`Testing with Node.js ${process.version}`);
const out = cp.execSync("node --experimental-modules ./src/main.mjs", {
encoding: "utf8",
});

if (expected === out) {
console.log("OK");
} else if (process.env.OVERWRITE) {
fs.writeFileSync(expectedPath, out);
console.log("UPDATED");
} else {
console.error("FAILED\n\n");
console.error(out);
}
console.log("\n");
}
10 changes: 10 additions & 0 deletions test/runtime-integration/src/import-auto.mjs
@@ -0,0 +1,10 @@
import inheritsLoose from "@babel/runtime/helpers/inheritsLoose";

console.log("================== import - auto ====================");
console.log("typeof inheritsLoose:", typeof inheritsLoose);

function A() {}
function B() {}
inheritsLoose(A, B);

console.log("A.__proto__ === B", A.__proto__ === B);
8 changes: 8 additions & 0 deletions test/runtime-integration/src/import-esm.mjs
@@ -0,0 +1,8 @@
import toArray from "@babel/runtime/helpers/esm/toArray";

console.log("================= import - esm ======================");
console.log("typeof toArray:", typeof toArray);

const arr = toArray(new Set([1, 2, 3]));

console.log("arr:", arr.toString());
3 changes: 3 additions & 0 deletions test/runtime-integration/src/main.mjs
@@ -0,0 +1,3 @@
import "./import-auto.mjs";
import "./import-esm.mjs";
import "./require-auto.cjs";
7 changes: 7 additions & 0 deletions test/runtime-integration/src/package.json
@@ -0,0 +1,7 @@
{
"name": "@babel-internal/runtime-integration-src",
"private": true,
"devDependencies": {
"@babel/runtime": "workspace:*"
}
}
14 changes: 14 additions & 0 deletions test/runtime-integration/src/require-auto.cjs
@@ -0,0 +1,14 @@
const objectWithoutProperties = require("@babel/runtime/helpers/objectWithoutProperties");

console.log("================= require - auto ====================");
console.log("typeof objectWithoutProperties:", typeof objectWithoutProperties);
console.log(
"typeof objectWithoutProperties.default:",
typeof objectWithoutProperties.default
);

const obj = objectWithoutProperties(
{ a: 1, b: 2, c: 3, [Symbol.iterator]: 4, [Symbol.toStringTag]: 5 },
["a", "c", Symbol.iterator]
);
console.log("obj:", obj);
9 changes: 9 additions & 0 deletions test/runtime-integration/webpack-4/package.json
@@ -0,0 +1,9 @@
{
"name": "@babel-internal/runtime-integration-webpack-4",
"private": true,
"devDependencies": {
"@babel/runtime": "workspace:*",
"webpack": "^4.46.0",
"webpack-cli": "^4.5.0"
}
}
13 changes: 13 additions & 0 deletions test/runtime-integration/webpack-4/webpack.config.js
@@ -0,0 +1,13 @@
const path = require("path");

module.exports = {
mode: "development",

entry: path.join(__dirname, "../src/main.mjs"),
output: {
path: __dirname,
filename: "output.js",
},

devtool: false,
};
10 changes: 10 additions & 0 deletions test/runtime-integration/webpack-5/package.json
@@ -0,0 +1,10 @@
{
"name": "@babel-internal/runtime-integration-webpack-5",
"private": true,
"exports": "./index.js",
"devDependencies": {
"@babel/runtime": "workspace:*",
"webpack": "^5.24.1",
"webpack-cli": "^4.5.0"
}
}
13 changes: 13 additions & 0 deletions test/runtime-integration/webpack-5/webpack.config.js
@@ -0,0 +1,13 @@
const path = require("path");

module.exports = {
mode: "development",

entry: path.join(__dirname, "../src/main.mjs"),
output: {
path: __dirname,
filename: "output.js",
},

devtool: false,
};

0 comments on commit a3ee405

Please sign in to comment.