Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Commit

Permalink
Simplify error messaging in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed Jan 11, 2019
1 parent 2441b9d commit 5f16839
Showing 1 changed file with 1 addition and 36 deletions.
37 changes: 1 addition & 36 deletions test/specs/babel-eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,9 @@ const assert = require("assert");
const babelEslint = require("../..");
const espree = require("espree");
const escope = require("eslint-scope");
const util = require("util");
const unpad = require("dedent");
const assertImplementsAST = require("../helpers/assert-implements-ast");

function lookup(obj, keypath, backwardsDepth) {
if (!keypath) {
return obj;
}

let pathSegments = keypath.split(".");

if (pathSegments.length > 1) {
pathSegments = pathSegments.slice(0, -1 * backwardsDepth);
}

return pathSegments.reduce((base, segment) => {
return base && base[segment], obj;
});
}

function parseAndAssertSame(code) {
code = unpad(code);
const esAST = espree.parse(code, {
Expand All @@ -48,25 +31,7 @@ function parseAndAssertSame(code) {
eslintVisitorKeys: true,
eslintScopeManager: true,
}).ast;
try {
assertImplementsAST(esAST, babylonAST);
} catch (err) {
const traversal = err.message.slice(3, err.message.indexOf(":"));
err.message += `\n${unpad(`
espree:
${util.inspect(lookup(esAST, traversal, 2), {
depth: err.depth,
colors: true,
})}
babel-eslint:
${util.inspect(lookup(babylonAST, traversal, 2), {
depth: err.depth,
colors: true,
})}
`)}`;
throw err;
}
//assert.equal(esAST, babylonAST);
assertImplementsAST(esAST, babylonAST);
}

describe("babylon-to-espree", () => {
Expand Down

0 comments on commit 5f16839

Please sign in to comment.