diff --git a/package.json b/package.json index fc71f364..2af22324 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,9 @@ "mocha": "5.0.0" }, "scripts": { - "test": "mocha" + "test": "mocha", + "acquire": "node test/util/acquire.js" }, - "repository": "git://github.com/darobin/webidl2.js", + "repository": "git://github.com/w3c/webidl2.js", "main": "index" } diff --git a/test/invalid.js b/test/invalid.js index 05bc20f3..19bbf006 100644 --- a/test/invalid.js +++ b/test/invalid.js @@ -4,38 +4,17 @@ "use strict"; -const wp = require("../lib/webidl2"); -const expect = require("expect"); -const pth = require("path"); +const { collect } = require("./util/collect"); const fs = require("fs"); +const expect = require("expect"); describe("Parses all of the invalid IDLs to check that they blow up correctly", () => { - const dir = pth.join(__dirname, "invalid/idl"); - const skip = {}; - const idls = fs.readdirSync(dir) - .filter(it => (/\.w?idl$/).test(it) && !skip[it]) - .map(it => pth.join(dir, it)); - - for (const idl of idls) { - const err = JSON.parse(fs.readFileSync( - pth.join(__dirname, "invalid", "json", pth.basename(idl).replace(/\.w?idl/, ".json")), - "utf8" - )); - - it(`should produce the right error for ${idl}`, () => { - let error; - try { - const ast = wp.parse(fs.readFileSync(idl, "utf8")); - console.log(JSON.stringify(ast, null, 4)); - } - catch (e) { - error = e; - } - finally { - expect(error).toBeTruthy(); - expect(error.message).toEqual(err.message); - expect(error.line).toEqual(err.line); - } + for (const test of collect("invalid", { expectError: true })) { + it(`should produce the right error for ${test.path}`, () => { + const err = test.readJSON(); + expect(test.error).toBeTruthy(); + expect(test.error.message).toEqual(err.message); + expect(test.error.line).toEqual(err.line); }); } }); diff --git a/test/invalid/idl/stringconstants.idl b/test/invalid/idl/stringconstants.widl similarity index 100% rename from test/invalid/idl/stringconstants.idl rename to test/invalid/idl/stringconstants.widl diff --git a/test/syntax.js b/test/syntax.js index c7d903bd..05d647ed 100644 --- a/test/syntax.js +++ b/test/syntax.js @@ -1,32 +1,14 @@ "use strict"; -const wp = require("../lib/webidl2"); +const { collect } = require("./util/collect"); const expect = require("expect"); -const pth = require("path"); -const fs = require("fs"); -const jdp = require("jsondiffpatch"); const debug = true; describe("Parses all of the IDLs to produce the correct ASTs", () => { - const dir = pth.join(__dirname, "syntax/idl"); - const skip = {}; // use if we have a broken test - const idls = fs.readdirSync(dir) - .filter(it => (/\.widl$/).test(it) && !skip[it]) - .map(it => pth.join(dir, it)); - - for (const idl of idls) { - const json = pth.join(__dirname, "syntax/json", pth.basename(idl).replace(".widl", ".json")); - - it(`should produce the same AST for ${idl}`, () => { + for (const test of collect("syntax")) { + it(`should produce the same AST for ${test.path}`, () => { try { - const optFile = pth.join(__dirname, "syntax/opt", pth.basename(json)); - let opt = undefined; - if (fs.existsSync(optFile)) - opt = JSON.parse(fs.readFileSync(optFile, "utf8")); - const diff = jdp.diff(JSON.parse(fs.readFileSync(json, "utf8")), - wp.parse(fs.readFileSync(idl, "utf8").replace(/\r\n/g, "\n"), opt)); - if (diff && debug) console.log(JSON.stringify(diff, null, 4)); - expect(diff).toBe(undefined); + expect(test.diff()).toBeFalsy(); } catch (e) { console.log(e.toString()); diff --git a/test/syntax/idl/typedef-union.idl b/test/syntax/idl/typedef-union.widl similarity index 100% rename from test/syntax/idl/typedef-union.idl rename to test/syntax/idl/typedef-union.widl diff --git a/test/syntax/json/attributes.json b/test/syntax/json/attributes.json index 86fe9d52..34a36fde 100644 --- a/test/syntax/json/attributes.json +++ b/test/syntax/json/attributes.json @@ -24,4 +24,4 @@ "inheritance": null, "extAttrs": [] } -] \ No newline at end of file +] diff --git a/test/syntax/json/constants.json b/test/syntax/json/constants.json index 75222866..aa5bb274 100644 --- a/test/syntax/json/constants.json +++ b/test/syntax/json/constants.json @@ -95,4 +95,4 @@ "inheritance": null, "extAttrs": [] } -] \ No newline at end of file +] diff --git a/test/syntax/json/dictionary-inherits.json b/test/syntax/json/dictionary-inherits.json index ef30b1ab..48545140 100644 --- a/test/syntax/json/dictionary-inherits.json +++ b/test/syntax/json/dictionary-inherits.json @@ -76,4 +76,4 @@ "inheritance": "PaintOptions", "extAttrs": [] } -] \ No newline at end of file +] diff --git a/test/syntax/json/dictionary.json b/test/syntax/json/dictionary.json index 28494ce4..00d333c6 100644 --- a/test/syntax/json/dictionary.json +++ b/test/syntax/json/dictionary.json @@ -124,4 +124,4 @@ ], "extAttrs": [] } -] \ No newline at end of file +] diff --git a/test/syntax/json/documentation-dos.json b/test/syntax/json/documentation-dos.json index 340e039b..baa0b5a0 100644 --- a/test/syntax/json/documentation-dos.json +++ b/test/syntax/json/documentation-dos.json @@ -7,4 +7,4 @@ "inheritance": null, "extAttrs": [] } -] \ No newline at end of file +] diff --git a/test/syntax/json/documentation.json b/test/syntax/json/documentation.json index 340e039b..baa0b5a0 100644 --- a/test/syntax/json/documentation.json +++ b/test/syntax/json/documentation.json @@ -7,4 +7,4 @@ "inheritance": null, "extAttrs": [] } -] \ No newline at end of file +] diff --git a/test/syntax/json/enum.json b/test/syntax/json/enum.json index 88a608ba..b27eeb7c 100644 --- a/test/syntax/json/enum.json +++ b/test/syntax/json/enum.json @@ -3,9 +3,18 @@ "type": "enum", "name": "MealType", "values": [ - { "type": "string", "value": "rice" }, - { "type": "string", "value": "noodles" }, - { "type": "string", "value": "other" } + { + "type": "string", + "value": "rice" + }, + { + "type": "string", + "value": "noodles" + }, + { + "type": "string", + "value": "other" + } ], "extAttrs": [] }, @@ -99,9 +108,18 @@ "type": "enum", "name": "AltMealType", "values": [ - { "type": "string", "value": "rice" }, - { "type": "string", "value": "noodles" }, - { "type": "string", "value": "other" } + { + "type": "string", + "value": "rice" + }, + { + "type": "string", + "value": "noodles" + }, + { + "type": "string", + "value": "other" + } ], "extAttrs": [] } diff --git a/test/syntax/json/extended-attributes.json b/test/syntax/json/extended-attributes.json index b3081bf7..4b6bec14 100644 --- a/test/syntax/json/extended-attributes.json +++ b/test/syntax/json/extended-attributes.json @@ -30,140 +30,140 @@ ] }, { - "type": "interface", - "name": "IdInterface", - "partial": false, - "members": [], - "inheritance": null, - "extAttrs": [ - { - "name": "IntAttr", - "arguments": null, - "type": "extended-attribute", - "rhs": { - "type": "integer", - "value": "0" - } - }, - { - "name": "FloatAttr", - "arguments": null, - "type": "extended-attribute", - "rhs": { - "type": "float", - "value": "3.14" - } - }, - { - "name": "StringAttr", - "arguments": null, - "type": "extended-attribute", - "rhs": { - "type": "string", - "value": "\"abc\"" - } - } - ] + "type": "interface", + "name": "IdInterface", + "partial": false, + "members": [], + "inheritance": null, + "extAttrs": [ + { + "name": "IntAttr", + "arguments": null, + "type": "extended-attribute", + "rhs": { + "type": "integer", + "value": "0" + } + }, + { + "name": "FloatAttr", + "arguments": null, + "type": "extended-attribute", + "rhs": { + "type": "float", + "value": "3.14" + } + }, + { + "name": "StringAttr", + "arguments": null, + "type": "extended-attribute", + "rhs": { + "type": "string", + "value": "\"abc\"" + } + } + ] }, { - "type": "interface", - "name": "Circle", - "partial": false, - "members": [ - { - "type": "attribute", - "static": false, - "stringifier": false, - "inherit": false, - "readonly": false, - "idlType": { - "sequence": false, - "generic": null, - "nullable": false, - "union": false, - "idlType": "double" - }, - "name": "r", - "extAttrs": [] - }, - { - "type": "attribute", - "static": false, - "stringifier": false, - "inherit": false, - "readonly": false, - "idlType": { - "sequence": false, - "generic": null, - "nullable": false, - "union": false, - "idlType": "double" - }, - "name": "cx", - "extAttrs": [] - }, - { - "type": "attribute", - "static": false, - "stringifier": false, - "inherit": false, - "readonly": false, - "idlType": { - "sequence": false, - "generic": null, - "nullable": false, - "union": false, - "idlType": "double" - }, - "name": "cy", - "extAttrs": [] - }, - { - "type": "attribute", - "static": false, - "stringifier": false, - "inherit": false, - "readonly": true, - "idlType": { - "sequence": false, - "generic": null, - "nullable": false, - "union": false, - "idlType": "double" - }, - "name": "circumference", - "extAttrs": [] - } - ], - "inheritance": null, - "extAttrs": [ - { - "name": "Constructor", - "arguments": null, - "type": "extended-attribute", - "rhs": null - }, - { - "name": "Constructor", - "arguments": [ + "type": "interface", + "name": "Circle", + "partial": false, + "members": [ + { + "type": "attribute", + "static": false, + "stringifier": false, + "inherit": false, + "readonly": false, + "idlType": { + "sequence": false, + "generic": null, + "nullable": false, + "union": false, + "idlType": "double" + }, + "name": "r", + "extAttrs": [] + }, + { + "type": "attribute", + "static": false, + "stringifier": false, + "inherit": false, + "readonly": false, + "idlType": { + "sequence": false, + "generic": null, + "nullable": false, + "union": false, + "idlType": "double" + }, + "name": "cx", + "extAttrs": [] + }, + { + "type": "attribute", + "static": false, + "stringifier": false, + "inherit": false, + "readonly": false, + "idlType": { + "sequence": false, + "generic": null, + "nullable": false, + "union": false, + "idlType": "double" + }, + "name": "cy", + "extAttrs": [] + }, + { + "type": "attribute", + "static": false, + "stringifier": false, + "inherit": false, + "readonly": true, + "idlType": { + "sequence": false, + "generic": null, + "nullable": false, + "union": false, + "idlType": "double" + }, + "name": "circumference", + "extAttrs": [] + } + ], + "inheritance": null, + "extAttrs": [ { - "optional": false, - "variadic": false, - "extAttrs": [], - "idlType": { - "sequence": false, - "generic": null, - "nullable": false, - "union": false, - "idlType": "double" - }, - "name": "radius" + "name": "Constructor", + "arguments": null, + "type": "extended-attribute", + "rhs": null + }, + { + "name": "Constructor", + "arguments": [ + { + "optional": false, + "variadic": false, + "extAttrs": [], + "idlType": { + "sequence": false, + "generic": null, + "nullable": false, + "union": false, + "idlType": "double" + }, + "name": "radius" + } + ], + "type": "extended-attribute", + "rhs": null } - ], - "type": "extended-attribute", - "rhs": null - } - ] + ] }, { "type": "interface", diff --git a/test/syntax/json/inherits-getter.json b/test/syntax/json/inherits-getter.json index ba6bafdf..a37a9851 100644 --- a/test/syntax/json/inherits-getter.json +++ b/test/syntax/json/inherits-getter.json @@ -65,4 +65,4 @@ "inheritance": "Animal", "extAttrs": [] } -] \ No newline at end of file +] diff --git a/test/syntax/json/interface-inherits.json b/test/syntax/json/interface-inherits.json index e78c1cce..51c9aefa 100644 --- a/test/syntax/json/interface-inherits.json +++ b/test/syntax/json/interface-inherits.json @@ -74,4 +74,4 @@ "inheritance": "Animal", "extAttrs": [] } -] \ No newline at end of file +] diff --git a/test/syntax/json/iterable.json b/test/syntax/json/iterable.json index d4b97fba..bb92db89 100644 --- a/test/syntax/json/iterable.json +++ b/test/syntax/json/iterable.json @@ -7,7 +7,7 @@ { "type": "iterable", "idlType": [ - { + { "sequence": false, "generic": null, "nullable": false, @@ -81,4 +81,3 @@ "extAttrs": [] } ] - diff --git a/test/syntax/json/legacyiterable.json b/test/syntax/json/legacyiterable.json index eca1e6b3..e8a4ed66 100644 --- a/test/syntax/json/legacyiterable.json +++ b/test/syntax/json/legacyiterable.json @@ -22,4 +22,3 @@ "extAttrs": [] } ] - diff --git a/test/syntax/json/maplike.json b/test/syntax/json/maplike.json index 97e76d58..a533838f 100644 --- a/test/syntax/json/maplike.json +++ b/test/syntax/json/maplike.json @@ -106,4 +106,3 @@ "extAttrs": [] } ] - diff --git a/test/syntax/json/namedconstructor.json b/test/syntax/json/namedconstructor.json index cee16306..908bb040 100644 --- a/test/syntax/json/namedconstructor.json +++ b/test/syntax/json/namedconstructor.json @@ -40,4 +40,4 @@ } ] } -] \ No newline at end of file +] diff --git a/test/syntax/json/nullable.json b/test/syntax/json/nullable.json index 2c83c3da..dc9cf7f7 100644 --- a/test/syntax/json/nullable.json +++ b/test/syntax/json/nullable.json @@ -44,4 +44,4 @@ "inheritance": null, "extAttrs": [] } -] \ No newline at end of file +] diff --git a/test/syntax/json/partial-interface.json b/test/syntax/json/partial-interface.json index e95af2ba..8a3ce13b 100644 --- a/test/syntax/json/partial-interface.json +++ b/test/syntax/json/partial-interface.json @@ -48,4 +48,4 @@ ], "extAttrs": [] } -] \ No newline at end of file +] diff --git a/test/syntax/json/primitives.json b/test/syntax/json/primitives.json index 7568542f..9cfaabb2 100644 --- a/test/syntax/json/primitives.json +++ b/test/syntax/json/primitives.json @@ -280,4 +280,4 @@ "inheritance": null, "extAttrs": [] } -] \ No newline at end of file +] diff --git a/test/syntax/json/putforwards.json b/test/syntax/json/putforwards.json index 1b0a7b6b..d1692dfa 100644 --- a/test/syntax/json/putforwards.json +++ b/test/syntax/json/putforwards.json @@ -50,4 +50,4 @@ "inheritance": null, "extAttrs": [] } -] \ No newline at end of file +] diff --git a/test/syntax/json/sequence.json b/test/syntax/json/sequence.json index 79821181..8cb98849 100644 --- a/test/syntax/json/sequence.json +++ b/test/syntax/json/sequence.json @@ -75,7 +75,6 @@ "name": "Foo", "partial": false, "members": [ - { "type": "operation", "getter": false, @@ -98,7 +97,6 @@ "inheritance": null, "extAttrs": [] }, - { "type": "interface", "name": "I", diff --git a/test/syntax/json/setlike.json b/test/syntax/json/setlike.json index cfaac319..d955dfd3 100644 --- a/test/syntax/json/setlike.json +++ b/test/syntax/json/setlike.json @@ -77,4 +77,3 @@ "extAttrs": [] } ] - diff --git a/test/syntax/json/typedef-union.json b/test/syntax/json/typedef-union.json index 9c87672c..e812e1f0 100644 --- a/test/syntax/json/typedef-union.json +++ b/test/syntax/json/typedef-union.json @@ -1,49 +1,43 @@ [ - { - "type" : "typedef", - "idlType" : { - "nullable" : false, - "generic" : null, - "union" : true, - "idlType" : [ - { - "union" : false, - "generic" : null, - "nullable" : false, - "array" : false, - "sequence" : false, - "idlType" : "ImageData" - }, - { - "generic" : null, - "union" : false, - "nullable" : false, - "array" : false, - "idlType" : "HTMLImageElement", - "sequence" : false - }, - { - "array" : false, - "sequence" : false, - "idlType" : "HTMLCanvasElement", - "generic" : null, - "union" : false, - "nullable" : false - }, - { - "union" : false, - "generic" : null, - "nullable" : false, - "array" : false, - "sequence" : false, - "idlType" : "HTMLVideoElement" - } - ], - "sequence" : false, - "array" : false - }, - "name" : "TexImageSource", - "extAttrs" : [], - "typeExtAttrs" : [] - } + { + "type": "typedef", + "idlType": { + "sequence": false, + "generic": null, + "nullable": false, + "union": true, + "idlType": [ + { + "sequence": false, + "generic": null, + "nullable": false, + "union": false, + "idlType": "ImageData" + }, + { + "sequence": false, + "generic": null, + "nullable": false, + "union": false, + "idlType": "HTMLImageElement" + }, + { + "sequence": false, + "generic": null, + "nullable": false, + "union": false, + "idlType": "HTMLCanvasElement" + }, + { + "sequence": false, + "generic": null, + "nullable": false, + "union": false, + "idlType": "HTMLVideoElement" + } + ] + }, + "name": "TexImageSource", + "extAttrs": [] + } ] diff --git a/test/syntax/json/uniontype.json b/test/syntax/json/uniontype.json index c4725d41..4cd56d6c 100644 --- a/test/syntax/json/uniontype.json +++ b/test/syntax/json/uniontype.json @@ -1,118 +1,118 @@ [ - { - "partial": false, - "members": [ - { - "idlType": { - "idlType": [ - { - "union": false, - "sequence": false, - "generic": null, - "idlType": "float", - "nullable": false - }, - { - "idlType": [ + { + "type": "interface", + "name": "Union", + "partial": false, + "members": [ + { + "type": "attribute", + "static": false, + "stringifier": false, + "inherit": false, + "readonly": false, + "idlType": { + "sequence": false, + "generic": null, + "nullable": false, + "union": true, + "idlType": [ { - "nullable": false, - "idlType": "Date", - "sequence": false, - "generic": null, - "union": false + "sequence": false, + "generic": null, + "nullable": false, + "union": false, + "idlType": "float" }, { - "nullable": false, - "idlType": "Event", - "generic": null, - "sequence": false, - "union": false - } - ], - "nullable": false, - "sequence": false, - "generic": null, - "union": true - }, - { - "generic": null, - "sequence": false, - "idlType": [ - { - "union": false, - "sequence": false, - "generic": null, - "nullable": false, - "idlType": "Node" + "sequence": false, + "generic": null, + "nullable": false, + "union": true, + "idlType": [ + { + "sequence": false, + "generic": null, + "nullable": false, + "union": false, + "idlType": "Date" + }, + { + "sequence": false, + "generic": null, + "nullable": false, + "union": false, + "idlType": "Event" + } + ] }, { - "nullable": false, - "idlType": "DOMString", - "sequence": false, - "generic": null, - "union": false + "sequence": false, + "generic": null, + "nullable": true, + "union": true, + "idlType": [ + { + "sequence": false, + "generic": null, + "nullable": false, + "union": false, + "idlType": "Node" + }, + { + "sequence": false, + "generic": null, + "nullable": false, + "union": false, + "idlType": "DOMString" + } + ] } - ], - "nullable": true, - "union": true - } - ], - "nullable": false, - "generic": null, - "sequence": false, - "union": true + ] + }, + "name": "test", + "extAttrs": [] }, - "name": "test", - "inherit": false, - "type": "attribute", - "extAttrs": [], - "readonly": false, - "stringifier": false, - "static": false - }, - { - "readonly": false, - "extAttrs": [], - "stringifier": false, - "static": false, - "name": "test2", - "idlType": { - "nullable": false, - "idlType": [ - { - "extAttrs": [ + { + "type": "attribute", + "static": false, + "stringifier": false, + "inherit": false, + "readonly": false, + "idlType": { + "sequence": false, + "generic": null, + "nullable": false, + "union": true, + "idlType": [ { - "name": "EnforceRange", - "arguments": null, - "type": "extended-attribute", - "rhs": null + "sequence": false, + "generic": null, + "nullable": false, + "union": false, + "idlType": "long", + "extAttrs": [ + { + "name": "EnforceRange", + "arguments": null, + "type": "extended-attribute", + "rhs": null + } + ] + }, + { + "sequence": false, + "generic": null, + "nullable": false, + "union": false, + "idlType": "Date" } - ], - "nullable": false, - "idlType": "long", - "generic": null, - "sequence": false, - "union": false - }, - { - "union": false, - "sequence": false, - "generic": null, - "idlType": "Date", - "nullable": false - } - ], - "generic": null, - "sequence": false, - "union": true - }, - "inherit": false, - "type": "attribute" - } - ], - "inheritance": null, - "name": "Union", - "extAttrs": [], - "type": "interface" - } + ] + }, + "name": "test2", + "extAttrs": [] + } + ], + "inheritance": null, + "extAttrs": [] + } ] diff --git a/test/util/acquire.js b/test/util/acquire.js new file mode 100644 index 00000000..6f37dd60 --- /dev/null +++ b/test/util/acquire.js @@ -0,0 +1,8 @@ +"use strict"; + +const { collect } = require("./collect"); +const fs = require("fs"); + +for (const test of collect("syntax")) { + fs.writeFileSync(test.jsonPath, `${JSON.stringify(test.ast, null, 4)}\n`) +} diff --git a/test/util/collect.js b/test/util/collect.js new file mode 100644 index 00000000..83f288ac --- /dev/null +++ b/test/util/collect.js @@ -0,0 +1,59 @@ +"use strict"; + +const wp = require("../../lib/webidl2"); +const pth = require("path"); +const fs = require("fs"); +const jdp = require("jsondiffpatch"); + +/** + * Collects test items from the specified directory + * @param {string} base + */ +function* collect(base, { expectError } = {}) { + base = pth.join(__dirname, "..", base); + const dir = pth.join(base, "idl"); + const idls = fs.readdirSync(dir) + .filter(it => (/\.widl$/).test(it)) + .map(it => pth.join(dir, it)); + + for (const path of idls) { + const optFile = pth.join(base, "opt", pth.basename(path)).replace(".widl", ".json"); + let opt; + if (fs.existsSync(optFile)) + opt = JSON.parse(fs.readFileSync(optFile, "utf8")); + + try { + const ast = wp.parse(fs.readFileSync(path, "utf8").replace(/\r\n/g, "\n"), opt); + yield new TestItem({ ast, path, opt }); + } + catch (error) { + if (expectError) { + yield new TestItem({ path, error }); + } + else { + throw e; + } + } + } +}; + + +class TestItem { + constructor({ ast, path, error, opt }) { + this.ast = ast; + this.path = path; + this.error = error; + this.opt = opt; + this.jsonPath = pth.join(pth.dirname(path), "../json", pth.basename(path).replace(".widl", ".json")); + } + + readJSON() { + return JSON.parse(fs.readFileSync(this.jsonPath, "utf8")); + } + + diff(target = this.readJSON()) { + return jdp.diff(target, this.ast); + } +} + +module.exports.collect = collect; diff --git a/test/writer.js b/test/writer.js index f9ed6591..e84076b4 100644 --- a/test/writer.js +++ b/test/writer.js @@ -1,32 +1,16 @@ "use strict"; +const { collect } = require("./util/collect"); const wp = require("../lib/webidl2"); const writer = require("../lib/writer"); const expect = require("expect"); -const pth = require("path"); -const fs = require("fs"); -const jdp = require("jsondiffpatch"); const debug = true; describe("Rewrite and parses all of the IDLs to produce the same ASTs", () => { - const dir = pth.join(__dirname, "syntax/idl"); - const skip = {}; // use if we have a broken test - const idls = fs.readdirSync(dir) - .filter(it => (/\.widl$/).test(it) && !skip[it]) - .map(it => pth.join(dir, it)); - - for (const idl of idls) { - const json = pth.join(__dirname, "syntax/json", pth.basename(idl).replace(".widl", ".json")); - - it(`should produce the same AST for ${idl}`, () => { + for (const test of collect("syntax")) { + it(`should produce the same AST for ${test.path}`, () => { try { - const ast = JSON.parse(fs.readFileSync(json, "utf8")); - const optFile = pth.join(__dirname, "syntax/opt", pth.basename(json)); - let opt = undefined; - if (fs.existsSync(optFile)) - opt = JSON.parse(fs.readFileSync(optFile, "utf8")); - const diff = jdp.diff(ast, - wp.parse(writer.write(ast), opt)); + const diff = test.diff(wp.parse(writer.write(test.ast), test.opt)); if (diff && debug) console.log(JSON.stringify(diff, null, 4)); expect(diff).toBe(undefined); }