MCPcopy Create free account
hub / github.com/firebase/firebase-tools / parseTestFilesRecursive

Function parseTestFilesRecursive

src/apptesting/parseTestFiles.ts:97–137  ·  view source on GitHub ↗
(params: {
  testDir: string;
  targetUri?: string;
})

Source from the content-addressed store, hash-verified

95}
96
97async 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
139export function pluralizeTests(numTests: number) {
140 return `${numTests} test${numTests === 1 ? "" : "s"}`;

Callers 1

parseTestFilesFunction · 0.85

Calls 8

listFilesFunction · 0.90
dirExistsSyncFunction · 0.90
fileExistsSyncFunction · 0.90
readFileFromDirectoryFunction · 0.90
wrappedSafeLoadFunction · 0.90
getErrMsgFunction · 0.90
toTestCaseInvocationFunction · 0.85
pluralizeTestsFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…