Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Chore: Replace mocha (istanbul, chai, leche) with Jest #300

Merged
merged 1 commit into from
May 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const OPEN_SOURCE_LICENSES = [
const NODE_MODULES = "./node_modules/",

// Utilities - intentional extra space at the end of each string
MOCHA = `${NODE_MODULES}mocha/bin/_mocha `,
JEST = `${NODE_MODULES}jest/bin/jest.js`,

// Files
MAKEFILE = "./Makefile.js",
Expand Down Expand Up @@ -103,7 +103,7 @@ target.lint = function() {
target.test = function() {
target.lint();

const lastReturn = nodeCLI.exec("istanbul", "cover", MOCHA, "-- -c", TEST_FILES);
const lastReturn = nodeCLI.exec(JEST);
let errors = 0;

if (lastReturn.code !== 0) {
Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@
},
"license": "BSD-2-Clause",
"devDependencies": {
"chai": "3.5.0",
"dateformat": "2.0.0",
"eslint": "3.19.0",
"eslint-config-eslint": "4.0.0",
"eslint-plugin-node": "4.2.2",
"eslint-release": "0.10.3",
"istanbul": "0.4.5",
"leche": "2.1.2",
"mocha": "3.3.0",
"jest": "20.0.4",
"npm-license": "0.3.3",
"shelljs": "0.7.7",
"shelljs-nodecli": "0.1.1",
Expand All @@ -43,6 +39,7 @@
],
"scripts": {
"test": "node Makefile.js test",
"jest": "jest",
"lint": "node Makefile.js lint",
"release": "eslint-release",
"ci-release": "eslint-ci-release",
Expand All @@ -56,5 +53,11 @@
},
"peerDependencies": {
"typescript": "*"
},
"jest": {
"testRegex": "tests\/lib\/.+\\.js$",
"testPathIgnorePatterns": [],
"collectCoverage": true,
"coverageReporters": ["text-summary"]
}
}
2 changes: 1 addition & 1 deletion tests/lib/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
env:
mocha: true
jest: true
12 changes: 5 additions & 7 deletions tests/lib/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
// Requirements
//------------------------------------------------------------------------------

const assert = require("chai").assert,
leche = require("leche"),
path = require("path"),
const path = require("path"),
parser = require("../../parser"),
shelljs = require("shelljs"),
tester = require("./tester");
testUtils = require("../../tools/test-utils");

//------------------------------------------------------------------------------
// Setup
Expand Down Expand Up @@ -47,7 +45,7 @@ describe("basics", () => {
};
});

leche.withData(testFiles, filename => {
testFiles.forEach(filename => {

// Uncomment and fill in filename to focus on a single file
// var filename = "jsx/invalid-matching-placeholder-in-closing-tag";
Expand All @@ -59,7 +57,7 @@ describe("basics", () => {

try {
result = parser.parse(code, config);
result = tester.getRaw(result);
result = testUtils.getRaw(result);
} catch (ex) {

// format of error isn't exactly the same, just check if it's expected
Expand All @@ -72,7 +70,7 @@ describe("basics", () => {
}

// console.log(JSON.stringify(result, null, 4));
assert.deepEqual(result, expected);
expect(result).toEqual(expected);

});

Expand Down
12 changes: 5 additions & 7 deletions tests/lib/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@
// Requirements
//------------------------------------------------------------------------------

const assert = require("chai").assert,
leche = require("leche"),
path = require("path"),
const path = require("path"),
parser = require("../../parser"),
shelljs = require("shelljs"),
tester = require("./tester");
testUtils = require("../../tools/test-utils");

//------------------------------------------------------------------------------
// Setup
Expand Down Expand Up @@ -68,7 +66,7 @@ describe("Comments", () => {
};
});

leche.withData(testFiles, filename => {
testFiles.forEach(filename => {
const code = shelljs.cat(`${path.resolve(FIXTURES_DIR, filename)}.src.js`);

it("should produce correct AST when parsed with comment", () => {
Expand All @@ -77,7 +75,7 @@ describe("Comments", () => {

try {
result = parser.parse(code, config);
result = tester.getRaw(result);
result = testUtils.getRaw(result);
} catch (ex) {

// format of error isn't exactly the same, just check if it's expected
Expand All @@ -88,7 +86,7 @@ describe("Comments", () => {


}
assert.deepEqual(result, expected);
expect(result).toEqual(expected);
});

});
Expand Down
12 changes: 5 additions & 7 deletions tests/lib/ecma-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
// Requirements
//------------------------------------------------------------------------------

const assert = require("chai").assert,
leche = require("leche"),
path = require("path"),
const path = require("path"),
parser = require("../../parser"),
shelljs = require("shelljs"),
tester = require("./tester");
testUtils = require("../../tools/test-utils");

//------------------------------------------------------------------------------
// Setup
Expand Down Expand Up @@ -65,7 +63,7 @@ describe("ecmaFeatures", () => {
};
});

leche.withData(testFiles, filename => {
testFiles.forEach(filename => {

// Uncomment and fill in filename to focus on a single file
// var filename = "jsx/invalid-matching-placeholder-in-closing-tag";
Expand Down Expand Up @@ -98,7 +96,7 @@ describe("ecmaFeatures", () => {

try {
result = parser.parse(code, config);
result = tester.getRaw(result);
result = testUtils.getRaw(result);
} catch (ex) {

// format of error isn't exactly the same, just check if it's expected
Expand All @@ -109,7 +107,7 @@ describe("ecmaFeatures", () => {


}
assert.deepEqual(result, expected);
expect(result).toEqual(expected);
});

});
Expand Down
14 changes: 6 additions & 8 deletions tests/lib/jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
// Requirements
//------------------------------------------------------------------------------

const assert = require("chai").assert,
leche = require("leche"),
path = require("path"),
const path = require("path"),
parser = require("../../parser"),
shelljs = require("shelljs"),
tester = require("./tester");
testUtils = require("../../tools/test-utils");

//------------------------------------------------------------------------------
// Setup
Expand Down Expand Up @@ -84,7 +82,7 @@ describe("JSX", () => {

try {
result = parser.parse(code, config);
result = tester.getRaw(result);
result = testUtils.getRaw(result);
} catch (ex) {

// format of error isn't exactly the same, just check if it's expected
Expand All @@ -95,15 +93,15 @@ describe("JSX", () => {


}
assert.deepEqual(result, expected);
expect(result).toEqual(expected);
});
};
}

describe("useJSXTextNode: false", () => {
leche.withData(jsxTestFiles, testFixture(JSX_FIXTURES_DIR, false));
jsxTestFiles.forEach(testFixture(JSX_FIXTURES_DIR, false));
});
describe("useJSXTextNode: true", () => {
leche.withData(jsxTextTestFiles, testFixture(JSX_JSXTEXT_FIXTURES_DIR, true));
jsxTextTestFiles.forEach(testFixture(JSX_JSXTEXT_FIXTURES_DIR, true));
});
});
13 changes: 6 additions & 7 deletions tests/lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
// Requirements
//------------------------------------------------------------------------------

const assert = require("chai").assert,
parser = require("../../parser"),
tester = require("./tester");
const parser = require("../../parser"),
testUtils = require("../../tools/test-utils");

//------------------------------------------------------------------------------
// Tests
Expand All @@ -25,8 +24,8 @@ describe("parse()", () => {
describe("basic functionality", () => {

it("should parse an empty string", () => {
assert.deepEqual(parser.parse("").body, []);
assert.deepEqual(parser.parse("", {}).body, []);
expect(parser.parse("").body).toEqual([]);
expect(parser.parse("", {}).body).toEqual([]);
});

});
Expand All @@ -37,7 +36,7 @@ describe("parse()", () => {
try {
parser.parse("function fn(a, a) {\n}", { sourceType: "module" });
} catch (err) {
assert.equal(err.column, 16);
expect(err.column).toEqual(16);
}
});

Expand All @@ -56,7 +55,7 @@ describe("parse()", () => {
loc: true
});

assert.deepEqual(tester.getRaw(ast), require("../fixtures/parse/all-pieces.json"));
expect(testUtils.getRaw(ast)).toEqual(require("../fixtures/parse/all-pieces.json"));
});

});
Expand Down
12 changes: 5 additions & 7 deletions tests/lib/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
// Requirements
//------------------------------------------------------------------------------

const assert = require("chai").assert,
leche = require("leche"),
path = require("path"),
const path = require("path"),
parser = require("../../parser"),
shelljs = require("shelljs"),
tester = require("./tester");
testUtils = require("../../tools/test-utils");

//------------------------------------------------------------------------------
// Setup
Expand Down Expand Up @@ -47,7 +45,7 @@ describe("typescript", () => {
};
});

leche.withData(testFiles, filename => {
testFiles.forEach(filename => {

// Uncomment and fill in filename to focus on a single file
// var filename = "jsx/invalid-matching-placeholder-in-closing-tag";
Expand All @@ -59,7 +57,7 @@ describe("typescript", () => {

try {
result = parser.parse(code, config);
result = tester.getRaw(result);
result = testUtils.getRaw(result);
} catch (ex) {

// format of error isn't exactly the same, just check if it's expected
Expand All @@ -72,7 +70,7 @@ describe("typescript", () => {
}

// console.log(JSON.stringify(result, null, 4));
assert.deepEqual(result, expected);
expect(result).toEqual(expected);

});

Expand Down
File renamed without changes.
14 changes: 3 additions & 11 deletions tools/update-typescript-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

const shelljs = require("shelljs"),
parser = require("../parser"),
tester = require("../tests/lib/tester"),
testUtils = require("./test-utils"),
path = require("path");

//------------------------------------------------------------------------------
Expand All @@ -36,7 +36,7 @@ function getRaw(ast) {
*/
function getExpectedResult(code, config) {
try {
return tester.getRaw(parser.parse(code, config));
return testUtils.getRaw(parser.parse(code, config));
} catch (ex) {
const raw = getRaw(ex);
raw.message = ex.message;
Expand Down Expand Up @@ -70,7 +70,6 @@ function outputResult(result, testResultFilename) {

const FIXTURES_DIR = "./tests/fixtures/typescript";
const testFiles = getTestFilenames(FIXTURES_DIR);
const assert = require("chai").assert;

testFiles.forEach(filename => {

Expand All @@ -86,13 +85,6 @@ testFiles.forEach(filename => {
const testResultFilename = `${path.resolve(__dirname, "..", FIXTURES_DIR, filename)}.result.js`;
const result = getExpectedResult(code, config);

const expected = require(testResultFilename);

try {
assert.deepEqual(result, expected);
} catch (e) {
shelljs.echo("DIFFERENT", e);
outputResult(result, testResultFilename);
}
outputResult(result, testResultFilename);

});