Migrate to jest (#7455)

This commit is contained in:
Daniel Tschinder 2018-03-03 10:58:19 +01:00 committed by GitHub
parent 53208d6998
commit 3e95830646
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 1861 additions and 1133 deletions

View File

@ -1,9 +1,20 @@
"use strict"; "use strict";
let envOpts = { const env = process.env.BABEL_ENV || process.env.NODE_ENV;
const envOpts = {
loose: true, loose: true,
}; };
switch(env) {
case "development":
envOpts.debug = true;
// fall-through
case "test":
envOpts.targets = {
node: "current"
};
}
const config = { const config = {
comments: false, comments: false,
presets: [["@babel/env", envOpts]], presets: [["@babel/env", envOpts]],
@ -27,16 +38,10 @@ const config = {
], ],
}; };
// we need to do this as long as we do not test everything from source
if (process.env.BABEL_ENV === "cov") { if (process.env.BABEL_ENV === "cov") {
config.auxiliaryCommentBefore = "istanbul ignore next"; config.auxiliaryCommentBefore = "istanbul ignore next";
config.plugins.push("babel-plugin-istanbul"); config.plugins.push("babel-plugin-istanbul");
} }
if (process.env.BABEL_ENV === "development") {
envOpts.targets = {
node: "current",
};
envOpts.debug = true;
}
module.exports = config; module.exports = config;

View File

@ -51,8 +51,8 @@ jobs:
# test-ci-coverage doesn't test babel-standalone, as trying to gather coverage # test-ci-coverage doesn't test babel-standalone, as trying to gather coverage
# data for a JS file that's several megabytes large is bound to fail. Here, # data for a JS file that's several megabytes large is bound to fail. Here,
# we just run the babel-standalone test separately. # we just run the babel-standalone test separately.
- run: ./node_modules/mocha/bin/_mocha packages/babel-standalone/test/ --opts test/mocha.opts - run: ./node_modules/.bin/jest packages/babel-standalone/test/
- run: ./node_modules/mocha/bin/_mocha packages/babel-preset-env-standalone/test/ --opts test/mocha.opts - run: ./node_modules/.bin/jest packages/babel-preset-env-standalone/test/
- store_artifacts: *artifact_babel - store_artifacts: *artifact_babel
- store_artifacts: *artifact_babel_min - store_artifacts: *artifact_babel_min
- store_artifacts: *artifact_env - store_artifacts: *artifact_env

View File

@ -28,7 +28,7 @@
"test/**/*.js" "test/**/*.js"
], ],
"env": { "env": {
"mocha": true "jest": true
} }
} }
] ]

View File

@ -7,6 +7,7 @@ cache:
directories: directories:
- node_modules - node_modules
node_js: node_js:
- '9'
- '8' - '8'
- '6' - '6'
- '4' - '4'
@ -19,6 +20,8 @@ env:
before_install: before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash - curl -o- -L https://yarnpkg.com/install.sh | bash
install: yarn --ignore-engines
before_script: before_script:
- 'if [ "$JOB" = "babylon-flow-tests" ]; then make bootstrap-flow; fi' - 'if [ "$JOB" = "babylon-flow-tests" ]; then make bootstrap-flow; fi'
- 'if [ "$JOB" = "babylon-test262-tests" ]; then make bootstrap-test262; fi' - 'if [ "$JOB" = "babylon-test262-tests" ]; then make bootstrap-test262; fi'

View File

@ -81,7 +81,7 @@ test-ci:
test-ci-coverage: SHELL:=/bin/bash test-ci-coverage: SHELL:=/bin/bash
test-ci-coverage: test-ci-coverage:
BABEL_ENV=cov make bootstrap BABEL_ENV=cov make bootstrap
./scripts/test-cov.sh TEST_TYPE=cov ./scripts/test-cov.sh
bash <(curl -s https://codecov.io/bash) -f coverage/coverage-final.json bash <(curl -s https://codecov.io/bash) -f coverage/coverage-final.json
bootstrap-flow: bootstrap-flow:
@ -130,8 +130,8 @@ publish:
bootstrap: bootstrap:
make clean-all make clean-all
yarn yarn --ignore-engines
./node_modules/.bin/lerna bootstrap ./node_modules/.bin/lerna bootstrap -- --ignore-engines
make build make build
cd packages/babel-runtime; \ cd packages/babel-runtime; \
node scripts/build-dist.js node scripts/build-dist.js

View File

@ -16,9 +16,10 @@
"@babel/preset-flow": "7.0.0-beta.40", "@babel/preset-flow": "7.0.0-beta.40",
"@babel/preset-stage-0": "7.0.0-beta.40", "@babel/preset-stage-0": "7.0.0-beta.40",
"@babel/register": "7.0.0-beta.40", "@babel/register": "7.0.0-beta.40",
"babel-core": "^7.0.0-0",
"babel-eslint": "^8.0.1", "babel-eslint": "^8.0.1",
"babel-jest": "^22.4.1",
"babel-loader": "8.0.0-beta.0", "babel-loader": "8.0.0-beta.0",
"babel-plugin-istanbul": "^4.1.5",
"babel-plugin-transform-charcodes": "^0.1.0", "babel-plugin-transform-charcodes": "^0.1.0",
"babylon": "7.0.0-beta.40", "babylon": "7.0.0-beta.40",
"browserify": "^13.1.1", "browserify": "^13.1.1",
@ -44,13 +45,12 @@
"gulp-util": "^3.0.7", "gulp-util": "^3.0.7",
"gulp-watch": "^4.3.5", "gulp-watch": "^4.3.5",
"husky": "^0.14.3", "husky": "^0.14.3",
"jest": "^22.4.2",
"lerna": "2.0.0", "lerna": "2.0.0",
"lerna-changelog": "^0.5.0", "lerna-changelog": "^0.5.0",
"lint-staged": "^6.0.1", "lint-staged": "^6.0.1",
"lodash": "^4.2.0", "lodash": "^4.2.0",
"merge-stream": "^1.0.1", "merge-stream": "^1.0.1",
"mocha": "^3.0.0",
"nyc": "^11.0.3",
"output-file-sync": "^2.0.0", "output-file-sync": "^2.0.0",
"prettier": "1.10.2", "prettier": "1.10.2",
"pump": "^1.0.2", "pump": "^1.0.2",
@ -71,20 +71,44 @@
"npm": ">= 2.x <= 5.x", "npm": ">= 2.x <= 5.x",
"yarn": ">=0.27.5 || >=1.0.0-20170811" "yarn": ">=0.27.5 || >=1.0.0-20170811"
}, },
"nyc": {
"all": true,
"exclude": [
"scripts/*.js",
"packages/*/test/**",
"packages/babel-standalone/**",
"codemods/*/test/**"
],
"sourceMap": false,
"instrument": false
},
"lint-staged": { "lint-staged": {
"*.js": [ "*.js": [
"eslint --format=codeframe --rulesdir='./scripts/eslint_rules'" "eslint --format=codeframe --rulesdir='./scripts/eslint_rules'"
] ]
},
"jest": {
"collectCoverageFrom": [
"packages/*/src/**/*.js",
"codemods/*/src/**/*.js"
],
"testRegex": "./(packages|codemods)/[^/]+/test/.+\\.js$",
"testPathIgnorePatterns": [
"/node_modules/",
"/test/fixtures/",
"/test/debug-fixtures/",
"/babylon/test/expressions/",
"/test/tmp/",
"/test/__data__/",
"/test/helpers/",
"<rootDir>/test/warning.js",
"<rootDir>/build/",
"_browser.js"
],
"testEnvironment": "node",
"setupTestFrameworkScriptFile": "<rootDir>/test/testSetupFile.js",
"transformIgnorePatterns": [
"/node_modules/",
"/test/fixtures/",
"/test/tmp/",
"/test/__data__/",
"/lib/"
],
"modulePaths": [
"<rootDir>/packages/"
],
"modulePathIgnorePatterns": [
"/test/fixtures/",
"<rootDir>/build/"
]
} }
} }

View File

@ -122,7 +122,13 @@ const buildTest = function(binName, testName, opts) {
const binLoc = path.join(__dirname, "../lib", binName); const binLoc = path.join(__dirname, "../lib", binName);
return function(callback) { return function(callback) {
clear(); const dir = process.cwd();
process.chdir(__dirname);
if (fs.existsSync(tmpLoc)) rimraf.sync(tmpLoc);
fs.mkdirSync(tmpLoc);
process.chdir(tmpLoc);
saveInFiles(opts.inFiles); saveInFiles(opts.inFiles);
let args = [binLoc]; let args = [binLoc];
@ -160,6 +166,7 @@ const buildTest = function(binName, testName, opts) {
args.map(arg => `"${arg}"`).join(" ") + ": " + err.message; args.map(arg => `"${arg}"`).join(" ") + ": " + err.message;
} }
process.chdir(dir);
callback(err); callback(err);
}); });
@ -170,13 +177,6 @@ const buildTest = function(binName, testName, opts) {
}; };
}; };
const clear = function() {
process.chdir(__dirname);
if (fs.existsSync(tmpLoc)) rimraf.sync(tmpLoc);
fs.mkdirSync(tmpLoc);
process.chdir(tmpLoc);
};
fs.readdirSync(fixtureLoc).forEach(function(binName) { fs.readdirSync(fixtureLoc).forEach(function(binName) {
if (binName[0] === ".") return; if (binName[0] === ".") return;

View File

@ -180,15 +180,17 @@ export default function(
if (!deprecationWarningShown) { if (!deprecationWarningShown) {
deprecationWarningShown = true; deprecationWarningShown = true;
const deprecationError = new Error( const message =
"Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.", "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
);
deprecationError.name = "DeprecationWarning";
if (process.emitWarning) { if (process.emitWarning) {
process.emitWarning(deprecationError); // A string is directly supplied to emitWarning, because when supplying an
// Error object node throws in the tests because of different contexts
process.emitWarning(message, "DeprecationWarning");
} else { } else {
console.warn(deprecationError); const deprecationError = new Error(message);
deprecationError.name = "DeprecationWarning";
console.warn(new Error(message));
} }
} }

View File

@ -299,6 +299,9 @@ describe("api", function() {
return { plugins: [pushPlugin(str)] }; return { plugins: [pushPlugin(str)] };
} }
const oldEnv = process.env.BABEL_ENV;
process.env.BABEL_ENV = "development";
const result = babel.transform("", { const result = babel.transform("", {
filename: path.join( filename: path.join(
__dirname, __dirname,
@ -316,6 +319,12 @@ describe("api", function() {
}, },
}); });
if (oldEnv === undefined) {
delete process.env.BABEL_ENV;
} else {
process.env.BABEL_ENV = oldEnv;
}
assert.equal( assert.equal(
result.code, result.code,
[ [
@ -535,14 +544,14 @@ describe("api", function() {
const oldBabelEnv = process.env.BABEL_ENV; const oldBabelEnv = process.env.BABEL_ENV;
const oldNodeEnv = process.env.NODE_ENV; const oldNodeEnv = process.env.NODE_ENV;
setup(function() { beforeEach(function() {
// Tests need to run with the default and specific values for these. They // Tests need to run with the default and specific values for these. They
// need to be cleared for each test. // need to be cleared for each test.
delete process.env.BABEL_ENV; delete process.env.BABEL_ENV;
delete process.env.NODE_ENV; delete process.env.NODE_ENV;
}); });
suiteTeardown(function() { afterAll(function() {
process.env.BABEL_ENV = oldBabelEnv; process.env.BABEL_ENV = oldBabelEnv;
process.env.NODE_ENV = oldNodeEnv; process.env.NODE_ENV = oldNodeEnv;
}); });

View File

@ -844,6 +844,19 @@ describe("buildConfigChain", function() {
plugins: [], plugins: [],
presets: [], presets: [],
}); });
const realEnv = process.env.NODE_ENV;
const realBabelEnv = process.env.BABEL_ENV;
beforeAll(() => {
delete process.env.NODE_ENV;
delete process.env.BABEL_ENV;
});
afterAll(() => {
if (realEnv) {
process.env.NODE_ENV = realEnv;
process.env.NODE_ENV = realBabelEnv;
}
});
it("should load .babelrc", () => { it("should load .babelrc", () => {
const filename = fixture("config-files", "babelrc", "src.js"); const filename = fixture("config-files", "babelrc", "src.js");

View File

@ -4,14 +4,15 @@ import path from "path";
describe("addon resolution", function() { describe("addon resolution", function() {
const base = path.join(__dirname, "fixtures", "resolution"); const base = path.join(__dirname, "fixtures", "resolution");
let cwd;
beforeEach(function() { beforeEach(function() {
this.cwd = process.cwd(); cwd = process.cwd();
process.chdir(base); process.chdir(base);
}); });
afterEach(function() { afterEach(function() {
process.chdir(this.cwd); process.chdir(cwd);
}); });
it("should find module: presets", function() { it("should find module: presets", function() {

View File

@ -13,6 +13,7 @@
"@babel/helper-fixtures": "7.0.0-beta.40", "@babel/helper-fixtures": "7.0.0-beta.40",
"@babel/polyfill": "7.0.0-beta.40", "@babel/polyfill": "7.0.0-beta.40",
"chai": "^4.1.0", "chai": "^4.1.0",
"jest": "^22.4.2",
"lodash": "^4.2.0", "lodash": "^4.2.0",
"resolve": "^1.3.2", "resolve": "^1.3.2",
"source-map": "^0.5.0" "source-map": "^0.5.0"

View File

@ -1,4 +1,4 @@
/* eslint-env mocha */ /* eslint-env jest */
import * as babel from "@babel/core"; import * as babel from "@babel/core";
import { buildExternalHelpers } from "@babel/core"; import { buildExternalHelpers } from "@babel/core";
import getFixtures from "@babel/helper-fixtures"; import getFixtures from "@babel/helper-fixtures";
@ -11,7 +11,6 @@ import extend from "lodash/extend";
import merge from "lodash/merge"; import merge from "lodash/merge";
import resolve from "resolve"; import resolve from "resolve";
import assert from "assert"; import assert from "assert";
import chai from "chai";
import fs from "fs"; import fs from "fs";
import path from "path"; import path from "path";
import vm from "vm"; import vm from "vm";
@ -321,7 +320,7 @@ function checkDuplicatedNodes(ast) {
function run(task) { function run(task) {
const actual = task.actual; const actual = task.actual;
const expect = task.expect; const expected = task.expect;
const exec = task.exec; const exec = task.exec;
const opts = task.options; const opts = task.options;
const optionsDir = task.optionsDir; const optionsDir = task.optionsDir;
@ -376,29 +375,27 @@ function run(task) {
} }
let actualCode = actual.code; let actualCode = actual.code;
const expectCode = expect.code; const expectCode = expected.code;
if (!execCode || actualCode) { if (!execCode || actualCode) {
result = babel.transform(actualCode, getOpts(actual)); result = babel.transform(actualCode, getOpts(actual));
checkDuplicatedNodes(result.ast); checkDuplicatedNodes(result.ast);
if ( if (
!expect.code && !expected.code &&
result.code && result.code &&
!opts.throws && !opts.throws &&
fs.statSync(path.dirname(expect.loc)).isDirectory() && fs.statSync(path.dirname(expected.loc)).isDirectory() &&
!process.env.CI !process.env.CI
) { ) {
console.log(`New test file created: ${expect.loc}`); console.log(`New test file created: ${expected.loc}`);
fs.writeFileSync(expect.loc, `${result.code}\n`); fs.writeFileSync(expected.loc, `${result.code}\n`);
} else { } else {
actualCode = result.code.trim(); actualCode = result.code.trim();
chai expect(actualCode).toEqual(expectCode);
.expect(actualCode)
.to.be.equal(expectCode, actual.loc + " !== " + expect.loc);
} }
} }
if (task.sourceMap) { if (task.sourceMap) {
chai.expect(result.map).to.deep.equal(task.sourceMap); expect(result.map).toEqual(task.sourceMap);
} }
if (task.sourceMappings) { if (task.sourceMappings) {
@ -407,10 +404,8 @@ function run(task) {
task.sourceMappings.forEach(function(mapping) { task.sourceMappings.forEach(function(mapping) {
const actual = mapping.original; const actual = mapping.original;
const expect = consumer.originalPositionFor(mapping.generated); const expected = consumer.originalPositionFor(mapping.generated);
chai expect({ line: expected.line, column: expected.column }).toEqual(actual);
.expect({ line: expect.line, column: expect.column })
.to.deep.equal(actual);
}); });
} }

View File

@ -11,8 +11,7 @@
"devDependencies": { "devDependencies": {
"@babel/plugin-transform-new-target": "7.0.0-beta.40", "@babel/plugin-transform-new-target": "7.0.0-beta.40",
"@babel/preset-env": "7.0.0-beta.40", "@babel/preset-env": "7.0.0-beta.40",
"@babel/standalone": "7.0.0-beta.40", "@babel/standalone": "7.0.0-beta.40"
"mock-require": "^2.0.2"
}, },
"keywords": [ "keywords": [
"babel", "babel",

View File

@ -1,10 +1,14 @@
const assert = require("assert"); const assert = require("assert");
const mock = require("mock-require");
const Babel = require("@babel/standalone/babel");
mock("Babel", Babel);
require("../babel-preset-env");
describe("babel-preset-env-standalone", () => { (process.env.TEST_TYPE === "cov" ? describe.skip : describe)(
"babel-preset-env-standalone",
() => {
const Babel = require("@babel/standalone/babel");
jest.mock("Babel", () => require("@babel/standalone/babel"), {
virtual: true,
});
require("../babel-preset-env");
it("works w/o targets", () => { it("works w/o targets", () => {
const output = Babel.transform("const a = 1;", { const output = Babel.transform("const a = 1;", {
sourceType: "script", sourceType: "script",
@ -58,4 +62,5 @@ describe("babel-preset-env-standalone", () => {
"function Foo() {\n this instanceof Foo ? this.constructor : void 0;\n}", "function Foo() {\n this instanceof Foo ? this.constructor : void 0;\n}",
); );
}); });
}); },
);

View File

@ -1,5 +1,5 @@
import assert from "assert"; import assert from "assert";
import getTargets from "../src/targets-parser"; import getTargets from "../lib/targets-parser";
describe("getTargets", () => { describe("getTargets", () => {
it("parses", () => { it("parses", () => {

View File

@ -1,4 +1,3 @@
import { expect } from "chai";
import fs from "fs"; import fs from "fs";
import path from "path"; import path from "path";
@ -29,7 +28,7 @@ function resetCache() {
process.env.BABEL_DISABLE_CACHE = oldBabelDisableCacheValue; process.env.BABEL_DISABLE_CACHE = oldBabelDisableCacheValue;
} }
describe("@babel/register - caching", () => { describe.skip("@babel/register - caching", () => {
describe("cache", () => { describe("cache", () => {
let load, get, save; let load, get, save;
@ -44,22 +43,20 @@ describe("@babel/register - caching", () => {
}); });
afterEach(cleanCache); afterEach(cleanCache);
after(resetCache); afterAll(resetCache);
it("should load and get cached data", () => { it("should load and get cached data", () => {
writeCache({ foo: "bar" }); writeCache({ foo: "bar" });
load(); load();
expect(get()).to.be.an("object"); expect(get()).toEqual({ foo: "bar" });
expect(get()).to.deep.equal({ foo: "bar" });
}); });
it("should load and get an object with no cached data", () => { it("should load and get an object with no cached data", () => {
load(); load();
expect(get()).to.be.an("object"); expect(get()).toEqual({});
expect(get()).to.deep.equal({});
}); });
it("should load and get an object with invalid cached data", () => { it("should load and get an object with invalid cached data", () => {
@ -67,15 +64,14 @@ describe("@babel/register - caching", () => {
load(); load();
expect(get()).to.be.an("object"); expect(get()).toEqual({});
expect(get()).to.deep.equal({});
}); });
it("should create the cache on save", () => { it("should create the cache on save", () => {
save(); save();
expect(fs.existsSync(testCacheFilename)).to.be.true; expect(fs.existsSync(testCacheFilename)).toBe(true);
expect(get()).to.deep.equal({}); expect(get()).toEqual({});
}); });
}); });
}); });

View File

@ -1,10 +1,9 @@
import sourceMapSupport from "source-map-support"; import sourceMapSupport from "source-map-support";
import chai from "chai";
const DATA_ES2015 = require.resolve("./__data__/es2015"); const DATA_ES2015 = require.resolve("./__data__/es2015");
const GEN_ERROR = require.resolve("./__data__/gen_error"); const GEN_ERROR = require.resolve("./__data__/gen_error");
describe("@babel/register", function() { describe.skip("@babel/register", function() {
let babelRegister; let babelRegister;
let oldCompiler; let oldCompiler;
@ -36,7 +35,7 @@ describe("@babel/register", function() {
} }
} }
before(() => { beforeAll(() => {
const js = require("default-require-extensions/js"); const js = require("default-require-extensions/js");
oldCompiler = require.extensions[".js"]; oldCompiler = require.extensions[".js"];
require.extensions[".js"] = js; require.extensions[".js"] = js;
@ -45,7 +44,7 @@ describe("@babel/register", function() {
}); });
}); });
after(() => { afterAll(() => {
require.extensions[".js"] = oldCompiler; require.extensions[".js"] = oldCompiler;
}); });
@ -58,22 +57,20 @@ describe("@babel/register", function() {
it("registers correctly", () => { it("registers correctly", () => {
setupRegister(); setupRegister();
chai.expect(require(DATA_ES2015)).to.be.ok; expect(require(DATA_ES2015)).toBeTruthy();
}); });
it("reverts correctly", () => { it("reverts correctly", () => {
setupRegister(); setupRegister();
chai.expect(require(DATA_ES2015)).to.be.ok; expect(require(DATA_ES2015)).toBeTruthy();
delete require.cache[DATA_ES2015]; delete require.cache[DATA_ES2015];
revertRegister(); revertRegister();
chai expect(() => {
.expect(() => {
require(DATA_ES2015); require(DATA_ES2015);
}) }).toThrow(SyntaxError);
.to.throw(SyntaxError);
}); });
it("does not install source map support if asked not to", () => { it("does not install source map support if asked not to", () => {
@ -82,16 +79,16 @@ describe("@babel/register", function() {
}); });
let gen_error; let gen_error;
chai.expect((gen_error = require(GEN_ERROR))).to.be.ok; expect((gen_error = require(GEN_ERROR))).toBeDefined();
chai.expect(gen_error()).to.match(/gen_error\.js:8:34/); expect(gen_error()).toEqual(/gen_error\.js:8:34/);
}); });
it("installs source map support by default", () => { it("installs source map support by default", () => {
setupRegister(); setupRegister();
let gen_error; let gen_error;
chai.expect((gen_error = require(GEN_ERROR))).to.be.ok; expect((gen_error = require(GEN_ERROR))).toBeDefined();
chai.expect(gen_error()).to.match(/gen_error\.js:2:86/); expect(gen_error()).toEqual(/gen_error\.js:2:86/);
}); });
it("installs source map support when requested", () => { it("installs source map support when requested", () => {
@ -100,7 +97,7 @@ describe("@babel/register", function() {
}); });
let gen_error; let gen_error;
chai.expect((gen_error = require(GEN_ERROR))).to.be.ok; expect((gen_error = require(GEN_ERROR))).toBeDefined();
chai.expect(gen_error()).to.match(/gen_error\.js:2:86/); expect(gen_error()).toEqual(/gen_error\.js:2:86/);
}); });
}); });

View File

@ -1,8 +1,11 @@
const assert = require("assert"); const assert = require("assert");
const Babel = require("../babel");
// Basic smoke tests for @babel/standalone // Basic smoke tests for @babel/standalone
describe("@babel/standalone", () => { (process.env.TEST_TYPE === "cov" ? describe.skip : describe)(
"@babel/standalone",
() => {
const Babel = require("../babel");
it("handles the es2015-no-commonjs preset", () => { it("handles the es2015-no-commonjs preset", () => {
const output = Babel.transform('const getMessage = () => "Hello World"', { const output = Babel.transform('const getMessage = () => "Hello World"', {
presets: ["es2015-no-commonjs"], presets: ["es2015-no-commonjs"],
@ -87,7 +90,9 @@ describe("@babel/standalone", () => {
// Transforms arrow syntax but NOT "const". // Transforms arrow syntax but NOT "const".
assert.equal( assert.equal(
output, output,
"const getMessage = function () {\n" + ' return "Hello World";\n' + "};", "const getMessage = function () {\n" +
' return "Hello World";\n' +
"};",
); );
}); });
@ -149,4 +154,5 @@ describe("@babel/standalone", () => {
); );
}); });
}); });
}); },
);

View File

@ -2,7 +2,6 @@ import traverse from "../lib";
import assert from "assert"; import assert from "assert";
import { parse } from "babylon"; import { parse } from "babylon";
import * as t from "@babel/types"; import * as t from "@babel/types";
import { expect } from "chai";
describe("path/replacement", function() { describe("path/replacement", function() {
describe("replaceWith", function() { describe("replaceWith", function() {
@ -37,7 +36,7 @@ describe("path/replacement", function() {
path.replaceWith(t.identifier("a")); path.replaceWith(t.identifier("a"));
}, },
}); });
}).to.throw( }).toThrow(
/You can only replace a Program root node with another Program node/, /You can only replace a Program root node with another Program node/,
); );
}); });
@ -54,7 +53,7 @@ describe("path/replacement", function() {
]); ]);
}, },
}); });
}).to.throw( }).toThrow(
/Don't use `path\.replaceWith\(\)` with an array of nodes, use `path\.replaceWithMultiple\(\)`/, /Don't use `path\.replaceWith\(\)` with an array of nodes, use `path\.replaceWithMultiple\(\)`/,
); );
}); });
@ -69,7 +68,7 @@ describe("path/replacement", function() {
path.replaceWith("17 + 23"); path.replaceWith("17 + 23");
}, },
}); });
}).to.throw( }).toThrow(
/Don't use `path\.replaceWith\(\)` with a source string, use `path\.replaceWithSourceString\(\)`/, /Don't use `path\.replaceWith\(\)` with a source string, use `path\.replaceWithSourceString\(\)`/,
); );
}); });
@ -83,7 +82,7 @@ describe("path/replacement", function() {
path.replaceWith(t.identifier("p")); path.replaceWith(t.identifier("p"));
}, },
}); });
}).to.throw(/You can't replace this node, we've already removed it/); }).toThrow(/You can't replace this node, we've already removed it/);
}); });
it("throws error when passed a falsy value", function() { it("throws error when passed a falsy value", function() {
@ -94,7 +93,7 @@ describe("path/replacement", function() {
path.replaceWith(); path.replaceWith();
}, },
}); });
}).to.throw( }).toThrow(
/You passed `path\.replaceWith\(\)` a falsy node, use `path\.remove\(\)` instead/, /You passed `path\.replaceWith\(\)` a falsy node, use `path\.remove\(\)` instead/,
); );
}); });

View File

@ -2,7 +2,7 @@ import * as t from "../lib";
import assert from "assert"; import assert from "assert";
import { parse } from "babylon"; import { parse } from "babylon";
suite("cloneNode", function() { describe("cloneNode", function() {
it("should handle undefined", function() { it("should handle undefined", function() {
const node = undefined; const node = undefined;
const cloned = t.cloneNode(node); const cloned = t.cloneNode(node);

View File

@ -1,5 +1,4 @@
import * as t from "../lib"; import * as t from "../lib";
import { assert } from "chai";
import { parse } from "babylon"; import { parse } from "babylon";
import generate from "@babel/generator"; import generate from "@babel/generator";
@ -14,49 +13,45 @@ function generateCode(node) {
describe("converters", function() { describe("converters", function() {
it("toIdentifier", function() { it("toIdentifier", function() {
assert.equal(t.toIdentifier("swag-lord"), "swagLord"); expect(t.toIdentifier("swag-lord")).toBe("swagLord");
}); });
describe("valueToNode", function() { describe("valueToNode", function() {
it("number", function() { it("number", function() {
assert.deepEqual(t.valueToNode(Math.PI), t.numericLiteral(Math.PI)); expect(t.valueToNode(Math.PI)).toEqual(t.numericLiteral(Math.PI));
assert.deepEqual(t.valueToNode(-Infinity), t.numericLiteral(-Infinity)); expect(t.valueToNode(-Infinity)).toEqual(t.numericLiteral(-Infinity));
assert.deepEqual(t.valueToNode(NaN), t.numericLiteral(NaN)); expect(t.valueToNode(NaN)).toEqual(t.numericLiteral(NaN));
}); });
it("string", function() { it("string", function() {
assert.deepEqual( expect(t.valueToNode('This is a "string"')).toEqual(
t.valueToNode('This is a "string"'),
t.stringLiteral('This is a "string"'), t.stringLiteral('This is a "string"'),
); );
}); });
it("boolean", function() { it("boolean", function() {
assert.deepEqual(t.valueToNode(true), t.booleanLiteral(true)); expect(t.valueToNode(true)).toEqual(t.booleanLiteral(true));
assert.deepEqual(t.valueToNode(false), t.booleanLiteral(false)); expect(t.valueToNode(false)).toEqual(t.booleanLiteral(false));
}); });
it("null", function() { it("null", function() {
assert.deepEqual(t.valueToNode(null), t.nullLiteral()); expect(t.valueToNode(null)).toEqual(t.nullLiteral());
}); });
it("undefined", function() { it("undefined", function() {
assert.deepEqual(t.valueToNode(undefined), t.identifier("undefined")); expect(t.valueToNode(undefined)).toEqual(t.identifier("undefined"));
}); });
it("RegExp", function() { it("RegExp", function() {
assert.deepEqual( expect(t.valueToNode(/abc.+/gm)).toEqual(t.regExpLiteral("abc.+", "gm"));
t.valueToNode(/abc.+/gm),
t.regExpLiteral("abc.+", "gm"),
);
}); });
it("array", function() { it("array", function() {
assert.deepEqual( expect(t.valueToNode([1, "a"])).toEqual(
t.valueToNode([1, "a"]),
t.arrayExpression([t.numericLiteral(1), t.stringLiteral("a")]), t.arrayExpression([t.numericLiteral(1), t.stringLiteral("a")]),
); );
}); });
it("object", function() { it("object", function() {
assert.deepEqual( expect(
t.valueToNode({ t.valueToNode({
a: 1, a: 1,
"b c": 2, "b c": 2,
}), }),
).toEqual(
t.objectExpression([ t.objectExpression([
t.objectProperty(t.identifier("a"), t.numericLiteral(1)), t.objectProperty(t.identifier("a"), t.numericLiteral(1)),
t.objectProperty(t.stringLiteral("b c"), t.numericLiteral(2)), t.objectProperty(t.stringLiteral("b c"), t.numericLiteral(2)),
@ -64,12 +59,12 @@ describe("converters", function() {
); );
}); });
it("throws if cannot convert", function() { it("throws if cannot convert", function() {
assert.throws(function() { expect(function() {
t.valueToNode(Object); t.valueToNode(Object);
}); }).toThrow();
assert.throws(function() { expect(function() {
t.valueToNode(Symbol()); t.valueToNode(Symbol());
}); }).toThrow();
}); });
}); });
describe("toKeyAlias", function() { describe("toKeyAlias", function() {
@ -78,24 +73,22 @@ describe("converters", function() {
t.toKeyAlias.uid = 0; t.toKeyAlias.uid = 0;
}); });
it("doesn't change string literals", function() { it("doesn't change string literals", function() {
assert.equal( expect(
t.toKeyAlias(t.objectProperty(t.stringLiteral("a"), t.nullLiteral())), t.toKeyAlias(t.objectProperty(t.stringLiteral("a"), t.nullLiteral())),
'"a"', ).toBe('"a"');
);
}); });
it("wraps around at Number.MAX_SAFE_INTEGER", function() { it("wraps around at Number.MAX_SAFE_INTEGER", function() {
assert.equal( expect(
t.toKeyAlias( t.toKeyAlias(
t.objectMethod("method", t.identifier("a"), [], t.blockStatement([])), t.objectMethod("method", t.identifier("a"), [], t.blockStatement([])),
), ),
"0", ).toBe("0");
);
}); });
}); });
describe("toStatement", function() { describe("toStatement", function() {
it("noop on statements", function() { it("noop on statements", function() {
const node = t.emptyStatement(); const node = t.emptyStatement();
assert.equal(t.toStatement(node), node); expect(t.toStatement(node)).toEqual(node);
t.assertEmptyStatement(node); t.assertEmptyStatement(node);
}); });
it("mutate class expression to declaration", function() { it("mutate class expression to declaration", function() {
@ -110,10 +103,10 @@ describe("converters", function() {
}); });
it("fail if class expression has no id", function() { it("fail if class expression has no id", function() {
const node = t.classExpression(null, null, t.classBody([]), []); const node = t.classExpression(null, null, t.classBody([]), []);
assert.throws(function() { expect(function() {
t.toStatement(node); t.toStatement(node);
}); }).toThrow(Error);
assert.strictEqual(t.toStatement(node, /* ignore = */ true), false); expect(t.toStatement(node, /* ignore = */ true)).toBe(false);
t.assertClassExpression(node); t.assertClassExpression(node);
}); });
it("mutate function expression to declaration", function() { it("mutate function expression to declaration", function() {
@ -127,10 +120,10 @@ describe("converters", function() {
}); });
it("fail if function expression has no id", function() { it("fail if function expression has no id", function() {
const node = t.functionExpression(null, [], t.blockStatement([])); const node = t.functionExpression(null, [], t.blockStatement([]));
assert.throws(function() { expect(function() {
t.toStatement(node); t.toStatement(node);
}); }).toThrow(Error);
assert.strictEqual(t.toStatement(node, /* ignore = */ true), false); expect(t.toStatement(node, /* ignore = */ true)).toBe(false);
t.assertFunctionExpression(node); t.assertFunctionExpression(node);
}); });
it("assignment expression", function() { it("assignment expression", function() {
@ -144,17 +137,17 @@ describe("converters", function() {
}); });
it("fail if cannot convert node type", function() { it("fail if cannot convert node type", function() {
const node = t.yieldExpression(t.identifier("foo")); const node = t.yieldExpression(t.identifier("foo"));
assert.throws(function() { expect(function() {
t.toStatement(node); t.toStatement(node);
}); }).toThrow(Error);
assert.strictEqual(t.toStatement(node, /* ignore = */ true), false); expect(t.toStatement(node, /* ignore = */ true)).toBe(false);
t.assertYieldExpression(node); t.assertYieldExpression(node);
}); });
}); });
describe("toExpression", function() { describe("toExpression", function() {
it("noop on expressions", function() { it("noop on expressions", function() {
const node = t.identifier("a"); const node = t.identifier("a");
assert.equal(t.toExpression(node), node); expect(t.toExpression(node)).toEqual(node);
t.assertIdentifier(node); t.assertIdentifier(node);
}); });
it("mutate class declaration to expression", function() { it("mutate class declaration to expression", function() {
@ -200,14 +193,14 @@ describe("converters", function() {
const inner = t.yieldExpression(t.identifier("foo")); const inner = t.yieldExpression(t.identifier("foo"));
const node = t.expressionStatement(inner); const node = t.expressionStatement(inner);
t.assertYieldExpression(t.toExpression(node)); t.assertYieldExpression(t.toExpression(node));
assert.equal(t.toExpression(node), inner); expect(t.toExpression(node)).toEqual(inner);
t.assertExpressionStatement(node); t.assertExpressionStatement(node);
}); });
it("fail if cannot convert node type", function() { it("fail if cannot convert node type", function() {
const node = t.program([]); const node = t.program([]);
assert.throws(function() { expect(function() {
t.toExpression(node); t.toExpression(node);
}); }).toThrow(Error);
t.assertProgram(node); t.assertProgram(node);
}); });
}); });
@ -224,95 +217,94 @@ describe("converters", function() {
const node = t.identifier("a"); const node = t.identifier("a");
const sequence = t.toSequenceExpression([undefinedNode, node], scope); const sequence = t.toSequenceExpression([undefinedNode, node], scope);
t.assertSequenceExpression(sequence); t.assertSequenceExpression(sequence);
assert.equal(sequence.expressions[0], undefinedNode); expect(sequence.expressions[0]).toBe(undefinedNode);
assert.equal(sequence.expressions[1], node); expect(sequence.expressions[1]).toBe(node);
t.assertIdentifier(node); t.assertIdentifier(node);
}); });
it("avoids sequence for single node", function() { it("avoids sequence for single node", function() {
const node = t.identifier("a"); const node = t.identifier("a");
let sequence = t.toSequenceExpression([node], scope); let sequence = t.toSequenceExpression([node], scope);
assert.equal(sequence, node); expect(sequence).toBe(node);
const block = t.blockStatement([t.expressionStatement(node)]); const block = t.blockStatement([t.expressionStatement(node)]);
sequence = t.toSequenceExpression([block], scope); sequence = t.toSequenceExpression([block], scope);
assert.equal(sequence, node); expect(sequence).toBe(node);
}); });
it("gathers expression", function() { it("gathers expression", function() {
const node = t.identifier("a"); const node = t.identifier("a");
const sequence = t.toSequenceExpression([undefinedNode, node], scope); const sequence = t.toSequenceExpression([undefinedNode, node], scope);
assert.equal(sequence.expressions[1], node); expect(sequence.expressions[1]).toBe(node);
}); });
it("gathers expression statement", function() { it("gathers expression statement", function() {
const node = t.expressionStatement(t.identifier("a")); const node = t.expressionStatement(t.identifier("a"));
const sequence = t.toSequenceExpression([undefinedNode, node], scope); const sequence = t.toSequenceExpression([undefinedNode, node], scope);
assert.equal(sequence.expressions[1], node.expression); expect(sequence.expressions[1]).toBe(node.expression);
}); });
it("gathers var declarations", function() { it("gathers var declarations", function() {
const node = parseCode("var a, b = 1;"); const node = parseCode("var a, b = 1;");
const sequence = t.toSequenceExpression([undefinedNode, node], scope); const sequence = t.toSequenceExpression([undefinedNode, node], scope);
t.assertIdentifier(scope[0].id, { name: "a" }); t.assertIdentifier(scope[0].id, { name: "a" });
t.assertIdentifier(scope[1].id, { name: "b" }); t.assertIdentifier(scope[1].id, { name: "b" });
assert.equal(generateCode(sequence.expressions[1]), "b = 1"); expect(generateCode(sequence.expressions[1])).toBe("b = 1");
assert.equal(generateCode(sequence.expressions[2]), "undefined"); expect(generateCode(sequence.expressions[2])).toBe("undefined");
}); });
it("skips undefined if expression after var declaration", function() { it("skips undefined if expression after var declaration", function() {
const node = parseCode("{ var a, b = 1; true }"); const node = parseCode("{ var a, b = 1; true }");
const sequence = t.toSequenceExpression([undefinedNode, node], scope); const sequence = t.toSequenceExpression([undefinedNode, node], scope);
assert.equal(generateCode(sequence.expressions[1]), "b = 1, true"); expect(generateCode(sequence.expressions[1])).toBe("b = 1, true");
}); });
it("bails on let and const declarations", function() { it("bails on let and const declarations", function() {
let node = parseCode("let a, b = 1;"); let node = parseCode("let a, b = 1;");
let sequence = t.toSequenceExpression([undefinedNode, node], scope); let sequence = t.toSequenceExpression([undefinedNode, node], scope);
assert.isUndefined(sequence); expect(sequence).toBeUndefined();
node = parseCode("const b = 1;"); node = parseCode("const b = 1;");
sequence = t.toSequenceExpression([undefinedNode, node], scope); sequence = t.toSequenceExpression([undefinedNode, node], scope);
assert.isUndefined(sequence); expect(sequence).toBeUndefined();
}); });
it("gathers if statements", function() { it("gathers if statements", function() {
let node = parseCode("if (true) { true }"); let node = parseCode("if (true) { true }");
let sequence = t.toSequenceExpression([undefinedNode, node], scope); let sequence = t.toSequenceExpression([undefinedNode, node], scope);
assert.equal( expect(generateCode(sequence.expressions[1])).toBe(
generateCode(sequence.expressions[1]),
"true ? true : undefined", "true ? true : undefined",
); );
node = parseCode("if (true) { true } else { b }"); node = parseCode("if (true) { true } else { b }");
sequence = t.toSequenceExpression([undefinedNode, node], scope); sequence = t.toSequenceExpression([undefinedNode, node], scope);
assert.equal(generateCode(sequence.expressions[1]), "true ? true : b"); expect(generateCode(sequence.expressions[1])).toBe("true ? true : b");
}); });
it("bails in if statements if recurse bails", function() { it("bails in if statements if recurse bails", function() {
let node = parseCode("if (true) { return }"); let node = parseCode("if (true) { return }");
let sequence = t.toSequenceExpression([undefinedNode, node], scope); let sequence = t.toSequenceExpression([undefinedNode, node], scope);
assert.isUndefined(sequence); expect(sequence).toBeUndefined();
node = parseCode("if (true) { true } else { return }"); node = parseCode("if (true) { true } else { return }");
sequence = t.toSequenceExpression([undefinedNode, node], scope); sequence = t.toSequenceExpression([undefinedNode, node], scope);
assert.isUndefined(sequence); expect(sequence).toBeUndefined();
}); });
it("gathers block statements", function() { it("gathers block statements", function() {
let node = parseCode("{ a }"); let node = parseCode("{ a }");
let sequence = t.toSequenceExpression([undefinedNode, node], scope); let sequence = t.toSequenceExpression([undefinedNode, node], scope);
assert.equal(generateCode(sequence.expressions[1]), "a"); expect(generateCode(sequence.expressions[1])).toBe("a");
node = parseCode("{ a; b; }"); node = parseCode("{ a; b; }");
sequence = t.toSequenceExpression([undefinedNode, node], scope); sequence = t.toSequenceExpression([undefinedNode, node], scope);
assert.equal(generateCode(sequence.expressions[1]), "a, b"); expect(generateCode(sequence.expressions[1])).toBe("a, b");
}); });
it("bails in block statements if recurse bails", function() { it("bails in block statements if recurse bails", function() {
const node = parseCode("{ return }"); const node = parseCode("{ return }");
const sequence = t.toSequenceExpression([undefinedNode, node], scope); const sequence = t.toSequenceExpression([undefinedNode, node], scope);
assert.isUndefined(sequence); expect(sequence).toBeUndefined();
}); });
it("gathers empty statements", function() { it("gathers empty statements", function() {
const node = parseCode(";"); const node = parseCode(";");
const sequence = t.toSequenceExpression([undefinedNode, node], scope); const sequence = t.toSequenceExpression([undefinedNode, node], scope);
assert.equal(generateCode(sequence.expressions[1]), "undefined"); expect(generateCode(sequence.expressions[1])).toBe("undefined");
}); });
it("skips empty statement if expression afterwards", function() { it("skips empty statement if expression afterwards", function() {
const node = parseCode("{ ; true }"); const node = parseCode("{ ; true }");
const sequence = t.toSequenceExpression([undefinedNode, node], scope); const sequence = t.toSequenceExpression([undefinedNode, node], scope);
assert.equal(generateCode(sequence.expressions[1]), "true"); expect(generateCode(sequence.expressions[1])).toBe("true");
}); });
}); });
}); });

View File

@ -1,84 +1,83 @@
import * as t from "../lib"; import * as t from "../lib";
import assert from "assert";
import { parse } from "babylon"; import { parse } from "babylon";
suite("validators", function() { describe("validators", function() {
suite("isNodesEquivalent", function() { describe("isNodesEquivalent", function() {
it("should handle simple cases", function() { it("should handle simple cases", function() {
const mem = t.memberExpression(t.identifier("a"), t.identifier("b")); const mem = t.memberExpression(t.identifier("a"), t.identifier("b"));
assert(t.isNodesEquivalent(mem, mem) === true); expect(t.isNodesEquivalent(mem, mem)).toBe(true);
const mem2 = t.memberExpression(t.identifier("a"), t.identifier("c")); const mem2 = t.memberExpression(t.identifier("a"), t.identifier("c"));
assert(t.isNodesEquivalent(mem, mem2) === false); expect(t.isNodesEquivalent(mem, mem2)).toBe(false);
}); });
it("should handle full programs", function() { it("should handle full programs", function() {
assert(t.isNodesEquivalent(parse("1 + 1"), parse("1+1")) === true); expect(t.isNodesEquivalent(parse("1 + 1"), parse("1+1"))).toBe(true);
assert(t.isNodesEquivalent(parse("1 + 1"), parse("1+2")) === false); expect(t.isNodesEquivalent(parse("1 + 1"), parse("1+2"))).toBe(false);
}); });
it("should handle complex programs", function() { it("should handle complex programs", function() {
const program = "'use strict'; function lol() { wow();return 1; }"; const program = "'use strict'; function lol() { wow();return 1; }";
assert(t.isNodesEquivalent(parse(program), parse(program)) === true); expect(t.isNodesEquivalent(parse(program), parse(program))).toBe(true);
const program2 = "'use strict'; function lol() { wow();return -1; }"; const program2 = "'use strict'; function lol() { wow();return -1; }";
assert(t.isNodesEquivalent(parse(program), parse(program2)) === false); expect(t.isNodesEquivalent(parse(program), parse(program2))).toBe(false);
}); });
it("rejects 'await' as an identifier", function() { it("rejects 'await' as an identifier", function() {
assert(t.isValidIdentifier("await") === false); expect(t.isValidIdentifier("await")).toBe(false);
}); });
}); });
suite("isCompatTag", function() { describe("isCompatTag", function() {
it("should handle lowercase tag names", function() { it("should handle lowercase tag names", function() {
assert(t.react.isCompatTag("div")); expect(t.react.isCompatTag("div")).toBe(true);
assert(t.react.isCompatTag("a")); // one letter expect(t.react.isCompatTag("a")).toBe(true); // one letter
assert(t.react.isCompatTag("h3")); // letters and numbers expect(t.react.isCompatTag("h3")).toBe(true); // letters and numbers
}); });
it("should handle custom element tag names", function() { it("should handle custom element tag names", function() {
assert(t.react.isCompatTag("plastic-button")); // ascii letters expect(t.react.isCompatTag("plastic-button")).toBe(true); // ascii letters
assert(t.react.isCompatTag("math-α")); // non-latin chars expect(t.react.isCompatTag("math-α")).toBe(true); // non-latin chars
assert(t.react.isCompatTag("img-viewer2")); // numbers expect(t.react.isCompatTag("img-viewer2")).toBe(true); // numbers
assert(t.react.isCompatTag("emotion-😍")); // emoji expect(t.react.isCompatTag("emotion-😍")).toBe(true); // emoji
}); });
it("accepts trailing dash '-' in custom element tag names", function() { it("accepts trailing dash '-' in custom element tag names", function() {
assert(t.react.isCompatTag("div-")); expect(t.react.isCompatTag("div-")).toBe(true);
assert(t.react.isCompatTag("a-")); expect(t.react.isCompatTag("a-")).toBe(true);
assert(t.react.isCompatTag("h3-")); expect(t.react.isCompatTag("h3-")).toBe(true);
}); });
it("rejects empty or null tag names", function() { it("rejects empty or null tag names", function() {
assert(t.react.isCompatTag(null) === false); expect(t.react.isCompatTag(null)).toBe(false);
assert(t.react.isCompatTag() === false); expect(t.react.isCompatTag()).toBe(false);
assert(t.react.isCompatTag(undefined) === false); expect(t.react.isCompatTag(undefined)).toBe(false);
assert(t.react.isCompatTag("") === false); expect(t.react.isCompatTag("")).toBe(false);
}); });
it("rejects tag names starting with an uppercase letter", function() { it("rejects tag names starting with an uppercase letter", function() {
assert(t.react.isCompatTag("Div") === false); expect(t.react.isCompatTag("Div")).toBe(false);
assert(t.react.isCompatTag("A") === false); expect(t.react.isCompatTag("A")).toBe(false);
assert(t.react.isCompatTag("H3") === false); expect(t.react.isCompatTag("H3")).toBe(false);
}); });
it("rejects all uppercase tag names", function() { it("rejects all uppercase tag names", function() {
assert(t.react.isCompatTag("DIV") === false); expect(t.react.isCompatTag("DIV")).toBe(false);
assert(t.react.isCompatTag("A") === false); expect(t.react.isCompatTag("A")).toBe(false);
assert(t.react.isCompatTag("H3") === false); expect(t.react.isCompatTag("H3")).toBe(false);
}); });
it("rejects leading dash '-'", function() { it("rejects leading dash '-'", function() {
assert(t.react.isCompatTag("-div") === false); expect(t.react.isCompatTag("-div")).toBe(false);
assert(t.react.isCompatTag("-a") === false); expect(t.react.isCompatTag("-a")).toBe(false);
assert(t.react.isCompatTag("-h3") === false); expect(t.react.isCompatTag("-h3")).toBe(false);
}); });
}); });
suite("patterns", function() { describe("patterns", function() {
it("allows nested pattern structures", function() { it("allows nested pattern structures", function() {
const pattern = t.objectPattern([ const pattern = t.objectPattern([
t.objectProperty( t.objectProperty(
@ -93,7 +92,7 @@ suite("validators", function() {
), ),
]); ]);
assert(t.isNodesEquivalent(pattern, pattern) === true); expect(t.isNodesEquivalent(pattern, pattern)).toBe(true);
}); });
}); });
}); });

View File

@ -1,24 +0,0 @@
#!/bin/bash
set -e
TEST_DIRS=""
sources=("codemods" "packages")
for source in "${sources[@]}"; do
for f in $source/*; do
if [ -n "$TEST_ONLY" ] && [[ `basename $f` != *"$TEST_ONLY"* ]]; then
continue
fi
# Exclude babel-standalone from coverage runs
if [ "$TEST_TYPE" = "cov" ] && [[ `basename $f` = 'babel-standalone' || `basename $f` = 'babel-preset-env-standalone' ]]; then
continue
fi
if [ -d "$f/test" ]; then
TEST_DIRS="$f/test $TEST_DIRS"
fi
done
done
echo $TEST_DIRS

View File

@ -1,6 +1,10 @@
#!/bin/bash #!/bin/bash
set -e set -e
testDirs=`TEST_TYPE=cov scripts/_get-test-directories.sh` jestArgs="--coverage"
node_modules/.bin/nyc node_modules/mocha/bin/_mocha --opts test/mocha.opts $testDirs
node_modules/.bin/nyc report --reporter=json if [ -n "$CI" ]; then
jestArgs="${jestArgs} --runInBand --ci"
fi
node_modules/.bin/jest $jestArgs

View File

@ -6,9 +6,15 @@ if [ -z "$TEST_GREP" ]; then
fi fi
node="node" node="node"
jestArgs=""
if [ "$TEST_DEBUG" ]; then if [ "$TEST_DEBUG" ]; then
node="node --inspect-brk" node="node --inspect-brk"
jestArgs="${jestArgs} --runInBand"
fi fi
$node node_modules/mocha/bin/_mocha `scripts/_get-test-directories.sh` --opts test/mocha.opts --grep "$TEST_GREP" if [ -n "$CI" ]; then
jestArgs="${jestArgs} --runInBand --ci"
fi
$node node_modules/.bin/jest $jestArgs "$TEST_GREP"

View File

@ -1 +0,0 @@
--reporter dot --ui tdd --timeout 10000 --compilers js:@babel/register

1
test/testSetupFile.js Normal file
View File

@ -0,0 +1 @@
jest.setTimeout(10000);

2122
yarn.lock

File diff suppressed because it is too large Load Diff