(stub, dir)
| 4 | |
| 5 | /** @param {string} stub @param {'exercises' | 'patch' | 'tests'} dir */ |
| 6 | export async function findFile(stub, dir) { |
| 7 | const folderFiles = await readdir( |
| 8 | fileURLToPath(new URL(`../../${dir}`, import.meta.url)) |
| 9 | ); |
| 10 | |
| 11 | const targetFileName = basename(stub, extname(stub)); |
| 12 | |
| 13 | const sourceFileNameWithExt = folderFiles.find((fileName) => { |
| 14 | if (dir === "exercises" && !fileName.endsWith(".wat")) return false; |
| 15 | if (dir === "patch" && !fileName.endsWith(".patch")) return false; |
| 16 | if (dir === "tests" && !fileName.endsWith(".test.js")) return false; |
| 17 | |
| 18 | return fileName.includes(targetFileName); |
| 19 | }); |
| 20 | |
| 21 | /** @type {string | undefined} */ |
| 22 | return sourceFileNameWithExt; |
| 23 | } |
no outgoing calls
no test coverage detected