@cucumber/cucumber 12.2.0 → 12.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +1 -1
  2. package/lib/api/run_cucumber.js +1 -0
  3. package/lib/api/run_cucumber.js.map +1 -1
  4. package/lib/cli/helpers.js +11 -1
  5. package/lib/cli/helpers.js.map +1 -1
  6. package/lib/configuration/argv_parser.js +1 -1
  7. package/lib/configuration/argv_parser.js.map +1 -1
  8. package/lib/filter/types.d.ts +2 -1
  9. package/lib/filter/types.js.map +1 -1
  10. package/lib/formatter/step_definition_snippet_builder/index.d.ts +1 -0
  11. package/lib/formatter/step_definition_snippet_builder/index.js +14 -0
  12. package/lib/formatter/step_definition_snippet_builder/index.js.map +1 -1
  13. package/lib/models/test_run_hook_definition.d.ts +6 -1
  14. package/lib/models/test_run_hook_definition.js +5 -0
  15. package/lib/models/test_run_hook_definition.js.map +1 -1
  16. package/lib/runtime/coordinator.d.ts +2 -1
  17. package/lib/runtime/coordinator.js +6 -5
  18. package/lib/runtime/coordinator.js.map +1 -1
  19. package/lib/runtime/make_runtime.d.ts +4 -3
  20. package/lib/runtime/make_runtime.js +20 -5
  21. package/lib/runtime/make_runtime.js.map +1 -1
  22. package/lib/runtime/make_suggestion.d.ts +7 -0
  23. package/lib/runtime/make_suggestion.js +31 -0
  24. package/lib/runtime/make_suggestion.js.map +1 -0
  25. package/lib/runtime/parallel/adapter.d.ts +4 -1
  26. package/lib/runtime/parallel/adapter.js +9 -1
  27. package/lib/runtime/parallel/adapter.js.map +1 -1
  28. package/lib/runtime/parallel/types.d.ts +3 -0
  29. package/lib/runtime/parallel/types.js.map +1 -1
  30. package/lib/runtime/parallel/worker.d.ts +1 -1
  31. package/lib/runtime/parallel/worker.js +9 -2
  32. package/lib/runtime/parallel/worker.js.map +1 -1
  33. package/lib/runtime/serial/adapter.d.ts +2 -1
  34. package/lib/runtime/serial/adapter.js +2 -2
  35. package/lib/runtime/serial/adapter.js.map +1 -1
  36. package/lib/runtime/test_case_runner.d.ts +4 -1
  37. package/lib/runtime/test_case_runner.js +12 -1
  38. package/lib/runtime/test_case_runner.js.map +1 -1
  39. package/lib/runtime/worker.d.ts +14 -6
  40. package/lib/runtime/worker.js +106 -14
  41. package/lib/runtime/worker.js.map +1 -1
  42. package/lib/support_code_library_builder/index.d.ts +1 -1
  43. package/lib/support_code_library_builder/index.js +6 -6
  44. package/lib/support_code_library_builder/index.js.map +1 -1
  45. package/lib/support_code_library_builder/types.d.ts +3 -0
  46. package/lib/support_code_library_builder/types.js.map +1 -1
  47. package/lib/tsconfig.node.tsbuildinfo +1 -1
  48. package/lib/version.d.ts +1 -1
  49. package/lib/version.js +1 -1
  50. package/lib/version.js.map +1 -1
  51. package/package.json +26 -26
  52. package/lib/runtime/run_test_run_hooks.d.ts +0 -4
  53. package/lib/runtime/run_test_run_hooks.js +0 -29
  54. package/lib/runtime/run_test_run_hooks.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../src/runtime/parallel/adapter.ts"],"names":[],"mappings":";;;;;;AAAA,2DAAuD;AACvD,0DAA4B;AAc5B,MAAM,aAAa,GAAG,mBAAI,CAAC,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC,CAAA;AAoB9D,MAAa,mBAAmB;IASX;IACA;IACA;IACA;IACA;IAZX,iBAAiB,GAAW,CAAC,CAAA;IAC7B,OAAO,GAAY,KAAK,CAAA;IACxB,QAAQ,CAA4B;IACpC,IAAI,GAA6B,EAAE,CAAA;IAC1B,UAAU,GAAsC,EAAE,CAAA;IAClD,OAAO,GAAkC,EAAE,CAAA;IAE5D,YACmB,WAA4B,EAC5B,MAAe,EACf,gBAA8B,EAC9B,OAA2B,EAC3B,kBAAsC;QAJtC,gBAAW,GAAX,WAAW,CAAiB;QAC5B,WAAM,GAAN,MAAM,CAAS;QACf,qBAAgB,GAAhB,gBAAgB,CAAc;QAC9B,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AC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAA;QAE5E,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;YAC3B,OAAM;QACR,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,aAAa,CAAA;QAEhD,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;QAC9B,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAA;QACjC,MAAM,CAAC,KAAK,8BAAsB,CAAA;QAClC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;YAClB,IAAI,EAAE,KAAK;YACX,iBAAiB,EAAE,IAAI;YACvB,OAAO,EAAE,IAAI,CAAC,OAAO;SACD,CAAC,CAAA;IACzB,CAAC;CACF;AA9KD,kDA8KC","sourcesContent":["import { ChildProcess, fork } from 'node:child_process'\nimport path from 'node:path'\nimport { EventEmitter } from 'node:events'\nimport { SupportCodeLibrary } from '../../support_code_library_builder/types'\nimport { AssembledTestCase } from '../../assemble'\nimport { ILogger, IRunEnvironment } from '../../environment'\nimport { RuntimeAdapter } from '../types'\nimport { IRunOptionsRuntime } from '../../api'\nimport {\n FinalizeCommand,\n InitializeCommand,\n RunCommand,\n WorkerToCoordinatorEvent,\n} from './types'\n\nconst runWorkerPath = path.resolve(__dirname, 'run_worker.js')\n\nconst enum WorkerState {\n 'idle',\n 'closed',\n 'running',\n 'new',\n}\n\ninterface ManagedWorker {\n state: WorkerState\n process: ChildProcess\n id: string\n}\n\ninterface WorkPlacement {\n index: number\n item: AssembledTestCase\n}\n\nexport class ChildProcessAdapter implements RuntimeAdapter {\n private idleInterventions: number = 0\n private failing: boolean = false\n private onFinish: (success: boolean) => void\n private todo: Array<AssembledTestCase> = []\n private readonly inProgress: Record<string, AssembledTestCase> = {}\n private readonly workers: Record<string, ManagedWorker> = {}\n\n constructor(\n private readonly environment: IRunEnvironment,\n private readonly logger: ILogger,\n private readonly eventBroadcaster: EventEmitter,\n private readonly options: IRunOptionsRuntime,\n private readonly supportCodeLibrary: SupportCodeLibrary\n ) {}\n\n parseWorkerMessage(\n worker: ManagedWorker,\n message: WorkerToCoordinatorEvent\n ): void {\n switch (message.type) {\n case 'READY':\n worker.state = WorkerState.idle\n this.awakenWorkers(worker)\n break\n case 'ENVELOPE':\n this.eventBroadcaster.emit('envelope', message.envelope)\n break\n case 'FINISHED':\n if (!message.success) {\n this.failing = true\n }\n delete this.inProgress[worker.id]\n worker.state = WorkerState.idle\n this.awakenWorkers(worker)\n break\n default:\n throw new Error(\n `Unexpected message from worker: ${JSON.stringify(message)}`\n )\n }\n }\n\n awakenWorkers(triggeringWorker: ManagedWorker): void {\n Object.values(this.workers).forEach((worker) => {\n if (worker.state === WorkerState.idle) {\n this.giveWork(worker)\n }\n return worker.state !== WorkerState.idle\n })\n\n if (Object.keys(this.inProgress).length == 0 && this.todo.length > 0) {\n this.giveWork(triggeringWorker, true)\n this.idleInterventions++\n }\n }\n\n startWorker(id: string, total: number): void {\n const workerProcess = fork(runWorkerPath, [], {\n cwd: this.environment.cwd,\n env: {\n ...this.environment.env,\n CUCUMBER_PARALLEL: 'true',\n CUCUMBER_TOTAL_WORKERS: total.toString(),\n CUCUMBER_WORKER_ID: id,\n },\n stdio: ['inherit', 'inherit', 'inherit', 'ipc'],\n })\n const worker = { state: WorkerState.new, process: workerProcess, id }\n this.workers[id] = worker\n worker.process.on('message', (message: WorkerToCoordinatorEvent) => {\n this.parseWorkerMessage(worker, message)\n })\n worker.process.on('close', (exitCode) => {\n worker.state = WorkerState.closed\n this.onWorkerProcessClose(exitCode)\n })\n worker.process.send({\n type: 'INITIALIZE',\n supportCodeCoordinates: this.supportCodeLibrary.originalCoordinates,\n supportCodeIds: {\n stepDefinitionIds: this.supportCodeLibrary.stepDefinitions.map(\n (s) => s.id\n ),\n beforeTestCaseHookDefinitionIds:\n this.supportCodeLibrary.beforeTestCaseHookDefinitions.map(\n (h) => h.id\n ),\n afterTestCaseHookDefinitionIds:\n this.supportCodeLibrary.afterTestCaseHookDefinitions.map((h) => h.id),\n },\n options: this.options,\n } satisfies InitializeCommand)\n }\n\n onWorkerProcessClose(exitCode: number): void {\n if (exitCode !== 0) {\n this.failing = true\n }\n\n if (\n Object.values(this.workers).every((x) => x.state === WorkerState.closed)\n ) {\n this.onFinish(!this.failing)\n }\n }\n\n async run(\n assembledTestCases: ReadonlyArray<AssembledTestCase>\n ): Promise<boolean> {\n this.todo = Array.from(assembledTestCases)\n return await new Promise<boolean>((resolve) => {\n for (let i = 0; i < this.options.parallel; i++) {\n this.startWorker(i.toString(), this.options.parallel)\n }\n this.onFinish = (status) => {\n if (this.idleInterventions > 0) {\n this.logger.warn(\n `WARNING: All workers went idle ${this.idleInterventions} time(s). Consider revising handler passed to setParallelCanAssign.`\n )\n }\n\n resolve(status)\n }\n })\n }\n\n nextWorkPlacement(): WorkPlacement {\n for (let index = 0; index < this.todo.length; index++) {\n const placement = this.placementAt(index)\n if (\n this.supportCodeLibrary.parallelCanAssign(\n placement.item.pickle,\n Object.values(this.inProgress).map(({ pickle }) => pickle)\n )\n ) {\n return placement\n }\n }\n\n return null\n }\n\n placementAt(index: number): WorkPlacement {\n return {\n index,\n item: this.todo[index],\n }\n }\n\n giveWork(worker: ManagedWorker, force: boolean = false): void {\n if (this.todo.length < 1) {\n worker.state = WorkerState.running\n worker.process.send({ type: 'FINALIZE' } satisfies FinalizeCommand)\n return\n }\n\n const workPlacement = force ? this.placementAt(0) : this.nextWorkPlacement()\n\n if (workPlacement === null) {\n return\n }\n\n const { index: nextIndex, item } = workPlacement\n\n this.todo.splice(nextIndex, 1)\n this.inProgress[worker.id] = item\n worker.state = WorkerState.running\n worker.process.send({\n type: 'RUN',\n assembledTestCase: item,\n failing: this.failing,\n } satisfies RunCommand)\n }\n}\n"]}
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../src/runtime/parall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MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;QAC9B,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAA;QACjC,MAAM,CAAC,KAAK,8BAAsB,CAAA;QAClC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;YAClB,IAAI,EAAE,KAAK;YACX,iBAAiB,EAAE,IAAI;YACvB,OAAO,EAAE,IAAI,CAAC,OAAO;SACD,CAAC,CAAA;IACzB,CAAC;CACF;AAzLD,kDAyLC","sourcesContent":["import { ChildProcess, fork } from 'node:child_process'\nimport path from 'node:path'\nimport { EventEmitter } from 'node:events'\nimport { SupportCodeLibrary } from '../../support_code_library_builder/types'\nimport { AssembledTestCase } from '../../assemble'\nimport { ILogger, IRunEnvironment } from '../../environment'\nimport { RuntimeAdapter } from '../types'\nimport { IRunOptionsRuntime } from '../../api'\nimport { FormatOptions } from '../../formatter'\nimport {\n FinalizeCommand,\n InitializeCommand,\n RunCommand,\n WorkerToCoordinatorEvent,\n} from './types'\n\nconst runWorkerPath = path.resolve(__dirname, 'run_worker.js')\n\nconst enum WorkerState {\n 'idle',\n 'closed',\n 'running',\n 'new',\n}\n\ninterface ManagedWorker {\n state: WorkerState\n process: ChildProcess\n id: string\n}\n\ninterface WorkPlacement {\n index: number\n item: AssembledTestCase\n}\n\nexport class ChildProcessAdapter implements RuntimeAdapter {\n private idleInterventions: number = 0\n private failing: boolean = false\n private onFinish: (success: boolean) => void\n private todo: Array<AssembledTestCase> = []\n private readonly inProgress: Record<string, AssembledTestCase> = {}\n private readonly workers: Record<string, ManagedWorker> = {}\n\n constructor(\n private readonly testRunStartedId: string,\n private readonly environment: IRunEnvironment,\n private readonly logger: ILogger,\n private readonly eventBroadcaster: EventEmitter,\n private readonly options: IRunOptionsRuntime,\n private readonly snippetOptions: Pick<\n FormatOptions,\n 'snippetInterface' | 'snippetSyntax'\n >,\n private readonly supportCodeLibrary: SupportCodeLibrary\n ) {}\n\n parseWorkerMessage(\n worker: ManagedWorker,\n message: WorkerToCoordinatorEvent\n ): void {\n switch (message.type) {\n case 'READY':\n worker.state = WorkerState.idle\n this.awakenWorkers(worker)\n break\n case 'ENVELOPE':\n this.eventBroadcaster.emit('envelope', message.envelope)\n break\n case 'FINISHED':\n if (!message.success) {\n this.failing = true\n }\n delete this.inProgress[worker.id]\n worker.state = WorkerState.idle\n this.awakenWorkers(worker)\n break\n default:\n throw new Error(\n `Unexpected message from worker: ${JSON.stringify(message)}`\n )\n }\n }\n\n awakenWorkers(triggeringWorker: ManagedWorker): void {\n Object.values(this.workers).forEach((worker) => {\n if (worker.state === WorkerState.idle) {\n this.giveWork(worker)\n }\n return worker.state !== WorkerState.idle\n })\n\n if (Object.keys(this.inProgress).length == 0 && this.todo.length > 0) {\n this.giveWork(triggeringWorker, true)\n this.idleInterventions++\n }\n }\n\n startWorker(id: string, total: number): void {\n const workerProcess = fork(runWorkerPath, [], {\n cwd: this.environment.cwd,\n env: {\n ...this.environment.env,\n CUCUMBER_PARALLEL: 'true',\n CUCUMBER_TOTAL_WORKERS: total.toString(),\n CUCUMBER_WORKER_ID: id,\n },\n stdio: ['inherit', 'inherit', 'inherit', 'ipc'],\n })\n const worker = { state: WorkerState.new, process: workerProcess, id }\n this.workers[id] = worker\n worker.process.on('message', (message: WorkerToCoordinatorEvent) => {\n this.parseWorkerMessage(worker, message)\n })\n worker.process.on('close', (exitCode) => {\n worker.state = WorkerState.closed\n this.onWorkerProcessClose(exitCode)\n })\n worker.process.send({\n type: 'INITIALIZE',\n testRunStartedId: this.testRunStartedId,\n supportCodeCoordinates: this.supportCodeLibrary.originalCoordinates,\n supportCodeIds: {\n stepDefinitionIds: this.supportCodeLibrary.stepDefinitions.map(\n (s) => s.id\n ),\n beforeTestCaseHookDefinitionIds:\n this.supportCodeLibrary.beforeTestCaseHookDefinitions.map(\n (h) => h.id\n ),\n afterTestCaseHookDefinitionIds:\n this.supportCodeLibrary.afterTestCaseHookDefinitions.map((h) => h.id),\n beforeTestRunHookDefinitionIds:\n this.supportCodeLibrary.beforeTestRunHookDefinitions.map((h) => h.id),\n afterTestRunHookDefinitionIds:\n this.supportCodeLibrary.afterTestRunHookDefinitions.map((h) => h.id),\n },\n options: this.options,\n snippetOptions: this.snippetOptions,\n } satisfies InitializeCommand)\n }\n\n onWorkerProcessClose(exitCode: number): void {\n if (exitCode !== 0) {\n this.failing = true\n }\n\n if (\n Object.values(this.workers).every((x) => x.state === WorkerState.closed)\n ) {\n this.onFinish(!this.failing)\n }\n }\n\n async run(\n assembledTestCases: ReadonlyArray<AssembledTestCase>\n ): Promise<boolean> {\n this.todo = Array.from(assembledTestCases)\n return await new Promise<boolean>((resolve) => {\n for (let i = 0; i < this.options.parallel; i++) {\n this.startWorker(i.toString(), this.options.parallel)\n }\n this.onFinish = (status) => {\n if (this.idleInterventions > 0) {\n this.logger.warn(\n `WARNING: All workers went idle ${this.idleInterventions} time(s). Consider revising handler passed to setParallelCanAssign.`\n )\n }\n\n resolve(status)\n }\n })\n }\n\n nextWorkPlacement(): WorkPlacement {\n for (let index = 0; index < this.todo.length; index++) {\n const placement = this.placementAt(index)\n if (\n this.supportCodeLibrary.parallelCanAssign(\n placement.item.pickle,\n Object.values(this.inProgress).map(({ pickle }) => pickle)\n )\n ) {\n return placement\n }\n }\n\n return null\n }\n\n placementAt(index: number): WorkPlacement {\n return {\n index,\n item: this.todo[index],\n }\n }\n\n giveWork(worker: ManagedWorker, force: boolean = false): void {\n if (this.todo.length < 1) {\n worker.state = WorkerState.running\n worker.process.send({ type: 'FINALIZE' } satisfies FinalizeCommand)\n return\n }\n\n const workPlacement = force ? this.placementAt(0) : this.nextWorkPlacement()\n\n if (workPlacement === null) {\n return\n }\n\n const { index: nextIndex, item } = workPlacement\n\n this.todo.splice(nextIndex, 1)\n this.inProgress[worker.id] = item\n worker.state = WorkerState.running\n worker.process.send({\n type: 'RUN',\n assembledTestCase: item,\n failing: this.failing,\n } satisfies RunCommand)\n }\n}\n"]}
@@ -3,12 +3,15 @@ import { RuntimeOptions } from '../index';
3
3
  import { ISupportCodeCoordinates } from '../../api';
4
4
  import { AssembledTestCase } from '../../assemble';
5
5
  import { CanonicalSupportCodeIds } from '../../support_code_library_builder/types';
6
+ import { FormatOptions } from '../../formatter';
6
7
  export type CoordinatorToWorkerCommand = InitializeCommand | RunCommand | FinalizeCommand;
7
8
  export interface InitializeCommand {
8
9
  type: 'INITIALIZE';
10
+ testRunStartedId: string;
9
11
  supportCodeCoordinates: ISupportCodeCoordinates;
10
12
  supportCodeIds: CanonicalSupportCodeIds;
11
13
  options: RuntimeOptions;
14
+ snippetOptions: Pick<FormatOptions, 'snippetInterface' | 'snippetSyntax'>;
12
15
  }
13
16
  export interface RunCommand {
14
17
  type: 'RUN';
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/runtime/parallel/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Envelope } from '@cucumber/messages'\nimport { RuntimeOptions } from '../index'\nimport { ISupportCodeCoordinates } from '../../api'\nimport { AssembledTestCase } from '../../assemble'\nimport { CanonicalSupportCodeIds } from '../../support_code_library_builder/types'\n\n// Messages from Coordinator to Worker\n\nexport type CoordinatorToWorkerCommand =\n | InitializeCommand\n | RunCommand\n | FinalizeCommand\n\nexport interface InitializeCommand {\n type: 'INITIALIZE'\n supportCodeCoordinates: ISupportCodeCoordinates\n supportCodeIds: CanonicalSupportCodeIds\n options: RuntimeOptions\n}\n\nexport interface RunCommand {\n type: 'RUN'\n assembledTestCase: AssembledTestCase\n failing: boolean\n}\n\nexport interface FinalizeCommand {\n type: 'FINALIZE'\n}\n\n// Messages from Worker to Coordinator\n\nexport type WorkerToCoordinatorEvent =\n | ReadyEvent\n | EnvelopeEvent\n | FinishedEvent\n\nexport interface ReadyEvent {\n type: 'READY'\n}\n\nexport interface EnvelopeEvent {\n type: 'ENVELOPE'\n envelope: Envelope\n}\n\nexport interface FinishedEvent {\n type: 'FINISHED'\n success: boolean\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/runtime/parallel/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Envelope } from '@cucumber/messages'\nimport { RuntimeOptions } from '../index'\nimport { ISupportCodeCoordinates } from '../../api'\nimport { AssembledTestCase } from '../../assemble'\nimport { CanonicalSupportCodeIds } from '../../support_code_library_builder/types'\nimport { FormatOptions } from '../../formatter'\n\n// Messages from Coordinator to Worker\n\nexport type CoordinatorToWorkerCommand =\n | InitializeCommand\n | RunCommand\n | FinalizeCommand\n\nexport interface InitializeCommand {\n type: 'INITIALIZE'\n testRunStartedId: string\n supportCodeCoordinates: ISupportCodeCoordinates\n supportCodeIds: CanonicalSupportCodeIds\n options: RuntimeOptions\n snippetOptions: Pick<FormatOptions, 'snippetInterface' | 'snippetSyntax'>\n}\n\nexport interface RunCommand {\n type: 'RUN'\n assembledTestCase: AssembledTestCase\n failing: boolean\n}\n\nexport interface FinalizeCommand {\n type: 'FINALIZE'\n}\n\n// Messages from Worker to Coordinator\n\nexport type WorkerToCoordinatorEvent =\n | ReadyEvent\n | EnvelopeEvent\n | FinishedEvent\n\nexport interface ReadyEvent {\n type: 'READY'\n}\n\nexport interface EnvelopeEvent {\n type: 'ENVELOPE'\n envelope: Envelope\n}\n\nexport interface FinishedEvent {\n type: 'FINISHED'\n success: boolean\n}\n"]}
@@ -17,7 +17,7 @@ export declare class ChildProcessWorker {
17
17
  id: string;
18
18
  sendMessage: IMessageSender;
19
19
  });
20
- initialize({ supportCodeCoordinates, supportCodeIds, options, }: InitializeCommand): Promise<void>;
20
+ initialize({ testRunStartedId, supportCodeCoordinates, supportCodeIds, options, snippetOptions, }: InitializeCommand): Promise<void>;
21
21
  finalize(): Promise<void>;
22
22
  receiveMessage(command: CoordinatorToWorkerCommand): Promise<void>;
23
23
  runTestCase(command: RunCommand): Promise<void>;
@@ -11,6 +11,7 @@ const messages_1 = require("@cucumber/messages");
11
11
  const support_code_library_builder_1 = __importDefault(require("../../support_code_library_builder"));
12
12
  const try_require_1 = __importDefault(require("../../try_require"));
13
13
  const worker_1 = require("../worker");
14
+ const builder_1 = __importDefault(require("../../formatter/builder"));
14
15
  const { uuid } = messages_1.IdGenerator;
15
16
  class ChildProcessWorker {
16
17
  cwd;
@@ -31,7 +32,7 @@ class ChildProcessWorker {
31
32
  this.eventBroadcaster = new node_events_1.EventEmitter();
32
33
  this.eventBroadcaster.on('envelope', (envelope) => this.sendMessage({ type: 'ENVELOPE', envelope }));
33
34
  }
34
- async initialize({ supportCodeCoordinates, supportCodeIds, options, }) {
35
+ async initialize({ testRunStartedId, supportCodeCoordinates, supportCodeIds, options, snippetOptions, }) {
35
36
  support_code_library_builder_1.default.reset(this.cwd, this.newId, supportCodeCoordinates);
36
37
  supportCodeCoordinates.requireModules.map((module) => (0, try_require_1.default)(module));
37
38
  supportCodeCoordinates.requirePaths.map((module) => (0, try_require_1.default)(module));
@@ -43,7 +44,13 @@ class ChildProcessWorker {
43
44
  }
44
45
  this.supportCodeLibrary = support_code_library_builder_1.default.finalize(supportCodeIds);
45
46
  this.options = options;
46
- this.worker = new worker_1.Worker(this.id, this.eventBroadcaster, this.newId, this.options, this.supportCodeLibrary);
47
+ const snippetBuilder = await builder_1.default.getStepDefinitionSnippetBuilder({
48
+ cwd: this.cwd,
49
+ snippetInterface: snippetOptions.snippetInterface,
50
+ snippetSyntax: snippetOptions.snippetSyntax,
51
+ supportCodeLibrary: this.supportCodeLibrary,
52
+ });
53
+ this.worker = new worker_1.Worker(testRunStartedId, this.id, this.eventBroadcaster, this.newId, this.options, this.supportCodeLibrary, snippetBuilder);
47
54
  await this.worker.runBeforeAllHooks();
48
55
  this.sendMessage({ type: 'READY' });
49
56
  }
@@ -1 +1 @@
1
- {"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/runtime/parallel/worker.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA0C;AAC1C,uCAAwC;AACxC,6CAAsC;AACtC,iDAA0D;AAC1D,sGAA0E;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,WAAW,CAAC,OAAmB;QACnC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAC3C,OAAO,CAAC,iBAAiB,EACzB,OAAO,CAAC,OAAO,CAChB,CAAA;QACD,IAAI,CAAC,WAAW,CAAC;YACf,IAAI,EAAE,UAAU;YAChB,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;CACF;AA/FD,gDA+FC","sourcesContent":["import { EventEmitter } from 'node:events'\nimport { pathToFileURL } from 'node:url'\nimport { register } from 'node:module'\nimport { Envelope, IdGenerator } from '@cucumber/messages'\nimport supportCodeLibraryBuilder from '../../support_code_library_builder'\nimport { SupportCodeLibrary } from '../../support_code_library_builder/types'\nimport tryRequire from '../../try_require'\nimport { Worker } from '../worker'\nimport { RuntimeOptions } from '../index'\nimport {\n WorkerToCoordinatorEvent,\n CoordinatorToWorkerCommand,\n InitializeCommand,\n RunCommand,\n} from './types'\n\nconst { uuid } = IdGenerator\n\ntype IExitFunction = (exitCode: number, error?: Error, message?: string) => void\ntype IMessageSender = (command: WorkerToCoordinatorEvent) => void\n\nexport class ChildProcessWorker {\n private readonly cwd: string\n private readonly exit: IExitFunction\n\n private readonly id: string\n private readonly eventBroadcaster: EventEmitter\n private readonly newId: IdGenerator.NewId\n private readonly sendMessage: IMessageSender\n private options: RuntimeOptions\n private supportCodeLibrary: SupportCodeLibrary\n private worker: Worker\n\n constructor({\n cwd,\n exit,\n id,\n sendMessage,\n }: {\n cwd: string\n exit: IExitFunction\n id: string\n sendMessage: IMessageSender\n }) {\n this.id = id\n this.newId = uuid()\n this.cwd = cwd\n this.exit = exit\n this.sendMessage = sendMessage\n this.eventBroadcaster = new EventEmitter()\n this.eventBroadcaster.on('envelope', (envelope: Envelope) =>\n this.sendMessage({ type: 'ENVELOPE', envelope })\n )\n }\n\n async initialize({\n supportCodeCoordinates,\n supportCodeIds,\n options,\n }: InitializeCommand): Promise<void> {\n supportCodeLibraryBuilder.reset(\n this.cwd,\n this.newId,\n supportCodeCoordinates\n )\n supportCodeCoordinates.requireModules.map((module) => tryRequire(module))\n supportCodeCoordinates.requirePaths.map((module) => tryRequire(module))\n for (const specifier of supportCodeCoordinates.loaders) {\n register(specifier, pathToFileURL('./'))\n }\n for (const path of supportCodeCoordinates.importPaths) {\n await import(pathToFileURL(path).toString())\n }\n this.supportCodeLibrary = supportCodeLibraryBuilder.finalize(supportCodeIds)\n\n this.options = options\n this.worker = new Worker(\n this.id,\n this.eventBroadcaster,\n this.newId,\n this.options,\n this.supportCodeLibrary\n )\n await this.worker.runBeforeAllHooks()\n this.sendMessage({ type: 'READY' })\n }\n\n async finalize(): Promise<void> {\n await this.worker.runAfterAllHooks()\n this.exit(0)\n }\n\n async receiveMessage(command: CoordinatorToWorkerCommand): Promise<void> {\n switch (command.type) {\n case 'INITIALIZE':\n await this.initialize(command)\n break\n case 'RUN':\n await this.runTestCase(command)\n break\n case 'FINALIZE':\n await this.finalize()\n break\n }\n }\n\n async runTestCase(command: RunCommand): Promise<void> {\n const success = await this.worker.runTestCase(\n command.assembledTestCase,\n command.failing\n )\n this.sendMessage({\n type: 'FINISHED',\n success,\n })\n }\n}\n"]}
1
+ {"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/runtime/parallel/worker.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA0C;AAC1C,uCAAwC;AACxC,6CAAsC;AACtC,iDAA0D;AAC1D,sGAA0E;AAE1E,oEAA0C;AAC1C,sCAAkC;AAElC,sEAAsD;AAQtD,MAAM,EAAE,IAAI,EAAE,GAAG,sBAAW,CAAA;AAK5B,MAAa,kBAAkB;IACZ,GAAG,CAAQ;IACX,IAAI,CAAe;IAEnB,EAAE,CAAQ;IACV,gBAAgB,CAAc;IAC9B,KAAK,CAAmB;IACxB,WAAW,CAAgB;IACpC,OAAO,CAAgB;IACvB,kBAAkB,CAAoB;IACtC,MAAM,CAAQ;IAEtB,YAAY,EACV,GAAG,EACH,IAAI,EACJ,EAAE,EACF,WAAW,GAMZ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CAAC,MAAM,CAAC,WAAW,CAC3C,OAAO,CAAC,iBAAiB,EACzB,OAAO,CAAC,OAAO,CAChB,CAAA;QACD,IAAI,CAAC,WAAW,CAAC;YACf,IAAI,EAAE,UAAU;YAChB,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;CACF;AA5GD,gDA4GC","sourcesContent":["import { EventEmitter } from 'node:events'\nimport { pathToFileURL } from 'node:url'\nimport { register } from 'node:module'\nimport { Envelope, IdGenerator } from '@cucumber/messages'\nimport supportCodeLibraryBuilder from '../../support_code_library_builder'\nimport { SupportCodeLibrary } from '../../support_code_library_builder/types'\nimport tryRequire from '../../try_require'\nimport { Worker } from '../worker'\nimport { RuntimeOptions } from '../index'\nimport FormatterBuilder from '../../formatter/builder'\nimport {\n WorkerToCoordinatorEvent,\n CoordinatorToWorkerCommand,\n InitializeCommand,\n RunCommand,\n} from './types'\n\nconst { uuid } = IdGenerator\n\ntype IExitFunction = (exitCode: number, error?: Error, message?: string) => void\ntype IMessageSender = (command: WorkerToCoordinatorEvent) => void\n\nexport class ChildProcessWorker {\n private readonly cwd: string\n private readonly exit: IExitFunction\n\n private readonly id: string\n private readonly eventBroadcaster: EventEmitter\n private readonly newId: IdGenerator.NewId\n private readonly sendMessage: IMessageSender\n private options: RuntimeOptions\n private supportCodeLibrary: SupportCodeLibrary\n private worker: Worker\n\n constructor({\n cwd,\n exit,\n id,\n sendMessage,\n }: {\n cwd: string\n exit: IExitFunction\n id: string\n sendMessage: IMessageSender\n }) {\n this.id = id\n this.newId = uuid()\n this.cwd = cwd\n this.exit = exit\n this.sendMessage = sendMessage\n this.eventBroadcaster = new EventEmitter()\n this.eventBroadcaster.on('envelope', (envelope: Envelope) =>\n this.sendMessage({ type: 'ENVELOPE', envelope })\n )\n }\n\n async initialize({\n testRunStartedId,\n supportCodeCoordinates,\n supportCodeIds,\n options,\n snippetOptions,\n }: InitializeCommand): Promise<void> {\n supportCodeLibraryBuilder.reset(\n this.cwd,\n this.newId,\n supportCodeCoordinates\n )\n supportCodeCoordinates.requireModules.map((module) => tryRequire(module))\n supportCodeCoordinates.requirePaths.map((module) => tryRequire(module))\n for (const specifier of supportCodeCoordinates.loaders) {\n register(specifier, pathToFileURL('./'))\n }\n for (const path of supportCodeCoordinates.importPaths) {\n await import(pathToFileURL(path).toString())\n }\n this.supportCodeLibrary = supportCodeLibraryBuilder.finalize(supportCodeIds)\n\n this.options = options\n\n const snippetBuilder =\n await FormatterBuilder.getStepDefinitionSnippetBuilder({\n cwd: this.cwd,\n snippetInterface: snippetOptions.snippetInterface,\n snippetSyntax: snippetOptions.snippetSyntax,\n supportCodeLibrary: this.supportCodeLibrary,\n })\n\n this.worker = new Worker(\n testRunStartedId,\n this.id,\n this.eventBroadcaster,\n this.newId,\n this.options,\n this.supportCodeLibrary,\n snippetBuilder\n )\n await this.worker.runBeforeAllHooks()\n this.sendMessage({ type: 'READY' })\n }\n\n async finalize(): Promise<void> {\n await this.worker.runAfterAllHooks()\n this.exit(0)\n }\n\n async receiveMessage(command: CoordinatorToWorkerCommand): Promise<void> {\n switch (command.type) {\n case 'INITIALIZE':\n await this.initialize(command)\n break\n case 'RUN':\n await this.runTestCase(command)\n break\n case 'FINALIZE':\n await this.finalize()\n break\n }\n }\n\n async runTestCase(command: RunCommand): Promise<void> {\n const success = await this.worker.runTestCase(\n command.assembledTestCase,\n command.failing\n )\n this.sendMessage({\n type: 'FINISHED',\n success,\n })\n }\n}\n"]}
@@ -4,9 +4,10 @@ import { RuntimeAdapter } from '../types';
4
4
  import { AssembledTestCase } from '../../assemble';
5
5
  import { RuntimeOptions } from '../index';
6
6
  import { SupportCodeLibrary } from '../../support_code_library_builder/types';
7
+ import StepDefinitionSnippetBuilder from '../../formatter/step_definition_snippet_builder';
7
8
  export declare class InProcessAdapter implements RuntimeAdapter {
8
9
  private readonly worker;
9
10
  private failing;
10
- constructor(eventBroadcaster: EventEmitter, newId: IdGenerator.NewId, options: RuntimeOptions, supportCodeLibrary: SupportCodeLibrary);
11
+ constructor(testRunStartedId: string, eventBroadcaster: EventEmitter, newId: IdGenerator.NewId, options: RuntimeOptions, supportCodeLibrary: SupportCodeLibrary, snippetBuilder: StepDefinitionSnippetBuilder);
11
12
  run(assembledTestCases: ReadonlyArray<AssembledTestCase>): Promise<boolean>;
12
13
  }
@@ -5,8 +5,8 @@ const worker_1 = require("../worker");
5
5
  class InProcessAdapter {
6
6
  worker;
7
7
  failing = false;
8
- constructor(eventBroadcaster, newId, options, supportCodeLibrary) {
9
- this.worker = new worker_1.Worker(undefined, eventBroadcaster, newId, options, supportCodeLibrary);
8
+ constructor(testRunStartedId, eventBroadcaster, newId, options, supportCodeLibrary, snippetBuilder) {
9
+ this.worker = new worker_1.Worker(testRunStartedId, undefined, eventBroadcaster, newId, options, supportCodeLibrary, snippetBuilder);
10
10
  }
11
11
  async run(assembledTestCases) {
12
12
  await this.worker.runBeforeAllHooks();
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../src/runtime/serial/adapter.ts"],"names":[],"mappings":";;;AAIA,sCAAkC;AAIlC,MAAa,gBAAgB;IACV,MAAM,CAAQ;IACvB,OAAO,GAAY,KAAK,CAAA;IAEhC,YACE,gBAA8B,EAC9B,KAAwB,EACxB,OAAuB,EACvB,kBAAsC;QAEtC,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CACtB,SAAS,EACT,gBAAgB,EAChB,KAAK,EACL,OAAO,EACP,kBAAkB,CACnB,CAAA;IACH,CAAC;IAED,KAAK,CAAC,GAAG,CACP,kBAAoD;QAEpD,MAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAA;QACrC,KAAK,MAAM,IAAI,IAAI,kBAAkB,EAAE,CAAC;YACtC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;YACjE,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;YACrB,CAAC;QACH,CAAC;QACD,MAAM,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAA;QACpC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAA;IACtB,CAAC;CACF;AAhCD,4CAgCC","sourcesContent":["import { EventEmitter } from 'node:events'\nimport { IdGenerator } from '@cucumber/messages'\nimport { RuntimeAdapter } from '../types'\nimport { AssembledTestCase } from '../../assemble'\nimport { Worker } from '../worker'\nimport { RuntimeOptions } from '../index'\nimport { SupportCodeLibrary } from '../../support_code_library_builder/types'\n\nexport class InProcessAdapter implements RuntimeAdapter {\n private readonly worker: Worker\n private failing: boolean = false\n\n constructor(\n eventBroadcaster: EventEmitter,\n newId: IdGenerator.NewId,\n options: RuntimeOptions,\n supportCodeLibrary: SupportCodeLibrary\n ) {\n this.worker = new Worker(\n undefined,\n eventBroadcaster,\n newId,\n options,\n supportCodeLibrary\n )\n }\n\n async run(\n assembledTestCases: ReadonlyArray<AssembledTestCase>\n ): Promise<boolean> {\n await this.worker.runBeforeAllHooks()\n for (const item of assembledTestCases) {\n const success = await this.worker.runTestCase(item, this.failing)\n if (!success) {\n this.failing = true\n }\n }\n await this.worker.runAfterAllHooks()\n return !this.failing\n }\n}\n"]}
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../src/runtime/serial/adapter.ts"],"names":[],"mappings":";;;AAIA,sCAAkC;AAKlC,MAAa,gBAAgB;IACV,MAAM,CAAQ;IACvB,OAAO,GAAY,KAAK,CAAA;IAEhC,YACE,gBAAwB,EACxB,gBAA8B,EAC9B,KAAwB,EACxB,OAAuB,EACvB,kBAAsC,EACtC,cAA4C;QAE5C,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CACtB,gBAAgB,EAChB,SAAS,EACT,gBAAgB,EAChB,KAAK,EACL,OAAO,EACP,kBAAkB,EAClB,cAAc,CACf,CAAA;IACH,CAAC;IAED,KAAK,CAAC,GAAG,CACP,kBAAoD;QAEpD,MAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAA;QACrC,KAAK,MAAM,IAAI,IAAI,kBAAkB,EAAE,CAAC;YACtC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;YACjE,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;YACrB,CAAC;QACH,CAAC;QACD,MAAM,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAA;QACpC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAA;IACtB,CAAC;CACF;AApCD,4CAoCC","sourcesContent":["import { EventEmitter } from 'node:events'\nimport { IdGenerator } from '@cucumber/messages'\nimport { RuntimeAdapter } from '../types'\nimport { AssembledTestCase } from '../../assemble'\nimport { Worker } from '../worker'\nimport { RuntimeOptions } from '../index'\nimport { SupportCodeLibrary } from '../../support_code_library_builder/types'\nimport StepDefinitionSnippetBuilder from '../../formatter/step_definition_snippet_builder'\n\nexport class InProcessAdapter implements RuntimeAdapter {\n private readonly worker: Worker\n private failing: boolean = false\n\n constructor(\n testRunStartedId: string,\n eventBroadcaster: EventEmitter,\n newId: IdGenerator.NewId,\n options: RuntimeOptions,\n supportCodeLibrary: SupportCodeLibrary,\n snippetBuilder: StepDefinitionSnippetBuilder\n ) {\n this.worker = new Worker(\n testRunStartedId,\n undefined,\n eventBroadcaster,\n newId,\n options,\n supportCodeLibrary,\n snippetBuilder\n )\n }\n\n async run(\n assembledTestCases: ReadonlyArray<AssembledTestCase>\n ): Promise<boolean> {\n await this.worker.runBeforeAllHooks()\n for (const item of assembledTestCases) {\n const success = await this.worker.runTestCase(item, this.failing)\n if (!success) {\n this.failing = true\n }\n }\n await this.worker.runAfterAllHooks()\n return !this.failing\n }\n}\n"]}
@@ -6,6 +6,7 @@ import { ITestCaseHookParameter, SupportCodeLibrary } from '../support_code_libr
6
6
  import TestCaseHookDefinition from '../models/test_case_hook_definition';
7
7
  import TestStepHookDefinition from '../models/test_step_hook_definition';
8
8
  import { IDefinition } from '../models/definition';
9
+ import StepDefinitionSnippetBuilder from '../formatter/step_definition_snippet_builder';
9
10
  import { RunStepResult } from './step_runner';
10
11
  export interface INewTestCaseRunnerOptions {
11
12
  workerId?: string;
@@ -19,6 +20,7 @@ export interface INewTestCaseRunnerOptions {
19
20
  filterStackTraces: boolean;
20
21
  supportCodeLibrary: SupportCodeLibrary;
21
22
  worldParameters: JsonObject;
23
+ snippetBuilder: StepDefinitionSnippetBuilder;
22
24
  }
23
25
  export default class TestCaseRunner {
24
26
  private readonly workerId;
@@ -34,10 +36,11 @@ export default class TestCaseRunner {
34
36
  private readonly skip;
35
37
  private readonly filterStackTraces;
36
38
  private readonly supportCodeLibrary;
39
+ private readonly snippetBuilder;
37
40
  private testStepResults;
38
41
  private world;
39
42
  private readonly worldParameters;
40
- constructor({ workerId, eventBroadcaster, gherkinDocument, newId, pickle, testCase, retries, skip, filterStackTraces, supportCodeLibrary, worldParameters, }: INewTestCaseRunnerOptions);
43
+ constructor({ workerId, eventBroadcaster, gherkinDocument, newId, pickle, testCase, retries, skip, filterStackTraces, supportCodeLibrary, worldParameters, snippetBuilder, }: INewTestCaseRunnerOptions);
41
44
  resetTestProgressData(): void;
42
45
  getBeforeStepHookDefinitions(): TestStepHookDefinition[];
43
46
  getAfterStepHookDefinitions(): TestStepHookDefinition[];
@@ -43,6 +43,7 @@ const stopwatch_1 = require("./stopwatch");
43
43
  const step_runner_1 = __importDefault(require("./step_runner"));
44
44
  const attachment_manager_1 = __importDefault(require("./attachment_manager"));
45
45
  const helpers_1 = require("./helpers");
46
+ const make_suggestion_1 = require("./make_suggestion");
46
47
  class TestCaseRunner {
47
48
  workerId;
48
49
  attachmentManager;
@@ -57,10 +58,11 @@ class TestCaseRunner {
57
58
  skip;
58
59
  filterStackTraces;
59
60
  supportCodeLibrary;
61
+ snippetBuilder;
60
62
  testStepResults;
61
63
  world;
62
64
  worldParameters;
63
- constructor({ workerId, eventBroadcaster, gherkinDocument, newId, pickle, testCase, retries = 0, skip, filterStackTraces, supportCodeLibrary, worldParameters, }) {
65
+ constructor({ workerId, eventBroadcaster, gherkinDocument, newId, pickle, testCase, retries = 0, skip, filterStackTraces, supportCodeLibrary, worldParameters, snippetBuilder, }) {
64
66
  this.workerId = workerId;
65
67
  this.attachmentManager = new attachment_manager_1.default(({ data, media, fileName }) => {
66
68
  if ((0, value_checker_1.doesNotHaveValue)(this.currentTestStepId)) {
@@ -74,6 +76,7 @@ class TestCaseRunner {
74
76
  fileName,
75
77
  testCaseStartedId: this.currentTestCaseStartedId,
76
78
  testStepId: this.currentTestStepId,
79
+ timestamp: (0, stopwatch_1.timestamp)(),
77
80
  },
78
81
  };
79
82
  this.eventBroadcaster.emit('envelope', attachment);
@@ -88,6 +91,7 @@ class TestCaseRunner {
88
91
  this.filterStackTraces = filterStackTraces;
89
92
  this.supportCodeLibrary = supportCodeLibrary;
90
93
  this.worldParameters = worldParameters;
94
+ this.snippetBuilder = snippetBuilder;
91
95
  this.resetTestProgressData();
92
96
  }
93
97
  resetTestProgressData() {
@@ -256,6 +260,13 @@ class TestCaseRunner {
256
260
  return findStepDefinition(stepDefinitionId, this.supportCodeLibrary);
257
261
  });
258
262
  if (stepDefinitions.length === 0) {
263
+ this.eventBroadcaster.emit('envelope', {
264
+ suggestion: (0, make_suggestion_1.makeSuggestion)({
265
+ newId: this.newId,
266
+ snippetBuilder: this.snippetBuilder,
267
+ pickleStep,
268
+ }),
269
+ });
259
270
  return {
260
271
  result: {
261
272
  status: messages.TestStepResultStatus.UNDEFINED,
@@ -1 +1 @@
1
- {"version":3,"file":"test_case_runner.js","sourceRoot":"","sources":["../../src/runtime/test_case_runner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,6DAA8C;AAC9C,iDAAwE;AAUxE,oDAAkE;AAGlE,2CAAu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C3D,IAAI,aAAa,GAAG,QAAQ,CAAC,cAAc,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAA;QACrE,KAAK,MAAM,MAAM,IAAI,WAAW,EAAE,CAAC;YACjC,aAAa,GAAG,QAAQ,CAAC,cAAc,CAAC,YAAY,CAClD,aAAa,EACb,MAAM,CAAC,QAAQ,CAChB,CAAA;QACH,CAAC;QACD,eAAe,CAAC,QAAQ,GAAG,aAAa,CAAA;QACxC,OAAO;YACL,MAAM,EAAE,eAAe;YACvB,KAAK;SACN,CAAA;IACH,CAAC;CACF;AA7VD,iCA6VC;AAED,SAAS,kBAAkB,CACzB,EAAU,EACV,kBAAsC;IAEtC,OAAO;QACL,GAAG,kBAAkB,CAAC,6BAA6B;QACnD,GAAG,kBAAkB,CAAC,4BAA4B;KACnD,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;AAC9C,CAAC;AAED,SAAS,kBAAkB,CACzB,EAAU,EACV,kBAAsC;IAEtC,OAAO,kBAAkB,CAAC,eAAe,CAAC,IAAI,CAC5C,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CACrC,CAAA;AACH,CAAC","sourcesContent":["import { EventEmitter } from 'node:events'\nimport * as messages from '@cucumber/messages'\nimport { getWorstTestStepResult, IdGenerator } from '@cucumber/messages'\nimport { JsonObject } from 'type-fest'\nimport {\n ITestCaseHookParameter,\n ITestStepHookParameter,\n SupportCodeLibrary,\n} from '../support_code_library_builder/types'\nimport TestCaseHookDefinition from '../models/test_case_hook_definition'\nimport TestStepHookDefinition from '../models/test_step_hook_definition'\nimport { IDefinition } from '../models/definition'\nimport { doesHaveValue, doesNotHaveValue } from '../value_checker'\nimport StepDefinition from '../models/step_definition'\nimport { IWorldOptions } from '../support_code_library_builder/world'\nimport { timestamp } from './stopwatch'\nimport StepRunner, { RunStepResult } from './step_runner'\nimport AttachmentManager from './attachment_manager'\nimport { getAmbiguousStepException } from './helpers'\n\nexport interface INewTestCaseRunnerOptions {\n workerId?: string\n eventBroadcaster: EventEmitter\n gherkinDocument: messages.GherkinDocument\n newId: IdGenerator.NewId\n pickle: messages.Pickle\n testCase: messages.TestCase\n retries: number\n skip: boolean\n filterStackTraces: boolean\n supportCodeLibrary: SupportCodeLibrary\n worldParameters: JsonObject\n}\n\nexport default class TestCaseRunner {\n private readonly workerId: string | undefined\n private readonly attachmentManager: AttachmentManager\n private currentTestCaseStartedId: string\n private currentTestStepId: string\n private readonly eventBroadcaster: EventEmitter\n private readonly gherkinDocument: messages.GherkinDocument\n private readonly newId: IdGenerator.NewId\n private readonly pickle: messages.Pickle\n private readonly testCase: messages.TestCase\n private readonly maxAttempts: number\n private readonly skip: boolean\n private readonly filterStackTraces: boolean\n private readonly supportCodeLibrary: SupportCodeLibrary\n private testStepResults: messages.TestStepResult[]\n private world: any\n private readonly worldParameters: JsonObject\n\n constructor({\n workerId,\n eventBroadcaster,\n gherkinDocument,\n newId,\n pickle,\n testCase,\n retries = 0,\n skip,\n filterStackTraces,\n supportCodeLibrary,\n worldParameters,\n }: INewTestCaseRunnerOptions) {\n this.workerId = workerId\n this.attachmentManager = new AttachmentManager(\n ({ data, media, fileName }) => {\n if (doesNotHaveValue(this.currentTestStepId)) {\n throw new Error(\n 'Cannot attach when a step/hook is not running. Ensure your step/hook waits for the attach to finish.'\n )\n }\n const attachment: messages.Envelope = {\n attachment: {\n body: data,\n contentEncoding: media.encoding,\n mediaType: media.contentType,\n fileName,\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId: this.currentTestStepId,\n },\n }\n this.eventBroadcaster.emit('envelope', attachment)\n }\n )\n this.eventBroadcaster = eventBroadcaster\n this.gherkinDocument = gherkinDocument\n this.maxAttempts = 1 + (skip ? 0 : retries)\n this.newId = newId\n this.pickle = pickle\n this.testCase = testCase\n this.skip = skip\n this.filterStackTraces = filterStackTraces\n this.supportCodeLibrary = supportCodeLibrary\n this.worldParameters = worldParameters\n this.resetTestProgressData()\n }\n\n resetTestProgressData(): void {\n this.world = new this.supportCodeLibrary.World({\n attach: this.attachmentManager.create.bind(this.attachmentManager),\n log: this.attachmentManager.log.bind(this.attachmentManager),\n link: this.attachmentManager.link.bind(this.attachmentManager),\n parameters: structuredClone(this.worldParameters),\n } satisfies IWorldOptions)\n this.testStepResults = []\n }\n\n getBeforeStepHookDefinitions(): TestStepHookDefinition[] {\n return this.supportCodeLibrary.beforeTestStepHookDefinitions.filter(\n (hookDefinition) => hookDefinition.appliesToTestCase(this.pickle)\n )\n }\n\n getAfterStepHookDefinitions(): TestStepHookDefinition[] {\n return this.supportCodeLibrary.afterTestStepHookDefinitions\n .slice(0)\n .reverse()\n .filter((hookDefinition) => hookDefinition.appliesToTestCase(this.pickle))\n }\n\n getWorstStepResult(): messages.TestStepResult {\n if (this.testStepResults.length === 0) {\n return {\n status: this.skip\n ? messages.TestStepResultStatus.SKIPPED\n : messages.TestStepResultStatus.PASSED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n }\n }\n return getWorstTestStepResult(this.testStepResults)\n }\n\n async invokeStep(\n step: messages.PickleStep,\n stepDefinition: IDefinition,\n hookParameter?: ITestCaseHookParameter\n ): Promise<RunStepResult> {\n return await StepRunner.run({\n defaultTimeout: this.supportCodeLibrary.defaultTimeout,\n filterStackTraces: this.filterStackTraces,\n hookParameter,\n step,\n stepDefinition,\n world: this.world,\n })\n }\n\n isSkippingSteps(): boolean {\n return (\n this.getWorstStepResult().status !== messages.TestStepResultStatus.PASSED\n )\n }\n\n shouldSkipHook(isBeforeHook: boolean): boolean {\n return this.skip || (this.isSkippingSteps() && isBeforeHook)\n }\n\n async aroundTestStep(\n testStepId: string,\n runStepFn: () => Promise<messages.TestStepResult>\n ): Promise<void> {\n const testStepStarted: messages.Envelope = {\n testStepStarted: {\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId,\n timestamp: timestamp(),\n },\n }\n this.eventBroadcaster.emit('envelope', testStepStarted)\n this.currentTestStepId = testStepId\n const testStepResult = await runStepFn()\n this.currentTestStepId = null\n this.testStepResults.push(testStepResult)\n const testStepFinished: messages.Envelope = {\n testStepFinished: {\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId,\n testStepResult,\n timestamp: timestamp(),\n },\n }\n this.eventBroadcaster.emit('envelope', testStepFinished)\n }\n\n async run(): Promise<messages.TestStepResultStatus> {\n for (let attempt = 0; attempt < this.maxAttempts; attempt++) {\n const moreAttemptsRemaining = attempt + 1 < this.maxAttempts\n\n const willBeRetried = await this.runAttempt(\n attempt,\n moreAttemptsRemaining\n )\n\n if (!willBeRetried) {\n break\n }\n this.resetTestProgressData()\n }\n return this.getWorstStepResult().status\n }\n\n async runAttempt(\n attempt: number,\n moreAttemptsRemaining: boolean\n ): Promise<boolean> {\n this.currentTestCaseStartedId = this.newId()\n const testCaseStarted: messages.Envelope = {\n testCaseStarted: {\n attempt,\n testCaseId: this.testCase.id,\n id: this.currentTestCaseStartedId,\n timestamp: timestamp(),\n },\n }\n if (this.workerId) {\n testCaseStarted.testCaseStarted.workerId = this.workerId\n }\n this.eventBroadcaster.emit('envelope', testCaseStarted)\n // used to determine whether a hook is a Before or After\n let didWeRunStepsYet = false\n let error = false\n for (const testStep of this.testCase.testSteps) {\n await this.aroundTestStep(testStep.id, async () => {\n if (doesHaveValue(testStep.hookId)) {\n const hookParameter: ITestCaseHookParameter = {\n gherkinDocument: this.gherkinDocument,\n pickle: this.pickle,\n testCaseStartedId: this.currentTestCaseStartedId,\n }\n if (didWeRunStepsYet) {\n hookParameter.result = this.getWorstStepResult()\n hookParameter.error = error\n hookParameter.willBeRetried =\n this.getWorstStepResult().status ===\n messages.TestStepResultStatus.FAILED && moreAttemptsRemaining\n }\n return await this.runHook(\n findHookDefinition(testStep.hookId, this.supportCodeLibrary),\n hookParameter,\n !didWeRunStepsYet\n )\n } else {\n const pickleStep = this.pickle.steps.find(\n (pickleStep) => pickleStep.id === testStep.pickleStepId\n )\n const testStepResult = await this.runStep(pickleStep, testStep)\n didWeRunStepsYet = true\n error = testStepResult.error\n return testStepResult.result\n }\n })\n }\n\n const willBeRetried =\n this.getWorstStepResult().status ===\n messages.TestStepResultStatus.FAILED && moreAttemptsRemaining\n const testCaseFinished: messages.Envelope = {\n testCaseFinished: {\n testCaseStartedId: this.currentTestCaseStartedId,\n timestamp: timestamp(),\n willBeRetried,\n },\n }\n this.eventBroadcaster.emit('envelope', testCaseFinished)\n\n return willBeRetried\n }\n\n async runHook(\n hookDefinition: TestCaseHookDefinition,\n hookParameter: ITestCaseHookParameter,\n isBeforeHook: boolean\n ): Promise<messages.TestStepResult> {\n if (this.shouldSkipHook(isBeforeHook)) {\n return {\n status: messages.TestStepResultStatus.SKIPPED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n }\n }\n const { result } = await this.invokeStep(\n null,\n hookDefinition,\n hookParameter\n )\n return result\n }\n\n async runStepHooks(\n stepHooks: TestStepHookDefinition[],\n pickleStep: messages.PickleStep,\n stepResult?: RunStepResult\n ): Promise<messages.TestStepResult[]> {\n const stepHooksResult = []\n const hookParameter: ITestStepHookParameter = {\n gherkinDocument: this.gherkinDocument,\n pickle: this.pickle,\n pickleStep,\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId: this.currentTestStepId,\n result: stepResult?.result,\n error: stepResult?.error,\n }\n for (const stepHookDefinition of stepHooks) {\n const { result } = await this.invokeStep(\n null,\n stepHookDefinition,\n hookParameter\n )\n stepHooksResult.push(result)\n }\n return stepHooksResult\n }\n\n async runStep(\n pickleStep: messages.PickleStep,\n testStep: messages.TestStep\n ): Promise<RunStepResult> {\n const stepDefinitions = testStep.stepDefinitionIds.map(\n (stepDefinitionId) => {\n return findStepDefinition(stepDefinitionId, this.supportCodeLibrary)\n }\n )\n if (stepDefinitions.length === 0) {\n return {\n result: {\n status: messages.TestStepResultStatus.UNDEFINED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n },\n }\n } else if (stepDefinitions.length > 1) {\n return {\n result: {\n message: getAmbiguousStepException(stepDefinitions),\n status: messages.TestStepResultStatus.AMBIGUOUS,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n },\n }\n } else if (this.isSkippingSteps()) {\n return {\n result: {\n status: messages.TestStepResultStatus.SKIPPED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n },\n }\n }\n\n let stepResult\n let error\n let stepResults = await this.runStepHooks(\n this.getBeforeStepHookDefinitions(),\n pickleStep\n )\n if (\n getWorstTestStepResult(stepResults).status !==\n messages.TestStepResultStatus.FAILED\n ) {\n stepResult = await this.invokeStep(pickleStep, stepDefinitions[0])\n stepResults.push(stepResult.result)\n error = stepResult.error\n }\n const afterStepHookResults = await this.runStepHooks(\n this.getAfterStepHookDefinitions(),\n pickleStep,\n stepResult\n )\n stepResults = stepResults.concat(afterStepHookResults)\n\n const finalStepResult = getWorstTestStepResult(stepResults)\n let finalDuration = messages.TimeConversion.millisecondsToDuration(0)\n for (const result of stepResults) {\n finalDuration = messages.TimeConversion.addDurations(\n finalDuration,\n result.duration\n )\n }\n finalStepResult.duration = finalDuration\n return {\n result: finalStepResult,\n error,\n }\n }\n}\n\nfunction findHookDefinition(\n id: string,\n supportCodeLibrary: SupportCodeLibrary\n): TestCaseHookDefinition {\n return [\n ...supportCodeLibrary.beforeTestCaseHookDefinitions,\n ...supportCodeLibrary.afterTestCaseHookDefinitions,\n ].find((definition) => definition.id === id)\n}\n\nfunction findStepDefinition(\n id: string,\n supportCodeLibrary: SupportCodeLibrary\n): StepDefinition {\n return supportCodeLibrary.stepDefinitions.find(\n (definition) => definition.id === id\n )\n}\n"]}
1
+ {"version":3,"file":"test_case_runner.js","sourceRoot":"","sources":["../../src/runtime/test_case_runner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,6DAA8C;AAC9C,iDAI2B;AAU3B,oDAAkE;AAIlE,2CAAuC;AACvC,gEAAyD;AACzD,8EAAoD;AACpD,uCAAqD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KAAK,GAAG,UAAU,CAAC,KAAK,CAAA;QAC1B,CAAC;QACD,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,YAAY,CAClD,IAAI,CAAC,2BAA2B,EAAE,EAClC,UAAU,EACV,UAAU,CACX,CAAA;QACD,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAA;QAEtD,MAAM,eAAe,GAAG,IAAA,iCAAsB,EAAC,WAAW,CAAC,CAAA;QAC3D,IAAI,aAAa,GAAG,QAAQ,CAAC,cAAc,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAA;QACrE,KAAK,MAAM,MAAM,IAAI,WAAW,EAAE,CAAC;YACjC,aAAa,GAAG,QAAQ,CAAC,cAAc,CAAC,YAAY,CAClD,aAAa,EACb,MAAM,CAAC,QAAQ,CAChB,CAAA;QACH,CAAC;QACD,eAAe,CAAC,QAAQ,GAAG,aAAa,CAAA;QACxC,OAAO;YACL,MAAM,EAAE,eAAe;YACvB,KAAK;SACN,CAAA;IACH,CAAC;CACF;AAxWD,iCAwWC;AAED,SAAS,kBAAkB,CACzB,EAAU,EACV,kBAAsC;IAEtC,OAAO;QACL,GAAG,kBAAkB,CAAC,6BAA6B;QACnD,GAAG,kBAAkB,CAAC,4BAA4B;KACnD,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;AAC9C,CAAC;AAED,SAAS,kBAAkB,CACzB,EAAU,EACV,kBAAsC;IAEtC,OAAO,kBAAkB,CAAC,eAAe,CAAC,IAAI,CAC5C,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CACrC,CAAA;AACH,CAAC","sourcesContent":["import { EventEmitter } from 'node:events'\nimport * as messages from '@cucumber/messages'\nimport {\n Envelope,\n getWorstTestStepResult,\n IdGenerator,\n} from '@cucumber/messages'\nimport { JsonObject } from 'type-fest'\nimport {\n ITestCaseHookParameter,\n ITestStepHookParameter,\n SupportCodeLibrary,\n} from '../support_code_library_builder/types'\nimport TestCaseHookDefinition from '../models/test_case_hook_definition'\nimport TestStepHookDefinition from '../models/test_step_hook_definition'\nimport { IDefinition } from '../models/definition'\nimport { doesHaveValue, doesNotHaveValue } from '../value_checker'\nimport StepDefinition from '../models/step_definition'\nimport { IWorldOptions } from '../support_code_library_builder/world'\nimport StepDefinitionSnippetBuilder from '../formatter/step_definition_snippet_builder'\nimport { timestamp } from './stopwatch'\nimport StepRunner, { RunStepResult } from './step_runner'\nimport AttachmentManager from './attachment_manager'\nimport { getAmbiguousStepException } from './helpers'\nimport { makeSuggestion } from './make_suggestion'\n\nexport interface INewTestCaseRunnerOptions {\n workerId?: string\n eventBroadcaster: EventEmitter\n gherkinDocument: messages.GherkinDocument\n newId: IdGenerator.NewId\n pickle: messages.Pickle\n testCase: messages.TestCase\n retries: number\n skip: boolean\n filterStackTraces: boolean\n supportCodeLibrary: SupportCodeLibrary\n worldParameters: JsonObject\n snippetBuilder: StepDefinitionSnippetBuilder\n}\n\nexport default class TestCaseRunner {\n private readonly workerId: string | undefined\n private readonly attachmentManager: AttachmentManager\n private currentTestCaseStartedId: string\n private currentTestStepId: string\n private readonly eventBroadcaster: EventEmitter\n private readonly gherkinDocument: messages.GherkinDocument\n private readonly newId: IdGenerator.NewId\n private readonly pickle: messages.Pickle\n private readonly testCase: messages.TestCase\n private readonly maxAttempts: number\n private readonly skip: boolean\n private readonly filterStackTraces: boolean\n private readonly supportCodeLibrary: SupportCodeLibrary\n private readonly snippetBuilder: StepDefinitionSnippetBuilder\n private testStepResults: messages.TestStepResult[]\n private world: any\n private readonly worldParameters: JsonObject\n\n constructor({\n workerId,\n eventBroadcaster,\n gherkinDocument,\n newId,\n pickle,\n testCase,\n retries = 0,\n skip,\n filterStackTraces,\n supportCodeLibrary,\n worldParameters,\n snippetBuilder,\n }: INewTestCaseRunnerOptions) {\n this.workerId = workerId\n this.attachmentManager = new AttachmentManager(\n ({ data, media, fileName }) => {\n if (doesNotHaveValue(this.currentTestStepId)) {\n throw new Error(\n 'Cannot attach when a step/hook is not running. Ensure your step/hook waits for the attach to finish.'\n )\n }\n const attachment: messages.Envelope = {\n attachment: {\n body: data,\n contentEncoding: media.encoding,\n mediaType: media.contentType,\n fileName,\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId: this.currentTestStepId,\n timestamp: timestamp(),\n },\n }\n this.eventBroadcaster.emit('envelope', attachment)\n }\n )\n this.eventBroadcaster = eventBroadcaster\n this.gherkinDocument = gherkinDocument\n this.maxAttempts = 1 + (skip ? 0 : retries)\n this.newId = newId\n this.pickle = pickle\n this.testCase = testCase\n this.skip = skip\n this.filterStackTraces = filterStackTraces\n this.supportCodeLibrary = supportCodeLibrary\n this.worldParameters = worldParameters\n this.snippetBuilder = snippetBuilder\n this.resetTestProgressData()\n }\n\n resetTestProgressData(): void {\n this.world = new this.supportCodeLibrary.World({\n attach: this.attachmentManager.create.bind(this.attachmentManager),\n log: this.attachmentManager.log.bind(this.attachmentManager),\n link: this.attachmentManager.link.bind(this.attachmentManager),\n parameters: structuredClone(this.worldParameters),\n } satisfies IWorldOptions)\n this.testStepResults = []\n }\n\n getBeforeStepHookDefinitions(): TestStepHookDefinition[] {\n return this.supportCodeLibrary.beforeTestStepHookDefinitions.filter(\n (hookDefinition) => hookDefinition.appliesToTestCase(this.pickle)\n )\n }\n\n getAfterStepHookDefinitions(): TestStepHookDefinition[] {\n return this.supportCodeLibrary.afterTestStepHookDefinitions\n .slice(0)\n .reverse()\n .filter((hookDefinition) => hookDefinition.appliesToTestCase(this.pickle))\n }\n\n getWorstStepResult(): messages.TestStepResult {\n if (this.testStepResults.length === 0) {\n return {\n status: this.skip\n ? messages.TestStepResultStatus.SKIPPED\n : messages.TestStepResultStatus.PASSED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n }\n }\n return getWorstTestStepResult(this.testStepResults)\n }\n\n async invokeStep(\n step: messages.PickleStep,\n stepDefinition: IDefinition,\n hookParameter?: ITestCaseHookParameter\n ): Promise<RunStepResult> {\n return await StepRunner.run({\n defaultTimeout: this.supportCodeLibrary.defaultTimeout,\n filterStackTraces: this.filterStackTraces,\n hookParameter,\n step,\n stepDefinition,\n world: this.world,\n })\n }\n\n isSkippingSteps(): boolean {\n return (\n this.getWorstStepResult().status !== messages.TestStepResultStatus.PASSED\n )\n }\n\n shouldSkipHook(isBeforeHook: boolean): boolean {\n return this.skip || (this.isSkippingSteps() && isBeforeHook)\n }\n\n async aroundTestStep(\n testStepId: string,\n runStepFn: () => Promise<messages.TestStepResult>\n ): Promise<void> {\n const testStepStarted: messages.Envelope = {\n testStepStarted: {\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId,\n timestamp: timestamp(),\n },\n }\n this.eventBroadcaster.emit('envelope', testStepStarted)\n this.currentTestStepId = testStepId\n const testStepResult = await runStepFn()\n this.currentTestStepId = null\n this.testStepResults.push(testStepResult)\n const testStepFinished: messages.Envelope = {\n testStepFinished: {\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId,\n testStepResult,\n timestamp: timestamp(),\n },\n }\n this.eventBroadcaster.emit('envelope', testStepFinished)\n }\n\n async run(): Promise<messages.TestStepResultStatus> {\n for (let attempt = 0; attempt < this.maxAttempts; attempt++) {\n const moreAttemptsRemaining = attempt + 1 < this.maxAttempts\n\n const willBeRetried = await this.runAttempt(\n attempt,\n moreAttemptsRemaining\n )\n\n if (!willBeRetried) {\n break\n }\n this.resetTestProgressData()\n }\n return this.getWorstStepResult().status\n }\n\n async runAttempt(\n attempt: number,\n moreAttemptsRemaining: boolean\n ): Promise<boolean> {\n this.currentTestCaseStartedId = this.newId()\n const testCaseStarted: messages.Envelope = {\n testCaseStarted: {\n attempt,\n testCaseId: this.testCase.id,\n id: this.currentTestCaseStartedId,\n timestamp: timestamp(),\n },\n }\n if (this.workerId) {\n testCaseStarted.testCaseStarted.workerId = this.workerId\n }\n this.eventBroadcaster.emit('envelope', testCaseStarted)\n // used to determine whether a hook is a Before or After\n let didWeRunStepsYet = false\n let error = false\n for (const testStep of this.testCase.testSteps) {\n await this.aroundTestStep(testStep.id, async () => {\n if (doesHaveValue(testStep.hookId)) {\n const hookParameter: ITestCaseHookParameter = {\n gherkinDocument: this.gherkinDocument,\n pickle: this.pickle,\n testCaseStartedId: this.currentTestCaseStartedId,\n }\n if (didWeRunStepsYet) {\n hookParameter.result = this.getWorstStepResult()\n hookParameter.error = error\n hookParameter.willBeRetried =\n this.getWorstStepResult().status ===\n messages.TestStepResultStatus.FAILED && moreAttemptsRemaining\n }\n return await this.runHook(\n findHookDefinition(testStep.hookId, this.supportCodeLibrary),\n hookParameter,\n !didWeRunStepsYet\n )\n } else {\n const pickleStep = this.pickle.steps.find(\n (pickleStep) => pickleStep.id === testStep.pickleStepId\n )\n const testStepResult = await this.runStep(pickleStep, testStep)\n didWeRunStepsYet = true\n error = testStepResult.error\n return testStepResult.result\n }\n })\n }\n\n const willBeRetried =\n this.getWorstStepResult().status ===\n messages.TestStepResultStatus.FAILED && moreAttemptsRemaining\n const testCaseFinished: messages.Envelope = {\n testCaseFinished: {\n testCaseStartedId: this.currentTestCaseStartedId,\n timestamp: timestamp(),\n willBeRetried,\n },\n }\n this.eventBroadcaster.emit('envelope', testCaseFinished)\n\n return willBeRetried\n }\n\n async runHook(\n hookDefinition: TestCaseHookDefinition,\n hookParameter: ITestCaseHookParameter,\n isBeforeHook: boolean\n ): Promise<messages.TestStepResult> {\n if (this.shouldSkipHook(isBeforeHook)) {\n return {\n status: messages.TestStepResultStatus.SKIPPED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n }\n }\n const { result } = await this.invokeStep(\n null,\n hookDefinition,\n hookParameter\n )\n return result\n }\n\n async runStepHooks(\n stepHooks: TestStepHookDefinition[],\n pickleStep: messages.PickleStep,\n stepResult?: RunStepResult\n ): Promise<messages.TestStepResult[]> {\n const stepHooksResult = []\n const hookParameter: ITestStepHookParameter = {\n gherkinDocument: this.gherkinDocument,\n pickle: this.pickle,\n pickleStep,\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId: this.currentTestStepId,\n result: stepResult?.result,\n error: stepResult?.error,\n }\n for (const stepHookDefinition of stepHooks) {\n const { result } = await this.invokeStep(\n null,\n stepHookDefinition,\n hookParameter\n )\n stepHooksResult.push(result)\n }\n return stepHooksResult\n }\n\n async runStep(\n pickleStep: messages.PickleStep,\n testStep: messages.TestStep\n ): Promise<RunStepResult> {\n const stepDefinitions = testStep.stepDefinitionIds.map(\n (stepDefinitionId) => {\n return findStepDefinition(stepDefinitionId, this.supportCodeLibrary)\n }\n )\n if (stepDefinitions.length === 0) {\n this.eventBroadcaster.emit('envelope', {\n suggestion: makeSuggestion({\n newId: this.newId,\n snippetBuilder: this.snippetBuilder,\n pickleStep,\n }),\n } satisfies Envelope)\n return {\n result: {\n status: messages.TestStepResultStatus.UNDEFINED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n },\n }\n } else if (stepDefinitions.length > 1) {\n return {\n result: {\n message: getAmbiguousStepException(stepDefinitions),\n status: messages.TestStepResultStatus.AMBIGUOUS,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n },\n }\n } else if (this.isSkippingSteps()) {\n return {\n result: {\n status: messages.TestStepResultStatus.SKIPPED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n },\n }\n }\n\n let stepResult\n let error\n let stepResults = await this.runStepHooks(\n this.getBeforeStepHookDefinitions(),\n pickleStep\n )\n if (\n getWorstTestStepResult(stepResults).status !==\n messages.TestStepResultStatus.FAILED\n ) {\n stepResult = await this.invokeStep(pickleStep, stepDefinitions[0])\n stepResults.push(stepResult.result)\n error = stepResult.error\n }\n const afterStepHookResults = await this.runStepHooks(\n this.getAfterStepHookDefinitions(),\n pickleStep,\n stepResult\n )\n stepResults = stepResults.concat(afterStepHookResults)\n\n const finalStepResult = getWorstTestStepResult(stepResults)\n let finalDuration = messages.TimeConversion.millisecondsToDuration(0)\n for (const result of stepResults) {\n finalDuration = messages.TimeConversion.addDurations(\n finalDuration,\n result.duration\n )\n }\n finalStepResult.duration = finalDuration\n return {\n result: finalStepResult,\n error,\n }\n }\n}\n\nfunction findHookDefinition(\n id: string,\n supportCodeLibrary: SupportCodeLibrary\n): TestCaseHookDefinition {\n return [\n ...supportCodeLibrary.beforeTestCaseHookDefinitions,\n ...supportCodeLibrary.afterTestCaseHookDefinitions,\n ].find((definition) => definition.id === id)\n}\n\nfunction findStepDefinition(\n id: string,\n supportCodeLibrary: SupportCodeLibrary\n): StepDefinition {\n return supportCodeLibrary.stepDefinitions.find(\n (definition) => definition.id === id\n )\n}\n"]}
@@ -1,17 +1,25 @@
1
1
  import { EventEmitter } from 'node:events';
2
- import { IdGenerator } from '@cucumber/messages';
2
+ import { IdGenerator, TestStepResult } from '@cucumber/messages';
3
3
  import { AssembledTestCase } from '../assemble';
4
4
  import { SupportCodeLibrary } from '../support_code_library_builder/types';
5
- import { RuntimeOptions } from './index';
5
+ import StepDefinitionSnippetBuilder from '../formatter/step_definition_snippet_builder';
6
+ import { RuntimeOptions } from './types';
7
+ export interface RunHookResult {
8
+ result: TestStepResult;
9
+ error?: any;
10
+ }
6
11
  export declare class Worker {
12
+ private readonly testRunStartedId;
7
13
  private readonly workerId;
8
14
  private readonly eventBroadcaster;
9
15
  private readonly newId;
10
16
  private readonly options;
11
17
  private readonly supportCodeLibrary;
12
- private readonly runTestRunHooks;
13
- constructor(workerId: string | undefined, eventBroadcaster: EventEmitter, newId: IdGenerator.NewId, options: RuntimeOptions, supportCodeLibrary: SupportCodeLibrary);
14
- runBeforeAllHooks(): Promise<void>;
18
+ private readonly snippetBuilder;
19
+ constructor(testRunStartedId: string, workerId: string | undefined, eventBroadcaster: EventEmitter, newId: IdGenerator.NewId, options: RuntimeOptions, supportCodeLibrary: SupportCodeLibrary, snippetBuilder: StepDefinitionSnippetBuilder);
20
+ private runTestRunHook;
21
+ private wrapTestRunHookError;
22
+ runBeforeAllHooks(): Promise<RunHookResult[]>;
15
23
  runTestCase({ gherkinDocument, pickle, testCase }: AssembledTestCase, failing: boolean): Promise<boolean>;
16
- runAfterAllHooks(): Promise<void>;
24
+ runAfterAllHooks(): Promise<RunHookResult[]>;
17
25
  }
@@ -4,33 +4,113 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Worker = void 0;
7
+ const messages_1 = require("@cucumber/messages");
8
+ const user_code_runner_1 = __importDefault(require("../user_code_runner"));
9
+ const value_checker_1 = require("../value_checker");
10
+ const helpers_1 = require("../formatter/helpers");
11
+ const helpers_2 = require("./helpers");
7
12
  const test_case_runner_1 = __importDefault(require("./test_case_runner"));
8
- const helpers_1 = require("./helpers");
9
- const run_test_run_hooks_1 = require("./run_test_run_hooks");
13
+ const scope_1 = require("./scope");
14
+ const format_error_1 = require("./format_error");
15
+ const stopwatch_1 = require("./stopwatch");
10
16
  class Worker {
17
+ testRunStartedId;
11
18
  workerId;
12
19
  eventBroadcaster;
13
20
  newId;
14
21
  options;
15
22
  supportCodeLibrary;
16
- runTestRunHooks;
17
- constructor(workerId, eventBroadcaster, newId, options, supportCodeLibrary) {
23
+ snippetBuilder;
24
+ constructor(testRunStartedId, workerId, eventBroadcaster, newId, options, supportCodeLibrary, snippetBuilder) {
25
+ this.testRunStartedId = testRunStartedId;
18
26
  this.workerId = workerId;
19
27
  this.eventBroadcaster = eventBroadcaster;
20
28
  this.newId = newId;
21
29
  this.options = options;
22
30
  this.supportCodeLibrary = supportCodeLibrary;
23
- this.runTestRunHooks = (0, run_test_run_hooks_1.makeRunTestRunHooks)(this.options.dryRun, this.supportCodeLibrary.defaultTimeout, this.options.worldParameters, (name, location) => {
24
- let message = `${name} hook errored`;
25
- if (this.workerId) {
26
- message += ` on worker ${this.workerId}`;
31
+ this.snippetBuilder = snippetBuilder;
32
+ }
33
+ async runTestRunHook(hookDefinition) {
34
+ const testRunHookStartedId = this.newId();
35
+ this.eventBroadcaster.emit('envelope', {
36
+ testRunHookStarted: {
37
+ testRunStartedId: this.testRunStartedId,
38
+ workerId: this.workerId,
39
+ id: testRunHookStartedId,
40
+ hookId: hookDefinition.id,
41
+ timestamp: (0, stopwatch_1.timestamp)(),
42
+ },
43
+ });
44
+ let result;
45
+ let error;
46
+ if (this.options.dryRun) {
47
+ result = {
48
+ duration: {
49
+ seconds: 0,
50
+ nanos: 0,
51
+ },
52
+ status: messages_1.TestStepResultStatus.SKIPPED,
53
+ };
54
+ }
55
+ else {
56
+ const stopwatch = (0, stopwatch_1.create)().start();
57
+ const context = { parameters: this.options.worldParameters };
58
+ const { error: rawError } = await (0, scope_1.runInTestRunScope)({ context }, () => user_code_runner_1.default.run({
59
+ argsArray: [],
60
+ fn: hookDefinition.code,
61
+ thisArg: context,
62
+ timeoutInMilliseconds: (0, value_checker_1.valueOrDefault)(hookDefinition.options.timeout, this.supportCodeLibrary.defaultTimeout),
63
+ }));
64
+ const duration = stopwatch.stop().duration();
65
+ if ((0, value_checker_1.doesHaveValue)(rawError)) {
66
+ result = {
67
+ duration,
68
+ status: messages_1.TestStepResultStatus.FAILED,
69
+ ...(0, format_error_1.formatError)(rawError, this.options.filterStacktraces),
70
+ };
71
+ error = this.wrapTestRunHookError('a BeforeAll', (0, helpers_1.formatLocation)(hookDefinition), rawError);
72
+ }
73
+ else {
74
+ result = {
75
+ duration,
76
+ status: messages_1.TestStepResultStatus.PASSED,
77
+ };
27
78
  }
28
- message += `, process exiting: ${location}`;
29
- return message;
79
+ }
80
+ this.eventBroadcaster.emit('envelope', {
81
+ testRunHookFinished: {
82
+ testRunHookStartedId,
83
+ result,
84
+ timestamp: (0, stopwatch_1.timestamp)(),
85
+ },
30
86
  });
87
+ return {
88
+ result,
89
+ error,
90
+ };
91
+ }
92
+ wrapTestRunHookError(name, location, error) {
93
+ if (!(0, value_checker_1.doesHaveValue)(error)) {
94
+ return undefined;
95
+ }
96
+ let message = `${name} hook errored`;
97
+ if (this.workerId) {
98
+ message += ` on worker ${this.workerId}`;
99
+ }
100
+ message += `, process exiting: ${location}`;
101
+ return new Error(message, { cause: error });
31
102
  }
32
103
  async runBeforeAllHooks() {
33
- await this.runTestRunHooks(this.supportCodeLibrary.beforeTestRunHookDefinitions, 'a BeforeAll');
104
+ const results = [];
105
+ for (const hookDefinition of this.supportCodeLibrary
106
+ .beforeTestRunHookDefinitions) {
107
+ const result = await this.runTestRunHook(hookDefinition);
108
+ results.push(result);
109
+ if ((0, value_checker_1.doesHaveValue)(result.error)) {
110
+ throw result.error;
111
+ }
112
+ }
113
+ return results;
34
114
  }
35
115
  async runTestCase({ gherkinDocument, pickle, testCase }, failing) {
36
116
  const testCaseRunner = new test_case_runner_1.default({
@@ -40,17 +120,29 @@ class Worker {
40
120
  gherkinDocument,
41
121
  pickle,
42
122
  testCase,
43
- retries: (0, helpers_1.retriesForPickle)(pickle, this.options),
123
+ retries: (0, helpers_2.retriesForPickle)(pickle, this.options),
44
124
  skip: this.options.dryRun || (this.options.failFast && failing),
45
125
  filterStackTraces: this.options.filterStacktraces,
46
126
  supportCodeLibrary: this.supportCodeLibrary,
47
127
  worldParameters: this.options.worldParameters,
128
+ snippetBuilder: this.snippetBuilder,
48
129
  });
49
130
  const status = await testCaseRunner.run();
50
- return !(0, helpers_1.shouldCauseFailure)(status, this.options);
131
+ return !(0, helpers_2.shouldCauseFailure)(status, this.options);
51
132
  }
52
133
  async runAfterAllHooks() {
53
- await this.runTestRunHooks(this.supportCodeLibrary.afterTestRunHookDefinitions.slice(0).reverse(), 'an AfterAll');
134
+ const results = [];
135
+ const reversed = [
136
+ ...this.supportCodeLibrary.afterTestRunHookDefinitions,
137
+ ].reverse();
138
+ for (const hookDefinition of reversed) {
139
+ const result = await this.runTestRunHook(hookDefinition);
140
+ results.push(result);
141
+ if ((0, value_checker_1.doesHaveValue)(result.error)) {
142
+ throw result.error;
143
+ }
144
+ }
145
+ return results;
54
146
  }
55
147
  }
56
148
  exports.Worker = Worker;