babel/parser: test helpers: write expected throw message to options.json ~ complete jest -u functionality (#8178) [skip ci]
* babel/parser: test helpers: when test fails with an exception and both reference output file and options.json file do not exist, write a simple options.json with the error message to expect when such a file doesn't exist yet. This completes the `jest -u` capability for new tests which are expected to *fail*.
This commit is contained in:
parent
a2cd264211
commit
e86d1e0d6a
@ -1,4 +1,6 @@
|
|||||||
import { multiple as getFixtures } from "@babel/helper-fixtures";
|
import { multiple as getFixtures } from "@babel/helper-fixtures";
|
||||||
|
import fs from "fs";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
export function runFixtureTests(fixturesPath, parseFunction) {
|
export function runFixtureTests(fixturesPath, parseFunction) {
|
||||||
const fixtures = getFixtures(fixturesPath);
|
const fixtures = getFixtures(fixturesPath);
|
||||||
@ -12,6 +14,18 @@ export function runFixtureTests(fixturesPath, parseFunction) {
|
|||||||
try {
|
try {
|
||||||
runTest(task, parseFunction);
|
runTest(task, parseFunction);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (!task.expect.code && !process.env.CI) {
|
||||||
|
const fn = path.dirname(task.expect.loc) + "/options.json";
|
||||||
|
if (!fs.existsSync(fn)) {
|
||||||
|
task.options = task.options || {};
|
||||||
|
task.options.throws = err.message.replace(
|
||||||
|
/^.*Got error message: /,
|
||||||
|
"",
|
||||||
|
);
|
||||||
|
fs.writeFileSync(fn, JSON.stringify(task.options, null, " "));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err.message =
|
err.message =
|
||||||
name + "/" + task.actual.filename + ": " + err.message;
|
name + "/" + task.actual.filename + ": " + err.message;
|
||||||
throw err;
|
throw err;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user