* @typedef {Object} ExtraParams @property {any} spinner } * @typedef {Object} ForEachTestFile * @property {string} [actionName] * @property {(arg0: SchemaFile, arg1: ExtraParams) => Promise } [onSchemaFile] * @property {(arg0: SchemaFile, arg1: DataFile, data: any, arg2: ExtraParams) => P
(/** @type {ForEachTestFile} */ obj)
| 220 | * @property {(arg0: SchemaFile, arg1: ExtraParams) => Promise<void>} [afterSchemaFile] |
| 221 | */ |
| 222 | async function forEachFile(/** @type {ForEachTestFile} */ obj) { |
| 223 | const spinner = ora() |
| 224 | if (obj.actionName) { |
| 225 | spinner.start() |
| 226 | } |
| 227 | |
| 228 | let hasValidatedAtLeastOneFile = false |
| 229 | for (const dirent1 of await fs.readdir(SchemaDir, { withFileTypes: true })) { |
| 230 | if (isIgnoredFile(dirent1.name)) continue |
| 231 | |
| 232 | const schemaName = dirent1.name |
| 233 | const schemaId = schemaName.replace('.json', '') |
| 234 | |
| 235 | if (argv['schema-name'] && argv['schema-name'] !== schemaName) { |
| 236 | continue |
| 237 | } |
| 238 | |
| 239 | if (SchemaValidation.skiptest.includes(schemaName)) { |
| 240 | continue |
| 241 | } |
| 242 | |
| 243 | hasValidatedAtLeastOneFile = true |
| 244 | |
| 245 | const schemaPath = path.join(SchemaDir, schemaName) |
| 246 | const schemaFile = await toFile(schemaPath) |
| 247 | if (obj.actionName) { |
| 248 | if (process.env.CI) { |
| 249 | console.info( |
| 250 | `Running "${obj.actionName}" on file "./${schemaFile.path}"`, |
| 251 | ) |
| 252 | } else { |
| 253 | spinner.text = `Running "${obj.actionName}" on file "./${schemaFile.path}"` |
| 254 | } |
| 255 | } |
| 256 | const data = await obj?.onSchemaFile?.(schemaFile, { spinner }) |
| 257 | |
| 258 | if (obj?.onPositiveTestFile) { |
| 259 | const positiveTestDir = path.join(TestPositiveDir, schemaId) |
| 260 | for (const testfile of await fs |
| 261 | .readdir(positiveTestDir) |
| 262 | .catch(ignoreOnlyENOENT)) { |
| 263 | if (isIgnoredFile(testfile)) continue |
| 264 | |
| 265 | const testfilePath = path.join(TestPositiveDir, schemaId, testfile) |
| 266 | let file = await toFile(testfilePath) |
| 267 | await obj.onPositiveTestFile(schemaFile, file, data, { spinner }) |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | if (obj?.onNegativeTestFile) { |
| 272 | const negativeTestDir = path.join(TestNegativeDir, schemaId) |
| 273 | for (const testfile of await fs |
| 274 | .readdir(negativeTestDir) |
| 275 | .catch(ignoreOnlyENOENT)) { |
| 276 | if (isIgnoredFile(testfile)) continue |
| 277 | |
| 278 | const testfilePath = path.join(TestNegativeDir, schemaId, testfile) |
| 279 | let file = await toFile(testfilePath) |
no test coverage detected