(pathToTestDir: string, targetFeatureOrGlobal: string, args: FeaturesTestCommandInput, testResults: TestResult[] = [])
| 320 | } |
| 321 | |
| 322 | async function doScenario(pathToTestDir: string, targetFeatureOrGlobal: string, args: FeaturesTestCommandInput, testResults: TestResult[] = []): Promise<TestResult[]> { |
| 323 | const { collectionFolder, cliHost, filter } = args; |
| 324 | const scenariosPath = path.join(pathToTestDir, 'scenarios.json'); |
| 325 | |
| 326 | if (!(await cliHost.isFile(scenariosPath))) { |
| 327 | log(`No scenario file found at '${scenariosPath}'. Skipping...`, { prefix: '⚠️', }); |
| 328 | return testResults; |
| 329 | } |
| 330 | |
| 331 | // Read in scenarios.json |
| 332 | const scenariosBuffer = await cliHost.readFile(scenariosPath); |
| 333 | // Parse to json |
| 334 | let scenarios: Scenarios = {}; |
| 335 | let errors: jsonc.ParseError[] = []; |
| 336 | scenarios = jsonc.parse(scenariosBuffer.toString(), errors); |
| 337 | if (errors.length > 0) { |
| 338 | // Print each jsonc error |
| 339 | errors.forEach(error => { |
| 340 | log(`${jsonc.printParseErrorCode(error.error)}`, { prefix: '⚠️' }); |
| 341 | }); |
| 342 | fail(`Failed to parse scenarios.json at ${scenariosPath}`); |
| 343 | return []; // We never reach here, we exit via fail() |
| 344 | } |
| 345 | |
| 346 | // For EACH scenario: Spin up a container and exec the scenario test script |
| 347 | for (const [scenarioName, scenarioConfig] of Object.entries(scenarios)) { |
| 348 | |
| 349 | if (filter && !scenarioName.includes(filter)) { |
| 350 | continue; |
| 351 | } |
| 352 | |
| 353 | log(`Running scenario: ${scenarioName}`); |
| 354 | |
| 355 | // Check if we have a scenario test script, otherwise skip. |
| 356 | if (!(await cliHost.isFile(path.join(pathToTestDir, `${scenarioName}.sh`)))) { |
| 357 | fail(`No scenario test script found at path '${path.join(pathToTestDir, `${scenarioName}.sh`)}'. Either add a script to the test folder, or remove from scenarios.json.`); |
| 358 | } |
| 359 | |
| 360 | // Create Container |
| 361 | const workspaceFolder = await generateProjectFromScenario(cliHost, collectionFolder, scenarioName, scenarioConfig, targetFeatureOrGlobal); |
| 362 | const params = await generateDockerParams(workspaceFolder, args); |
| 363 | await createContainerFromWorkingDirectory(params, workspaceFolder, args); |
| 364 | |
| 365 | // Move the entire test directory for the given Feature into the workspaceFolder |
| 366 | await cpDirectoryLocal(pathToTestDir, workspaceFolder); |
| 367 | |
| 368 | // Move the test library script into the workspaceFolder |
| 369 | await cliHost.writeFile(path.join(workspaceFolder, TEST_LIBRARY_SCRIPT_NAME), Buffer.from(testLibraryScript)); |
| 370 | |
| 371 | // Execute Test |
| 372 | testResults.push({ |
| 373 | testName: scenarioName, |
| 374 | result: await execTest(`${scenarioName}.sh`, workspaceFolder, cliHost) |
| 375 | }); |
| 376 | } |
| 377 | return testResults; |
| 378 | } |
| 379 |
no test coverage detected