diff --git a/jest.config.js b/jest.config.js index 276e156144d9..b60fa636a815 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,5 @@ const supportsESM = parseInt(process.versions.node) >= 12; +const isPublishBundle = process.env.IS_PUBLISH; module.exports = { collectCoverageFrom: [ @@ -23,6 +24,9 @@ module.exports = { "/build/", "/.history/", // local directory for VSCode Extension - https://marketplace.visualstudio.com/items?itemName=xyz.local-history "_browser\\.js", + // Some tests require internal files of bundled packages, which are not available + // in production builds. They are marked using the .skip-bundled.js extension. + ...(isPublishBundle ? ["\\.skip-bundled\\.js$"] : []), ], testEnvironment: "node", setupFilesAfterEnv: ["/test/testSetupFile.js"], diff --git a/packages/babel-parser/test/unit/tokenizer/types.js b/packages/babel-parser/test/unit/tokenizer/types.skip-bundled.js similarity index 65% rename from packages/babel-parser/test/unit/tokenizer/types.js rename to packages/babel-parser/test/unit/tokenizer/types.skip-bundled.js index 0785c3055e16..0cbcaa8d6fd6 100644 --- a/packages/babel-parser/test/unit/tokenizer/types.js +++ b/packages/babel-parser/test/unit/tokenizer/types.skip-bundled.js @@ -1,13 +1,6 @@ -const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe; - -describeSkipPublish("token types", () => { - let tt, tokenOperatorPrecedence; - beforeAll(async () => { - ({ tt, tokenOperatorPrecedence } = await import( - "../../../lib/tokenizer/types.js" - )); - }); +import { tt, tokenOperatorPrecedence } from "../../../lib/tokenizer/types.js"; +describe("token types", () => { it("should check if the binOp for relational === in", () => { expect(tokenOperatorPrecedence(tt.relational)).toEqual( tokenOperatorPrecedence(tt._in), diff --git a/packages/babel-parser/test/unit/util/identifier.js b/packages/babel-parser/test/unit/util/identifier.skip-bundled.js similarity index 78% rename from packages/babel-parser/test/unit/util/identifier.js rename to packages/babel-parser/test/unit/util/identifier.skip-bundled.js index 7ac5639eeb83..6a9b3f7b20fb 100644 --- a/packages/babel-parser/test/unit/util/identifier.js +++ b/packages/babel-parser/test/unit/util/identifier.skip-bundled.js @@ -1,13 +1,9 @@ -const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe; - -describeSkipPublish("identifier", () => { - let isKeyword, keywordRelationalOperator; - beforeAll(async () => { - ({ isKeyword, keywordRelationalOperator } = await import( - "../../../lib/util/identifier.js" - )); - }); +import { + isKeyword, + keywordRelationalOperator, +} from "../../../lib/util/identifier.js"; +describe("identifier", () => { describe("isKeyword", () => { it("break is a keyword", () => { expect(isKeyword("break")).toBe(true); diff --git a/packages/babel-parser/test/unit/util/location.js b/packages/babel-parser/test/unit/util/location.skip-bundled.js similarity index 77% rename from packages/babel-parser/test/unit/util/location.js rename to packages/babel-parser/test/unit/util/location.skip-bundled.js index 7439ebfeb383..463463c88921 100644 --- a/packages/babel-parser/test/unit/util/location.js +++ b/packages/babel-parser/test/unit/util/location.skip-bundled.js @@ -1,11 +1,6 @@ -const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe; - -describeSkipPublish("getLineInfo", () => { - let getLineInfo; - beforeAll(async () => { - ({ getLineInfo } = await import("../../../lib/util/location.js")); - }); +import { getLineInfo } from "../../../lib/util/location.js"; +describe("getLineInfo", () => { const input = "a\nb\nc\nd\ne\nf\ng\nh\ni"; it("reports correct position", () => { diff --git a/packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression/test/util.test.js b/packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression/test/util.skip-bundled.js similarity index 84% rename from packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression/test/util.test.js rename to packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression/test/util.skip-bundled.js index 23a34a258639..c2478caba4bf 100644 --- a/packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression/test/util.test.js +++ b/packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression/test/util.skip-bundled.js @@ -1,4 +1,5 @@ import { parseSync, traverse } from "@babel/core"; +import { shouldTransform } from "../lib/util.ts"; function getPath(input, parserOpts = {}) { let targetPath; @@ -18,14 +19,7 @@ function getPath(input, parserOpts = {}) { return targetPath; } -const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe; - -describeSkipPublish("shouldTransform", () => { - let shouldTransform; - beforeAll(async () => { - ({ shouldTransform } = await import("../lib/util.js")); - }); - +describe("shouldTransform", () => { const positiveCases = [ "(function a([a]) {})", "({ b: function a([a]) {} })", diff --git a/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.test.js b/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.skip-bundled.js similarity index 92% rename from packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.test.js rename to packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.skip-bundled.js index 9147705cced4..2703696945bd 100644 --- a/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.test.js +++ b/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.skip-bundled.js @@ -1,4 +1,5 @@ import { parseSync, traverse } from "@babel/core"; +import { shouldTransform } from "../lib/util.ts"; function getPath(input, parserOpts = {}) { let targetPath; @@ -19,14 +20,7 @@ function getPath(input, parserOpts = {}) { return targetPath; } -const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe; - -describeSkipPublish("shouldTransform", () => { - let shouldTransform; - beforeAll(async () => { - ({ shouldTransform } = await import("../lib/util.js")); - }); - +describe("shouldTransform", () => { const positiveCases = [ "fn?.(...[], 0)", "fn?.(...[], ...[])", diff --git a/packages/babel-plugin-proposal-optional-chaining/test/util.test.js b/packages/babel-plugin-proposal-optional-chaining/test/util.skip-bundled.js similarity index 89% rename from packages/babel-plugin-proposal-optional-chaining/test/util.test.js rename to packages/babel-plugin-proposal-optional-chaining/test/util.skip-bundled.js index afbd65c9ff19..ee3289dcc530 100644 --- a/packages/babel-plugin-proposal-optional-chaining/test/util.test.js +++ b/packages/babel-plugin-proposal-optional-chaining/test/util.skip-bundled.js @@ -1,3 +1,4 @@ +import { willPathCastToBoolean } from "../lib/util.js"; import { parseSync, traverse } from "@babel/core"; function getPath(input, parserOpts) { @@ -12,14 +13,7 @@ function getPath(input, parserOpts) { return targetPath; } -const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe; - -describeSkipPublish("willPathCastToBoolean", () => { - let willPathCastToBoolean; - beforeAll(async () => { - ({ willPathCastToBoolean } = await import("../lib/util.js")); - }); - +describe("willPathCastToBoolean", () => { const positiveCases = [ "if(a?.b) {}", "while(a?.b) {}", diff --git a/packages/babel-preset-react/test/normalize-options.spec.js b/packages/babel-preset-react/test/normalize-options.skip-bundled.js similarity index 94% rename from packages/babel-preset-react/test/normalize-options.spec.js rename to packages/babel-preset-react/test/normalize-options.skip-bundled.js index 87dafebc3180..5932ed4b6d73 100644 --- a/packages/babel-preset-react/test/normalize-options.spec.js +++ b/packages/babel-preset-react/test/normalize-options.skip-bundled.js @@ -1,13 +1,6 @@ -const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe; - -describeSkipPublish("normalize options", () => { - let normalizeOptions; - beforeAll(async () => { - ({ default: normalizeOptions } = await import( - "../lib/normalize-options.js" - )); - }); +import normalizeOptions from "../lib/normalize-options.js"; +describe("normalize options", () => { (process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => { it("should throw on unknown options", () => { expect(() => normalizeOptions({ throwIfNamespaces: true })).toThrowError( diff --git a/packages/babel-preset-typescript/test/normalize-options.spec.js b/packages/babel-preset-typescript/test/normalize-options.skip-bundled.js similarity index 91% rename from packages/babel-preset-typescript/test/normalize-options.spec.js rename to packages/babel-preset-typescript/test/normalize-options.skip-bundled.js index bae4bd54c1fa..205409af007e 100644 --- a/packages/babel-preset-typescript/test/normalize-options.spec.js +++ b/packages/babel-preset-typescript/test/normalize-options.skip-bundled.js @@ -1,13 +1,6 @@ -const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe; - -describeSkipPublish("normalize options", () => { - let normalizeOptions; - beforeAll(async () => { - ({ default: normalizeOptions } = await import( - "../lib/normalize-options.js" - )); - }); +import normalizeOptions from "../lib/normalize-options.js"; +describe("normalize options", () => { (process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => { it("should throw on unknown options", () => { expect(() => normalizeOptions({ allowNamespace: true })).toThrowError(