|
| 1 | +import assert from "assert"; |
| 2 | +import fs from "fs"; |
| 3 | +import path from "path"; |
| 4 | + |
| 5 | +import { parseForESLint } from "../../../src/index.js"; |
| 6 | +import { extractSelectorLocations } from "./style-selector-location-converter-utils.js"; |
| 7 | +import { generateParserOptions, listupFixtures } from "./test-utils.js"; |
| 8 | + |
| 9 | +const dirname = path.dirname(new URL(import.meta.url).pathname); |
| 10 | +const SELECTOR_CONVERTER_FIXTURE_ROOT = path.resolve( |
| 11 | + dirname, |
| 12 | + "../../fixtures/parser/style-selector-location-converter", |
| 13 | +); |
| 14 | + |
| 15 | +function parse(code: string, filePath: string, config: any) { |
| 16 | + return parseForESLint(code, generateParserOptions({ filePath }, config)); |
| 17 | +} |
| 18 | + |
| 19 | +describe("Check for AST.", () => { |
| 20 | + for (const { |
| 21 | + input, |
| 22 | + inputFileName, |
| 23 | + outputFileName, |
| 24 | + config, |
| 25 | + meetRequirements, |
| 26 | + } of listupFixtures(SELECTOR_CONVERTER_FIXTURE_ROOT)) { |
| 27 | + describe(inputFileName, () => { |
| 28 | + let services: any; |
| 29 | + |
| 30 | + it("most to generate the expected style context.", () => { |
| 31 | + services = parse(input, inputFileName, config).services; |
| 32 | + if (!meetRequirements("test")) { |
| 33 | + return; |
| 34 | + } |
| 35 | + const styleContext = services.getStyleContext(); |
| 36 | + assert.strictEqual(styleContext.status, "success"); |
| 37 | + const locations = extractSelectorLocations( |
| 38 | + services, |
| 39 | + styleContext.sourceAst, |
| 40 | + ); |
| 41 | + const output = fs.readFileSync(outputFileName, "utf8"); |
| 42 | + assert.strictEqual( |
| 43 | + `${JSON.stringify(locations, undefined, 2)}\n`, |
| 44 | + output, |
| 45 | + ); |
| 46 | + }); |
| 47 | + }); |
| 48 | + } |
| 49 | +}); |
0 commit comments