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:
Ger Hobbelt 2018-06-15 16:27:19 +02:00 committed by Henry Zhu
parent a2cd264211
commit e86d1e0d6a

View File

@ -1,4 +1,6 @@
import { multiple as getFixtures } from "@babel/helper-fixtures";
import fs from "fs";
import path from "path";
export function runFixtureTests(fixturesPath, parseFunction) {
const fixtures = getFixtures(fixturesPath);
@ -12,6 +14,18 @@ export function runFixtureTests(fixturesPath, parseFunction) {
try {
runTest(task, parseFunction);
} 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 =
name + "/" + task.actual.filename + ": " + err.message;
throw err;