Skip to content

Commit

Permalink
Only bundle the release build, and don't import src in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Nov 18, 2021
1 parent 90c659b commit 12c9476
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 29 deletions.
21 changes: 11 additions & 10 deletions Makefile
Expand Up @@ -18,7 +18,7 @@ NODE := $(YARN) node

.PHONY: build build-dist watch lint fix clean test-clean test-only test test-ci publish bootstrap

build: build-bundle
build: build-no-bundle
ifneq ("$(BABEL_COVERAGE)", "true")
$(MAKE) build-standalone
endif
Expand All @@ -28,8 +28,15 @@ build-bundle: clean clean-lib
$(MAKE) build-flow-typings
$(MAKE) build-dist

build-bundle-ci: bootstrap-only
$(MAKE) build-bundle
build-no-bundle-ci: bootstrap-only
$(YARN) gulp build-dev
$(MAKE) build-flow-typings
$(MAKE) build-dist

build-no-bundle: clean clean-lib
BABEL_ENV=development $(YARN) gulp build-dev
$(MAKE) build-flow-typings
$(MAKE) build-dist

generate-tsconfig:
$(NODE) scripts/generators/tsconfig.js
Expand All @@ -46,7 +53,7 @@ build-typescript-legacy-typings:

build-standalone: build-babel-standalone

build-standalone-ci: build-bundle-ci
build-standalone-ci: build-no-bundle-ci
$(MAKE) build-standalone

build-babel-standalone:
Expand All @@ -61,12 +68,6 @@ build-plugin-transform-runtime-dist:
cd packages/babel-plugin-transform-runtime; \
$(NODE) scripts/build-dist.js

build-no-bundle: clean clean-lib
BABEL_ENV=development $(YARN) gulp build-dev
# Ensure that build artifacts for types are created during local
# development too.
$(MAKE) build-flow-typings

watch: build-no-bundle
BABEL_ENV=development $(YARN) gulp watch

Expand Down
4 changes: 4 additions & 0 deletions babel.config.js
Expand Up @@ -215,6 +215,10 @@ module.exports = function (api) {
assumptions: sourceAssumptions,
plugins: [transformNamedBabelTypesImportToDestructuring],
},
{
test: sources.map(source => normalize(source.replace("/src", "/test"))),
plugins: ["@babel/plugin-proposal-dynamic-import"],
},
{
test: unambiguousSources.map(normalize),
sourceType: "unambiguous",
Expand Down
11 changes: 9 additions & 2 deletions packages/babel-parser/test/unit/tokenizer/types.js
@@ -1,6 +1,13 @@
import { tt, tokenOperatorPrecedence } from "../../../src/tokenizer/types";
const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe;

describeSkipPublish("token types", () => {
let tt, tokenOperatorPrecedence;
beforeAll(async () => {
({ tt, tokenOperatorPrecedence } = await import(
"../../../lib/tokenizer/types"
));
});

describe("token types", () => {
it("should check if the binOp for relational === in", () => {
expect(tokenOperatorPrecedence(tt.relational)).toEqual(
tokenOperatorPrecedence(tt._in),
Expand Down
14 changes: 9 additions & 5 deletions packages/babel-parser/test/unit/util/identifier.js
@@ -1,9 +1,13 @@
import {
isKeyword,
keywordRelationalOperator,
} from "../../../src/util/identifier";
const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe;

describeSkipPublish("identifier", () => {
let isKeyword, keywordRelationalOperator;
beforeAll(async () => {
({ isKeyword, keywordRelationalOperator } = await import(
"../../../lib/util/identifier"
));
});

describe("identifier", () => {
describe("isKeyword", () => {
it("break is a keyword", () => {
expect(isKeyword("break")).toBe(true);
Expand Down
9 changes: 7 additions & 2 deletions packages/babel-parser/test/unit/util/location.js
@@ -1,6 +1,11 @@
import { getLineInfo } from "../../../src/util/location";
const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe;

describeSkipPublish("getLineInfo", () => {
let getLineInfo;
beforeAll(async () => {
({ getLineInfo } = await import("../../../lib/util/location"));
});

describe("getLineInfo", () => {
const input = "a\nb\nc\nd\ne\nf\ng\nh\ni";

it("reports correct position", () => {
Expand Down
@@ -1,5 +1,4 @@
import { parseSync, traverse } from "@babel/core";
import { shouldTransform } from "../src/util.ts";

function getPath(input, parserOpts = {}) {
let targetPath;
Expand All @@ -19,7 +18,14 @@ function getPath(input, parserOpts = {}) {
return targetPath;
}

describe("shouldTransform", () => {
const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe;

describeSkipPublish("shouldTransform", () => {
let shouldTransform;
beforeAll(async () => {
({ shouldTransform } = await import("../lib/util"));
});

const positiveCases = [
"(function a([a]) {})",
"({ b: function a([a]) {} })",
Expand Down
@@ -1,5 +1,4 @@
import { parseSync, traverse } from "@babel/core";
import { shouldTransform } from "../src/util.ts";

function getPath(input, parserOpts = {}) {
let targetPath;
Expand All @@ -20,7 +19,14 @@ function getPath(input, parserOpts = {}) {
return targetPath;
}

describe("shouldTransform", () => {
const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe;

describeSkipPublish("shouldTransform", () => {
let shouldTransform;
beforeAll(async () => {
({ shouldTransform } = await import("../lib/util"));
});

const positiveCases = [
"fn?.(...[], 0)",
"fn?.(...[], ...[])",
Expand Down
@@ -1,4 +1,3 @@
import { willPathCastToBoolean } from "../src/util";
import { parseSync, traverse } from "@babel/core";

function getPath(input, parserOpts) {
Expand All @@ -13,7 +12,14 @@ function getPath(input, parserOpts) {
return targetPath;
}

describe("willPathCastToBoolean", () => {
const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe;

describeSkipPublish("willPathCastToBoolean", () => {
let willPathCastToBoolean;
beforeAll(async () => {
({ willPathCastToBoolean } = await import("../lib/util"));
});

const positiveCases = [
"if(a?.b) {}",
"while(a?.b) {}",
Expand Down
10 changes: 8 additions & 2 deletions packages/babel-preset-react/test/normalize-options.spec.js
@@ -1,5 +1,11 @@
import normalizeOptions from "../src/normalize-options";
describe("normalize options", () => {
const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe;

describeSkipPublish("normalize options", () => {
let normalizeOptions;
beforeAll(async () => {
({ default: normalizeOptions } = await import("../lib/normalize-options"));
});

(process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => {
it("should throw on unknown options", () => {
expect(() => normalizeOptions({ throwIfNamespaces: true })).toThrowError(
Expand Down
10 changes: 8 additions & 2 deletions packages/babel-preset-typescript/test/normalize-options.spec.js
@@ -1,5 +1,11 @@
import normalizeOptions from "../src/normalize-options";
describe("normalize options", () => {
const describeSkipPublish = process.env.IS_PUBLISH ? describe.skip : describe;

describeSkipPublish("normalize options", () => {
let normalizeOptions;
beforeAll(async () => {
({ default: normalizeOptions } = await import("../lib/normalize-options"));
});

(process.env.BABEL_8_BREAKING ? describe : describe.skip)("Babel 8", () => {
it("should throw on unknown options", () => {
expect(() => normalizeOptions({ allowNamespace: true })).toThrowError(
Expand Down

0 comments on commit 12c9476

Please sign in to comment.