MCPcopy
hub / github.com/prettier/prettier / runFormatTest

Function runFormatTest

tests/config/format-test/run-format-test.js:38–82  ·  view source on GitHub ↗

@param { | ImportMeta | { importMeta: ImportMeta, snippets?: Snippet[] } } rawFixtures @param {string[]} explicitParsers @param {any} rawOptions

(rawFixtures, explicitParsers, rawOptions)

Source from the content-addressed store, hash-verified

36@param {any} rawOptions
37*/
38function runFormatTest(rawFixtures, explicitParsers, rawOptions) {
39 const { importMeta, snippets = [] } = rawFixtures.importMeta
40 ? rawFixtures
41 : { importMeta: rawFixtures };
42
43 const filename = path.basename(new URL(importMeta.url).pathname);
44 if (filename !== FORMAT_TEST_SCRIPT_FILENAME) {
45 throw new Error(
46 `Format test should run in file named '${FORMAT_TEST_SCRIPT_FILENAME}'.`,
47 );
48 }
49
50 const dirname = normalizeDirectory(
51 path.dirname(url.fileURLToPath(importMeta.url)),
52 );
53
54 let options = { ...rawOptions };
55
56 // `IS_ERROR_TEST` mean to watch errors like:
57 // - syntax parser hasn't supported yet
58 // - syntax errors that should throws
59 const isErrorTest = isErrorTestDirectory(dirname);
60
61 if (isErrorTest) {
62 options = { errors: true, ...options };
63 }
64
65 // Make sure tests are in correct location
66
67 const context = {
68 dirname,
69 stringifiedOptions: stringifyOptionsForTitle(rawOptions),
70 parsers: getParsers(dirname, explicitParsers),
71 options,
72 explicitParsers,
73 rawOptions,
74 snippets,
75 };
76
77 verifyParsers(context);
78
79 for (const fixture of getFixtures(context)) {
80 testFixture(fixture);
81 }
82}
83
84export { runFormatTest };

Callers 15

format.test.jsFile · 0.85
format.test.jsFile · 0.85
format.test.jsFile · 0.85
format.test.jsFile · 0.85
format.test.jsFile · 0.85
format.test.jsFile · 0.85
format.test.jsFile · 0.85
format.test.jsFile · 0.85
format.test.jsFile · 0.85
format.test.jsFile · 0.85
format.test.jsFile · 0.85
format.test.jsFile · 0.85

Calls 6

normalizeDirectoryFunction · 0.90
stringifyOptionsForTitleFunction · 0.90
getParsersFunction · 0.90
verifyParsersFunction · 0.90
getFixturesFunction · 0.90
testFixtureFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…