From a6f1e79db10b3481ac3f4807b29cbd31f446f63b Mon Sep 17 00:00:00 2001 From: James Long Date: Fri, 30 Dec 2016 14:44:57 -0500 Subject: [PATCH] Ignore EmptyStatements when comparing asts, now down to 12 real failures \o/ --- tests_config/run_spec.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests_config/run_spec.js b/tests_config/run_spec.js index aa82cec7..013a811b 100644 --- a/tests_config/run_spec.js +++ b/tests_config/run_spec.js @@ -1,9 +1,23 @@ const fs = require('fs'); const child_process = require('child_process'); const jscodefmt = require("../"); +const recast = require("recast"); +const types = require("ast-types"); const RUN_AST_TESTS = process.env["AST_COMPARE"]; +// Ignoring empty statements that are added into the output removes a +// lot of noise from test failures and let's us focus on the real +// failures when comparing asts +function removeEmptyStatements(ast) { + return types.visit(ast, { + visitEmptyStatement: function(path) { + path.prune(); + return false; + } + }); +} + function run_spec(dirname) { fs.readdirSync(dirname).forEach(filename => { if (filename.endsWith('.js') && filename !== 'jsfmt.spec.js') { @@ -35,7 +49,7 @@ function run_spec(dirname) { expect(ppast).toBeDefined(); if(RUN_AST_TESTS === "1") { if(ast.errors.length === 0) { - expect(ast).toEqual(ppast); + expect(removeEmptyStatements(ast)).toEqual(removeEmptyStatements(ppast)); } } });