Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: rm devdep leche (fixes #480) #482

Merged
merged 2 commits into from
Apr 27, 2021
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"esprima": "latest",
"esprima-fb": "^8001.2001.0-dev-harmony-fb",
"json-diff": "^0.5.4",
"leche": "^2.3.0",
"mocha": "^8.3.1",
"npm-run-all": "^4.1.5",
"nyc": "^14.1.1",
Expand Down
36 changes: 18 additions & 18 deletions tests/lib/ecma-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//------------------------------------------------------------------------------

import assert from "assert";
import leche from "leche";
import path from "path";
import * as espree from "../../espree.js";
import shelljs from "shelljs";
Expand Down Expand Up @@ -57,31 +56,32 @@ describe("ecmaFeatures", () => {
ecmaFeatures: {}
};
});
testFiles.forEach(filename => {
aladdin-add marked this conversation as resolved.
Show resolved Hide resolved
describe(filename, () => {

leche.withData(testFiles, filename => {
// Uncomment and fill in filename to focus on a single file
// var filename = "jsx/invalid-matching-placeholder-in-closing-tag";
const feature = path.dirname(filename),
isPermissive = !shouldThrowInTestsWhenEnabled(feature),
code = shelljs.cat(`${path.resolve(FIXTURES_DIR, filename)}.src.js`);

// Uncomment and fill in filename to focus on a single file
// var filename = "jsx/invalid-matching-placeholder-in-closing-tag";
const feature = path.dirname(filename),
isPermissive = !shouldThrowInTestsWhenEnabled(feature),
code = shelljs.cat(`${path.resolve(FIXTURES_DIR, filename)}.src.js`);
it(`should parse correctly when ${feature} is ${isPermissive}`, async () => {
config.ecmaFeatures[feature] = isPermissive;

it(`should parse correctly when ${feature} is ${isPermissive}`, async () => {
config.ecmaFeatures[feature] = isPermissive;
// eslint-disable-next-line node/no-unsupported-features/es-syntax
const expected = await import(`${pathToFileURL(path.resolve(__dirname, "../../", FIXTURES_DIR, filename)).href}.result.js`);

// eslint-disable-next-line node/no-unsupported-features/es-syntax
const expected = await import(`${pathToFileURL(path.resolve(__dirname, "../../", FIXTURES_DIR, filename)).href}.result.js`);
tester.assertMatches(code, config, expected.default);
});

tester.assertMatches(code, config, expected.default);
});
it(`should throw an error when ${feature} is ${!isPermissive}`, () => {
config.ecmaFeatures[feature] = !isPermissive;

it(`should throw an error when ${feature} is ${!isPermissive}`, () => {
config.ecmaFeatures[feature] = !isPermissive;
assert.throws(() => {
espree.parse(code, config);
});

assert.throws(() => {
espree.parse(code, config);
});

});
});
});
81 changes: 41 additions & 40 deletions tests/lib/ecma-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//------------------------------------------------------------------------------

import fs from "fs";
import leche from "leche";
import path from "path";
import shelljs from "shelljs";
import tester from "./tester.js";
Expand Down Expand Up @@ -59,22 +58,23 @@ describe("ecmaVersion", () => {
});

describe("Scripts", () => {
scriptOnlyTestFiles.forEach(filename => {
aladdin-add marked this conversation as resolved.
Show resolved Hide resolved
describe(filename, () => {
const version = filename.slice(1, filename.indexOf("/", 1));

leche.withData(scriptOnlyTestFiles, filename => {
const version = filename.slice(1, filename.indexOf("/", 1));
// Uncomment and fill in filename to focus on a single file
// var filename = "newTarget/simple-new-target";
const code = shelljs.cat(`${FIXTURES_DIR}/${filename}.src.js`);

// Uncomment and fill in filename to focus on a single file
// var filename = "newTarget/simple-new-target";
const code = shelljs.cat(`${FIXTURES_DIR}/${filename}.src.js`);
it("should parse correctly when sourceType is script", async () => {
config.ecmaVersion = Number(version);

it("should parse correctly when sourceType is script", async () => {
config.ecmaVersion = Number(version);

const absolutePath = path.resolve(__dirname, FIXTURES_DIR, filename.slice(1));
// eslint-disable-next-line node/no-unsupported-features/es-syntax
const expected = await import(`${pathToFileURL(absolutePath).href}.result.js`);
const absolutePath = path.resolve(__dirname, FIXTURES_DIR, filename.slice(1));
// eslint-disable-next-line node/no-unsupported-features/es-syntax
const expected = await import(`${pathToFileURL(absolutePath).href}.result.js`);

tester.assertMatches(code, config, expected.default);
tester.assertMatches(code, config, expected.default);
});
});

});
Expand All @@ -83,37 +83,38 @@ describe("ecmaVersion", () => {


describe("Modules", () => {
moduleTestFiles.forEach(filename => {
aladdin-add marked this conversation as resolved.
Show resolved Hide resolved
describe(filename, () => {
const version = filename.slice(1, filename.indexOf("/", 1));
const code = shelljs.cat(`${FIXTURES_DIR}/${filename}.src.js`);

it("should parse correctly when sourceType is module", async () => {
const absolutePath = path.resolve(__dirname, FIXTURES_DIR, filename.slice(1));

let expected;

try {
// eslint-disable-next-line node/no-unsupported-features/es-syntax
expected = await import(`${pathToFileURL(absolutePath).href}.module-result.js`);
} catch {
// eslint-disable-next-line node/no-unsupported-features/es-syntax
expected = await import(`${pathToFileURL(absolutePath).href}.result.js`);
}

leche.withData(moduleTestFiles, filename => {
const version = filename.slice(1, filename.indexOf("/", 1));
const code = shelljs.cat(`${FIXTURES_DIR}/${filename}.src.js`);

it("should parse correctly when sourceType is module", async () => {
const absolutePath = path.resolve(__dirname, FIXTURES_DIR, filename.slice(1));

let expected;

try {
// eslint-disable-next-line node/no-unsupported-features/es-syntax
expected = await import(`${pathToFileURL(absolutePath).href}.module-result.js`);
} catch {
// eslint-disable-next-line node/no-unsupported-features/es-syntax
expected = await import(`${pathToFileURL(absolutePath).href}.result.js`);
}

if (expected) {
expected = expected.default;
}
if (expected) {
expected = expected.default;
}

config.ecmaVersion = Number(version);
config.sourceType = "module";
config.ecmaVersion = Number(version);
config.sourceType = "module";

// set sourceType of program node to module
if (expected.type === "Program") {
expected.sourceType = "module";
}
// set sourceType of program node to module
if (expected.type === "Program") {
expected.sourceType = "module";
}

tester.assertMatches(code, config, expected);
tester.assertMatches(code, config, expected);
});
});

});
Expand Down
29 changes: 14 additions & 15 deletions tests/lib/libraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// Requirements
//------------------------------------------------------------------------------

import leche from "leche";
import path from "path";
import shelljs from "shelljs";
import tester from "./tester.js";
Expand All @@ -30,24 +29,24 @@ const testFiles = shelljs.find(`${__dirname}/../fixtures/libraries`).filter(file
//------------------------------------------------------------------------------

describe("Libraries", () => {
testFiles.forEach(filename => {
aladdin-add marked this conversation as resolved.
Show resolved Hide resolved
describe(filename, () => {

leche.withData(testFiles, filename => {
// var filename = "angular-1.2.5.js";

// var filename = "angular-1.2.5.js";
it("should produce correct AST when parsed", () => {
const output = shelljs.cat(`${filename}.result.json`);
const input = shelljs.cat(filename);

it("should produce correct AST when parsed", () => {
const output = shelljs.cat(`${filename}.result.json`);
const input = shelljs.cat(filename);
const result = JSON.stringify(tester.getRaw(espree.parse(input, {
loc: true,
range: true,
tokens: true
})));

const result = JSON.stringify(tester.getRaw(espree.parse(input, {
loc: true,
range: true,
tokens: true
})));

assert.strictEqual(result, output);
assert.strictEqual(result, output);
});
});
});


});
});