(params: {
testDir: string;
targetUri?: string;
})
| 95 | } |
| 96 | |
| 97 | async function parseTestFilesRecursive(params: { |
| 98 | testDir: string; |
| 99 | targetUri?: string; |
| 100 | }): Promise<TestCaseFile[]> { |
| 101 | const testDir = params.testDir; |
| 102 | const targetUri = params.targetUri; |
| 103 | const filenames = listFiles(testDir); |
| 104 | const results = []; |
| 105 | for (const filename of filenames) { |
| 106 | const path = join(testDir, filename); |
| 107 | if (dirExistsSync(path)) { |
| 108 | results.push(...(await parseTestFilesRecursive({ testDir: path, targetUri }))); |
| 109 | } else if (fileExistsSync(path) && (path.endsWith(".yaml") || path.endsWith(".yml"))) { |
| 110 | try { |
| 111 | logger.debug(`Reading ${path}.`); |
| 112 | const file = await readFileFromDirectory(testDir, filename); |
| 113 | const parsedFile = wrappedSafeLoad(file.source); |
| 114 | const tests = parsedFile.tests; |
| 115 | const defaultConfig = parsedFile.defaultConfig; |
| 116 | if (!tests || !tests.length) { |
| 117 | logger.debug(`No tests found in ${path}. Ignoring.`); |
| 118 | continue; |
| 119 | } |
| 120 | logger.debug(`File contains ${pluralizeTests(tests.length)}.`); |
| 121 | const invocations = []; |
| 122 | for (const rawTestDef of tests) { |
| 123 | const invocation = toTestCaseInvocation(rawTestDef, targetUri, defaultConfig); |
| 124 | invocations.push(invocation); |
| 125 | } |
| 126 | results.push({ path, invocations: invocations }); |
| 127 | } catch (ex) { |
| 128 | const errMsg = getErrMsg(ex); |
| 129 | const errDetails = errMsg ? `Error details: \n${errMsg}` : ""; |
| 130 | logger.debug(`Unable to parse test file ${path}. Ignoring.${errDetails}`); |
| 131 | continue; |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | return results; |
| 137 | } |
| 138 | |
| 139 | export function pluralizeTests(numTests: number) { |
| 140 | return `${numTests} test${numTests === 1 ? "" : "s"}`; |
no test coverage detected
searching dependent graphs…