Skip to content

Commit

Permalink
Run Babel transform tests on old node if possible (#16352)
Browse files Browse the repository at this point in the history
* infra: run transform tests on old node

* add minNodeVersionInputJs option

* migrate some tests to minNodeVersionInputJs

* rename minNodeVersionInputJs to minNodeVersionTransform
  • Loading branch information
JLHwung committed Mar 15, 2024
1 parent 05b3997 commit 3a255c8
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 22 deletions.
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Expand Up @@ -295,7 +295,7 @@ Other than normal Babel options, `options.json` can contain other properties to

- **`minNodeVersion`** (string)

If the test requires a minimum Node version, you can add `minNodeVersion` (must be in semver format).
If an `exec.js`` test requires a minimum Node version, you can add `minNodeVersion` (must be in semver format).

```jsonc
// options.json example
Expand All @@ -304,6 +304,8 @@ Other than normal Babel options, `options.json` can contain other properties to
}
```

Use `minNodeVersionTransform` if an `input.js` test requires a minimum Node version.

- **`externalHelpers`** (boolean)

By default, all the tests run with the [`@babel/plugin-external-helpers`](https://babel.dev/docs/en/babel-plugin-external-helpers) enabled. You can disable this behavior with
Expand Down
20 changes: 14 additions & 6 deletions packages/babel-helper-fixtures/data/schema.json
Expand Up @@ -4,11 +4,14 @@
"description": "JSON schema for Babel Fixture Test Runner",
"allOf": [
{ "$ref": "#/definitions/TaskOption" },
{ "$ref": "https://json.schemastore.org/babelrc", "$comment": "Todo: switch to our inhouse schema" }
{
"$ref": "https://json.schemastore.org/babelrc",
"$comment": "Todo: switch to our inhouse schema"
}
],
"definitions": {
"OS": {
"type":"string",
"type": "string",
"description": "The possible values of `process.platform`. See https://nodejs.org/api/process.html#process_process_platform",
"enum": ["aix", "darwin", "freebsd", "linux", "openbsd", "sunos", "win32"]
},
Expand All @@ -17,14 +20,19 @@
"properties": {
"BABEL_8_BREAKING": {
"description": "Whether this test should run when BABEL_8_BREAKING is enabled",
"type":"boolean"
"type": "boolean"
},
"ignoreOutput": {
"description": "Whether the test should generate and compare with output.js",
"type": "boolean"
},
"minNodeVersion": {
"description": "The minimum Node.js version this test should run on",
"description": "The minimum Node.js version the exec.js test should run on",
"type": "string",
"pattern": "^\\d+(\\.\\d+){0,2}$"
},
"minNodeVersionTransform": {
"description": "The minimum Node.js version the input.js transform test should run on",
"type": "string",
"pattern": "^\\d+(\\.\\d+){0,2}$"
},
Expand All @@ -39,12 +47,12 @@
},
"throws": {
"description": "Expected thrown error message",
"type":"string",
"type": "string",
"default": ""
},
"validateLogs": {
"description": "Whether this test should validate the stdout and stderr",
"type":"boolean",
"type": "boolean",
"default": false
}
}
Expand Down
24 changes: 23 additions & 1 deletion packages/babel-helper-fixtures/src/index.ts
Expand Up @@ -53,6 +53,7 @@ export interface TaskOptions extends InputOptions {
externalHelpers?: boolean;
ignoreOutput?: boolean;
minNodeVersion?: string;
minNodeVersionTransform?: string;
sourceMap?: boolean;
os?: string | string[];
validateLogs?: boolean;
Expand Down Expand Up @@ -269,13 +270,34 @@ function pushTask(
}

if (semver.lt(nodeVersion, minimumVersion)) {
return;
if (test.actual.code) {
test.exec.code = null;
} else {
return;
}
}

// Delete to avoid option validation error
delete taskOpts.minNodeVersion;
}

if (taskOpts.minNodeVersionTransform) {
const minimumVersion = semver.clean(taskOpts.minNodeVersionTransform);

if (minimumVersion == null) {
throw new Error(
`'minNodeVersionTransform' has invalid semver format: ${taskOpts.minNodeVersionTransform}`,
);
}

if (semver.lt(nodeVersion, minimumVersion)) {
return;
}

// Delete to avoid option validation error
delete taskOpts.minNodeVersionTransform;
}

if (taskOpts.os) {
let os = taskOpts.os;

Expand Down
@@ -1,4 +1,4 @@
{
"minNodeVersion": "12.22.0",
"minNodeVersionTransform": "12.22.0",
"externalHelpers": false
}
@@ -1,4 +1,4 @@
{
"minNodeVersion": "12.22.0",
"minNodeVersionTransform": "12.22.0",
"plugins": ["./plugin"]
}
@@ -1,4 +1,4 @@
{
"plugins": ["./plugin"],
"minNodeVersion": "12.0.0"
"minNodeVersionTransform": "12.22.0",
"plugins": ["./plugin"]
}
@@ -1,4 +1,4 @@
{
"minNodeVersion": "12.22.0",
"minNodeVersionTransform": "12.22.0",
"plugins": ["./plugin"]
}
@@ -1,5 +1,5 @@
{
"minNodeVersion": "12.11.0",
"minNodeVersionTransform": "12.11.0",
"plugins": [
"./plugin.mjs",
"bugfix-safari-id-destructuring-collision-in-function-expression"
Expand Down
@@ -1,6 +1,6 @@
{
"minNodeVersion": "8.0.0",
"minNodeVersionTransform": "8.0.0",
"parserOpts": {
"allowReturnOutsideFunction": true
}
"allowReturnOutsideFunction": true
}
}
Expand Up @@ -6,5 +6,5 @@
"parserOpts": {
"allowReturnOutsideFunction": true
},
"minNodeVersion": "8.0.0"
"minNodeVersionTransform": "8.0.0"
}
@@ -1,3 +1,3 @@
{
"minNodeVersion": "12.0.0"
"minNodeVersionTransform": "12.0.0"
}
@@ -1,3 +1,3 @@
{
"minNodeVersion": "12.0.0"
"minNodeVersionTransform": "12.0.0"
}
@@ -1,5 +1,5 @@
{
"minNodeVersion": "12.0.0",
"minNodeVersionTransform": "12.0.0",
"presets": [
[
"env",
Expand Down
@@ -1,5 +1,5 @@
{
"BABEL_8_BREAKING": false,
"presets": [["flow", { "experimental_useHermesParser": true }]],
"minNodeVersion": "12.0.0"
"minNodeVersionTransform": "12.0.0"
}

0 comments on commit 3a255c8

Please sign in to comment.