@param { | ImportMeta | { importMeta: ImportMeta, snippets?: Snippet[] } } rawFixtures @param {string[]} explicitParsers @param {any} rawOptions
(rawFixtures, explicitParsers, rawOptions)
| 36 | @param {any} rawOptions |
| 37 | */ |
| 38 | function 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 | |
| 84 | export { runFormatTest }; |
no test coverage detected
searching dependent graphs…