ast.spec.js (1016B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 import { getAst } from "../ast"; 6 import { setSource } from "../../sources"; 7 import cases from "jest-in-case"; 8 9 import { makeMockSourceAndContent } from "../../../../utils/test-mockup"; 10 11 const astKeys = [ 12 "type", 13 "start", 14 "end", 15 "loc", 16 "errors", 17 "program", 18 "comments", 19 "tokens", 20 ]; 21 22 cases( 23 "ast.getAst", 24 ({ name }) => { 25 const source = makeMockSourceAndContent(undefined, "foo", name, "2"); 26 setSource({ 27 id: source.id, 28 text: source.content.value || "", 29 contentType: source.content.contentType, 30 isWasm: false, 31 }); 32 const ast = getAst("foo"); 33 expect(ast && Object.keys(ast)).toEqual(astKeys); 34 }, 35 [ 36 { name: "text/javascript" }, 37 { name: "application/javascript" }, 38 { name: "application/x-javascript" }, 39 { name: "text/jsx" }, 40 ] 41 );