Skip to content

Commit

Permalink
Misc test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jun 2, 2021
1 parent 79b412d commit 6e5315d
Show file tree
Hide file tree
Showing 22 changed files with 92 additions and 78 deletions.
2 changes: 1 addition & 1 deletion packages/babel-cli/bin/babel.js
@@ -1,3 +1,3 @@
#!/usr/bin/env node

require("../lib/babel");
import("../lib/babel.js");
@@ -1,2 +1 @@
src/foo/bar.js -> lib/foo/bar.js
Successfully compiled 1 file with Babel (123ms).
Successfully compiled 0 files with Babel (123ms).
5 changes: 5 additions & 0 deletions packages/babel-helper-plugin-test-runner/src/index.js
Expand Up @@ -2,6 +2,11 @@ import testRunner from "@babel/helper-transform-fixture-test-runner";
import path from "path";
import { URL } from "url";

// Workaround for https://github.com/facebook/jest/issues/11434
import "../../babel-helper-create-class-features-plugin/lib/index";
import "../../babel-template/lib/index";
import "../../babel-core/lib/index";

export default function (loc) {
if (!process.env.BABEL_8_BREAKING) {
if (!loc.startsWith("file://")) {
Expand Down
27 changes: 13 additions & 14 deletions packages/babel-helper-transform-fixture-test-runner/src/index.ts
Expand Up @@ -14,6 +14,12 @@ import path from "path";
import vm from "vm";
import QuickLRU from "quick-lru";
import { fileURLToPath } from "url";
import { jest } from "@jest/globals";

// Workaround for https://github.com/facebook/jest/issues/11434
import "../../babel-helper-create-class-features-plugin/lib/index";
import "../../babel-template/lib/index";
import "../../babel-core/lib/index";

import { createRequire } from "module";
const require = createRequire(import.meta.url);
Expand Down Expand Up @@ -196,7 +202,7 @@ export function runCodeInTestContext(
}
}

function run(task) {
async function run(task) {
const {
actual,
expect: expected,
Expand Down Expand Up @@ -234,7 +240,7 @@ function run(task) {
if (execCode) {
const context = createContext();
const execOpts = getOpts(exec);
result = babel.transform(execCode, execOpts);
result = await babel.transformAsync(execCode, execOpts);
checkDuplicatedNodes(babel, result.ast);
execCode = result.code;

Expand Down Expand Up @@ -266,7 +272,7 @@ function run(task) {
};
}

result = babel.transform(inputCode, getOpts(actual));
result = await babel.transformAsync(inputCode, getOpts(actual));

if (restoreSpies) restoreSpies();

Expand Down Expand Up @@ -448,9 +454,9 @@ export default function (
testFn(
task.title,

function () {
async function () {
function runTask() {
run(task);
return run(task);
}

if ("sourceMap" in task.options === false) {
Expand All @@ -477,7 +483,7 @@ export default function (
// the options object with useless options
delete task.options.throws;

assert.throws(runTask, function (err) {
await assert.rejects(runTask, function (err) {
assert.ok(
throwMsg === true || err.message.includes(throwMsg),
`
Expand All @@ -487,14 +493,7 @@ Actual Error: ${err.message}`,
return true;
});
} else {
if (task.exec.code) {
const result = run(task);
if (result && typeof result.then === "function") {
return result;
}
} else {
runTask();
}
return runTask();
}
},
);
Expand Down
Expand Up @@ -2,7 +2,7 @@ import * as babel from "@babel/core";
import proposalClassStaticBlock from "..";

describe("plugin ordering", () => {
it("should work when @babel/plugin-proposal-class-static-block is after class features plugin", () => {
it("should work when @babel/plugin-proposal-class-static-block is after class features plugin", async () => {
const source = `class Foo {
static {
this.foo = Foo.bar;
Expand All @@ -11,16 +11,18 @@ describe("plugin ordering", () => {
}
`;
expect(
babel.transform(source, {
filename: "example.js",
highlightCode: false,
configFile: false,
babelrc: false,
plugins: [
"@babel/plugin-proposal-class-properties",
proposalClassStaticBlock,
],
}).code,
(
await babel.transformAsync(source, {
filename: "example.js",
highlightCode: false,
configFile: false,
babelrc: false,
plugins: [
"@babel/plugin-proposal-class-properties",
proposalClassStaticBlock,
],
})
).code,
).toMatchInlineSnapshot(`
"function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
Expand Down
@@ -1,3 +1,3 @@
{
"plugins": ["./plugin-clear-scope", "proposal-object-rest-spread"]
"plugins": ["./plugin-clear-scope.cjs", "proposal-object-rest-spread"]
}
19 changes: 13 additions & 6 deletions packages/babel-plugin-proposal-optional-chaining/test/util.test.js
Expand Up @@ -3,13 +3,20 @@ import { parseSync, traverse } from "@babel/core";

function getPath(input, parserOpts) {
let targetPath;
traverse(parseSync(input, { parserOpts, filename: "example.js" }), {
OptionalMemberExpression(path) {
targetPath = path;
path.stop();
traverse(
parseSync(input, {
configFile: false,
parserOpts,
filename: "example.js",
}),
{
OptionalMemberExpression(path) {
targetPath = path;
path.stop();
},
noScope: true,
},
noScope: true,
});
);
return targetPath;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-transform-modules-amd/src/index.js
Expand Up @@ -10,7 +10,7 @@ import {
getModuleName,
} from "@babel/helper-module-transforms";
import { template, types as t } from "@babel/core";
import { getImportSource } from "babel-plugin-dynamic-import-node/utils";
import { getImportSource } from "babel-plugin-dynamic-import-node/utils.js";

const buildWrapper = template(`
define(MODULE_NAME, AMD_ARGUMENTS, function(IMPORT_NAMES) {
Expand Down
Expand Up @@ -11,7 +11,7 @@ import {
import simplifyAccess from "@babel/helper-simple-access";
import { template, types as t } from "@babel/core";

import { createDynamicImportTransform } from "babel-plugin-dynamic-import-node/utils";
import { createDynamicImportTransform } from "babel-plugin-dynamic-import-node/utils.js";

export default declare((api, options) => {
api.assertVersion(7);
Expand Down

This file was deleted.

This file was deleted.

@@ -0,0 +1,38 @@
import { transformSync } from "@babel/core";
import pluginCommonJS from "../lib/index";

const tests = [
'import "foo";',
'import foo from "foo";',
'import {default as foo2} from "foo";',
'import * as foo from "foo";',
'import {bar} from "foo";',
'import {bar2, baz} from "foo";',
'import {bar as baz2} from "foo";',
'import {bar as baz3, xyz} from "foo";',
'import bar, * as bar2 from "foo";',
'import bar, {bar2, bar3 as bar4} from "foo";',

"export var a;",
"export default function(){};",
"export default function f(){};",
"export default 42;",
"export {foo}; var foo;",
"export { foo as default }; var foo;",
'export * from "foo";',
'export {foo} from "foo";',
'export {default as foo} from "foo";',
];

describe("source maps", () => {
it.each(tests)("%s", code => {
var res = transformSync(code, {
configFile: false,
sourceMap: true,
plugins: [pluginCommonJS],
});

// Should create mapping
expect(res.map.mappings).not.toBe("");
});
});
@@ -1,7 +1,7 @@
import { declare } from "@babel/helper-plugin-utils";
import hoistVariables from "@babel/helper-hoist-variables";
import { template, types as t } from "@babel/core";
import { getImportSource } from "babel-plugin-dynamic-import-node/utils";
import { getImportSource } from "babel-plugin-dynamic-import-node/utils.js";
import { rewriteThis, getModuleName } from "@babel/helper-module-transforms";
import { isIdentifierName } from "@babel/helper-validator-identifier";

Expand Down
@@ -1,6 +1,6 @@
{
"plugins": [
"./plugin.js",
"./plugin.cjs",
["transform-react-jsx-development", { "runtime": "automatic" }]
]
}
@@ -1,3 +1,3 @@
{
"plugins": ["./remove"]
"plugins": ["./remove.cjs"]
}
@@ -1,3 +1,3 @@
{
"plugins": ["syntax-typescript", "./plugin"]
"plugins": ["syntax-typescript", "./plugin.cjs"]
}
@@ -1,3 +1,3 @@
{
"plugins": ["./plugin"]
"plugins": ["./plugin.cjs"]
}

0 comments on commit 6e5315d

Please sign in to comment.