@cucumber/cucumber 10.6.0 → 10.8.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 (79) hide show
  1. package/lib/api/formatters.d.ts +3 -1
  2. package/lib/api/formatters.js +36 -45
  3. package/lib/api/formatters.js.map +1 -1
  4. package/lib/api/plugins.js +3 -3
  5. package/lib/api/plugins.js.map +1 -1
  6. package/lib/api/run_cucumber.js +7 -1
  7. package/lib/api/run_cucumber.js.map +1 -1
  8. package/lib/configuration/argv_parser.js +2 -2
  9. package/lib/configuration/argv_parser.js.map +1 -1
  10. package/lib/formatter/builder.d.ts +1 -1
  11. package/lib/formatter/builder.js +6 -13
  12. package/lib/formatter/builder.js.map +1 -1
  13. package/lib/formatter/builtin/html.d.ts +6 -0
  14. package/lib/formatter/builtin/html.js +25 -0
  15. package/lib/formatter/builtin/html.js.map +1 -0
  16. package/lib/formatter/builtin/index.d.ts +3 -0
  17. package/lib/formatter/builtin/index.js +33 -0
  18. package/lib/formatter/builtin/index.js.map +1 -0
  19. package/lib/formatter/builtin/message.d.ts +6 -0
  20. package/lib/formatter/builtin/message.js +10 -0
  21. package/lib/formatter/builtin/message.js.map +1 -0
  22. package/lib/formatter/create_stream.d.ts +4 -0
  23. package/lib/formatter/create_stream.js +28 -0
  24. package/lib/formatter/create_stream.js.map +1 -0
  25. package/lib/formatter/find_class_or_plugin.d.ts +1 -0
  26. package/lib/formatter/find_class_or_plugin.js +25 -0
  27. package/lib/formatter/find_class_or_plugin.js.map +1 -0
  28. package/lib/formatter/helpers/formatters.d.ts +0 -1
  29. package/lib/formatter/helpers/formatters.js +0 -12
  30. package/lib/formatter/helpers/formatters.js.map +1 -1
  31. package/lib/formatter/import_code.d.ts +1 -0
  32. package/lib/formatter/import_code.js +27 -0
  33. package/lib/formatter/import_code.js.map +1 -0
  34. package/lib/formatter/index.d.ts +2 -0
  35. package/lib/formatter/index.js.map +1 -1
  36. package/lib/formatter/resolve_implementation.d.ts +2 -0
  37. package/lib/formatter/resolve_implementation.js +24 -0
  38. package/lib/formatter/resolve_implementation.js.map +1 -0
  39. package/lib/index.d.ts +2 -0
  40. package/lib/index.js +4 -1
  41. package/lib/index.js.map +1 -1
  42. package/lib/plugin/plugin_manager.d.ts +3 -2
  43. package/lib/plugin/plugin_manager.js +12 -2
  44. package/lib/plugin/plugin_manager.js.map +1 -1
  45. package/lib/plugin/types.d.ts +11 -0
  46. package/lib/plugin/types.js.map +1 -1
  47. package/lib/runtime/parallel/coordinator.d.ts +1 -1
  48. package/lib/runtime/parallel/coordinator.js +7 -6
  49. package/lib/runtime/parallel/coordinator.js.map +1 -1
  50. package/lib/runtime/run_test_run_hooks.js +5 -3
  51. package/lib/runtime/run_test_run_hooks.js.map +1 -1
  52. package/lib/runtime/scope/index.d.ts +2 -0
  53. package/lib/runtime/scope/index.js +19 -0
  54. package/lib/runtime/scope/index.js.map +1 -0
  55. package/lib/runtime/scope/make_proxy.d.ts +1 -0
  56. package/lib/runtime/scope/make_proxy.js +42 -0
  57. package/lib/runtime/scope/make_proxy.js.map +1 -0
  58. package/lib/runtime/scope/test_case_scope.d.ts +17 -0
  59. package/lib/runtime/scope/test_case_scope.js +29 -0
  60. package/lib/runtime/scope/test_case_scope.js.map +1 -0
  61. package/lib/runtime/scope/test_run_scope.d.ts +16 -0
  62. package/lib/runtime/scope/test_run_scope.js +28 -0
  63. package/lib/runtime/scope/test_run_scope.js.map +1 -0
  64. package/lib/runtime/step_runner.js +3 -2
  65. package/lib/runtime/step_runner.js.map +1 -1
  66. package/lib/support_code_library_builder/context.d.ts +3 -0
  67. package/lib/support_code_library_builder/context.js +3 -0
  68. package/lib/support_code_library_builder/context.js.map +1 -0
  69. package/lib/version.d.ts +1 -1
  70. package/lib/version.js +1 -1
  71. package/lib/version.js.map +1 -1
  72. package/lib/wrapper.mjs +2 -0
  73. package/package.json +3 -2
  74. package/lib/formatter/html_formatter.d.ts +0 -7
  75. package/lib/formatter/html_formatter.js +0 -31
  76. package/lib/formatter/html_formatter.js.map +0 -1
  77. package/lib/formatter/message_formatter.d.ts +0 -5
  78. package/lib/formatter/message_formatter.js +0 -15
  79. package/lib/formatter/message_formatter.js.map +0 -1
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findClassOrPlugin = void 0;
4
+ const value_checker_1 = require("../value_checker");
5
+ function findClassOrPlugin(imported) {
6
+ return findRecursive(imported, 3);
7
+ }
8
+ exports.findClassOrPlugin = findClassOrPlugin;
9
+ function findRecursive(thing, depth) {
10
+ if ((0, value_checker_1.doesNotHaveValue)(thing)) {
11
+ return null;
12
+ }
13
+ if (typeof thing === 'function') {
14
+ return thing;
15
+ }
16
+ if (typeof thing === 'object' && thing.type === 'formatter') {
17
+ return thing;
18
+ }
19
+ depth--;
20
+ if (depth > 0) {
21
+ return findRecursive(thing.default, depth);
22
+ }
23
+ return null;
24
+ }
25
+ //# sourceMappingURL=find_class_or_plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find_class_or_plugin.js","sourceRoot":"","sources":["../../src/formatter/find_class_or_plugin.ts"],"names":[],"mappings":";;;AAAA,oDAAmD;AAEnD,SAAgB,iBAAiB,CAAC,QAAa;IAC7C,OAAO,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;AACnC,CAAC;AAFD,8CAEC;AAED,SAAS,aAAa,CAAC,KAAU,EAAE,KAAa;IAC9C,IAAI,IAAA,gCAAgB,EAAC,KAAK,CAAC,EAAE;QAC3B,OAAO,IAAI,CAAA;KACZ;IACD,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;QAC/B,OAAO,KAAK,CAAA;KACb;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE;QAC3D,OAAO,KAAK,CAAA;KACb;IACD,KAAK,EAAE,CAAA;IACP,IAAI,KAAK,GAAG,CAAC,EAAE;QACb,OAAO,aAAa,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;KAC3C;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { doesNotHaveValue } from '../value_checker'\n\nexport function findClassOrPlugin(imported: any) {\n return findRecursive(imported, 3)\n}\n\nfunction findRecursive(thing: any, depth: number): any {\n if (doesNotHaveValue(thing)) {\n return null\n }\n if (typeof thing === 'function') {\n return thing\n }\n if (typeof thing === 'object' && thing.type === 'formatter') {\n return thing\n }\n depth--\n if (depth > 0) {\n return findRecursive(thing.default, depth)\n }\n return null\n}\n"]}
@@ -1,6 +1,5 @@
1
1
  import Formatter from '../.';
2
2
  declare const Formatters: {
3
3
  getFormatters(): Record<string, typeof Formatter>;
4
- buildFormattersDocumentationString(): string;
5
4
  };
6
5
  export default Formatters;
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const json_formatter_1 = __importDefault(require("../json_formatter"));
7
- const message_formatter_1 = __importDefault(require("../message_formatter"));
8
7
  const progress_bar_formatter_1 = __importDefault(require("../progress_bar_formatter"));
9
8
  const progress_formatter_1 = __importDefault(require("../progress_formatter"));
10
9
  const rerun_formatter_1 = __importDefault(require("../rerun_formatter"));
@@ -12,14 +11,11 @@ const snippets_formatter_1 = __importDefault(require("../snippets_formatter"));
12
11
  const summary_formatter_1 = __importDefault(require("../summary_formatter"));
13
12
  const usage_formatter_1 = __importDefault(require("../usage_formatter"));
14
13
  const usage_json_formatter_1 = __importDefault(require("../usage_json_formatter"));
15
- const html_formatter_1 = __importDefault(require("../html_formatter"));
16
14
  const junit_formatter_1 = __importDefault(require("../junit_formatter"));
17
15
  const Formatters = {
18
16
  getFormatters() {
19
17
  return {
20
18
  json: json_formatter_1.default,
21
- message: message_formatter_1.default,
22
- html: html_formatter_1.default,
23
19
  progress: progress_formatter_1.default,
24
20
  'progress-bar': progress_bar_formatter_1.default,
25
21
  rerun: rerun_formatter_1.default,
@@ -30,14 +26,6 @@ const Formatters = {
30
26
  junit: junit_formatter_1.default,
31
27
  };
32
28
  },
33
- buildFormattersDocumentationString() {
34
- let concatenatedFormattersDocumentation = '';
35
- const formatters = this.getFormatters();
36
- for (const formatterName in formatters) {
37
- concatenatedFormattersDocumentation += ` ${formatterName}: ${formatters[formatterName].documentation}\n`;
38
- }
39
- return concatenatedFormattersDocumentation;
40
- },
41
29
  };
42
30
  exports.default = Formatters;
43
31
  //# sourceMappingURL=formatters.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"formatters.js","sourceRoot":"","sources":["../../../src/formatter/helpers/formatters.ts"],"names":[],"mappings":";;;;;AACA,uEAA6C;AAC7C,6EAAmD;AACnD,uFAA4D;AAC5D,+EAAqD;AACrD,yEAA+C;AAC/C,+EAAqD;AACrD,6EAAmD;AACnD,yEAA+C;AAC/C,mFAAwD;AACxD,uEAA6C;AAC7C,yEAA+C;AAE/C,MAAM,UAAU,GAAG;IACjB,aAAa;QACX,OAAO;YACL,IAAI,EAAE,wBAAa;YACnB,OAAO,EAAE,2BAAgB;YACzB,IAAI,EAAE,wBAAa;YACnB,QAAQ,EAAE,4BAAiB;YAC3B,cAAc,EAAE,gCAAoB;YACpC,KAAK,EAAE,yBAAc;YACrB,QAAQ,EAAE,4BAAiB;YAC3B,OAAO,EAAE,2BAAgB;YACzB,KAAK,EAAE,yBAAc;YACrB,YAAY,EAAE,8BAAkB;YAChC,KAAK,EAAE,yBAAc;SACtB,CAAA;IACH,CAAC;IACD,kCAAkC;QAChC,IAAI,mCAAmC,GAAW,EAAE,CAAA;QACpD,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,EAAE,CAAA;QACvC,KAAK,MAAM,aAAa,IAAI,UAAU,EAAE;YACtC,mCAAmC,IAAI,OAAO,aAAa,KAAK,UAAU,CAAC,aAAa,CAAC,CAAC,aAAa,IAAI,CAAA;SAC5G;QAED,OAAO,mCAAmC,CAAA;IAC5C,CAAC;CACF,CAAA;AAED,kBAAe,UAAU,CAAA","sourcesContent":["import Formatter from '../.'\nimport JsonFormatter from '../json_formatter'\nimport MessageFormatter from '../message_formatter'\nimport ProgressBarFormatter from '../progress_bar_formatter'\nimport ProgressFormatter from '../progress_formatter'\nimport RerunFormatter from '../rerun_formatter'\nimport SnippetsFormatter from '../snippets_formatter'\nimport SummaryFormatter from '../summary_formatter'\nimport UsageFormatter from '../usage_formatter'\nimport UsageJsonFormatter from '../usage_json_formatter'\nimport HtmlFormatter from '../html_formatter'\nimport JunitFormatter from '../junit_formatter'\n\nconst Formatters = {\n getFormatters(): Record<string, typeof Formatter> {\n return {\n json: JsonFormatter,\n message: MessageFormatter,\n html: HtmlFormatter,\n progress: ProgressFormatter,\n 'progress-bar': ProgressBarFormatter,\n rerun: RerunFormatter,\n snippets: SnippetsFormatter,\n summary: SummaryFormatter,\n usage: UsageFormatter,\n 'usage-json': UsageJsonFormatter,\n junit: JunitFormatter,\n }\n },\n buildFormattersDocumentationString(): string {\n let concatenatedFormattersDocumentation: string = ''\n const formatters = this.getFormatters()\n for (const formatterName in formatters) {\n concatenatedFormattersDocumentation += ` ${formatterName}: ${formatters[formatterName].documentation}\\n`\n }\n\n return concatenatedFormattersDocumentation\n },\n}\n\nexport default Formatters\n"]}
1
+ {"version":3,"file":"formatters.js","sourceRoot":"","sources":["../../../src/formatter/helpers/formatters.ts"],"names":[],"mappings":";;;;;AACA,uEAA6C;AAC7C,uFAA4D;AAC5D,+EAAqD;AACrD,yEAA+C;AAC/C,+EAAqD;AACrD,6EAAmD;AACnD,yEAA+C;AAC/C,mFAAwD;AACxD,yEAA+C;AAE/C,MAAM,UAAU,GAAG;IACjB,aAAa;QACX,OAAO;YACL,IAAI,EAAE,wBAAa;YACnB,QAAQ,EAAE,4BAAiB;YAC3B,cAAc,EAAE,gCAAoB;YACpC,KAAK,EAAE,yBAAc;YACrB,QAAQ,EAAE,4BAAiB;YAC3B,OAAO,EAAE,2BAAgB;YACzB,KAAK,EAAE,yBAAc;YACrB,YAAY,EAAE,8BAAkB;YAChC,KAAK,EAAE,yBAAc;SACtB,CAAA;IACH,CAAC;CACF,CAAA;AAED,kBAAe,UAAU,CAAA","sourcesContent":["import Formatter from '../.'\nimport JsonFormatter from '../json_formatter'\nimport ProgressBarFormatter from '../progress_bar_formatter'\nimport ProgressFormatter from '../progress_formatter'\nimport RerunFormatter from '../rerun_formatter'\nimport SnippetsFormatter from '../snippets_formatter'\nimport SummaryFormatter from '../summary_formatter'\nimport UsageFormatter from '../usage_formatter'\nimport UsageJsonFormatter from '../usage_json_formatter'\nimport JunitFormatter from '../junit_formatter'\n\nconst Formatters = {\n getFormatters(): Record<string, typeof Formatter> {\n return {\n json: JsonFormatter,\n progress: ProgressFormatter,\n 'progress-bar': ProgressBarFormatter,\n rerun: RerunFormatter,\n snippets: SnippetsFormatter,\n summary: SummaryFormatter,\n usage: UsageFormatter,\n 'usage-json': UsageJsonFormatter,\n junit: JunitFormatter,\n }\n },\n}\n\nexport default Formatters\n"]}
@@ -0,0 +1 @@
1
+ export declare function importCode(specifier: string, cwd: string): Promise<any>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.importCode = void 0;
7
+ const node_url_1 = require("node:url");
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ async function importCode(specifier, cwd) {
10
+ try {
11
+ let normalized = specifier;
12
+ if (specifier.startsWith('.')) {
13
+ normalized = (0, node_url_1.pathToFileURL)(node_path_1.default.resolve(cwd, specifier));
14
+ }
15
+ else if (specifier.startsWith('file://')) {
16
+ normalized = new URL(specifier);
17
+ }
18
+ return await import(normalized.toString());
19
+ }
20
+ catch (e) {
21
+ throw new Error(`Failed to import formatter ${specifier}`, {
22
+ cause: e,
23
+ });
24
+ }
25
+ }
26
+ exports.importCode = importCode;
27
+ //# sourceMappingURL=import_code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import_code.js","sourceRoot":"","sources":["../../src/formatter/import_code.ts"],"names":[],"mappings":";;;;;;AAAA,uCAAwC;AACxC,0DAA4B;AAErB,KAAK,UAAU,UAAU,CAAC,SAAiB,EAAE,GAAW;IAC7D,IAAI;QACF,IAAI,UAAU,GAAiB,SAAS,CAAA;QACxC,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YAC7B,UAAU,GAAG,IAAA,wBAAa,EAAC,mBAAI,CAAC,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAA;SACzD;aAAM,IAAI,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;YAC1C,UAAU,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAA;SAChC;QACD,OAAO,MAAM,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAA;KAC3C;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,IAAI,KAAK,CAAC,8BAA8B,SAAS,EAAE,EAAE;YACzD,KAAK,EAAE,CAAC;SACT,CAAC,CAAA;KACH;AACH,CAAC;AAdD,gCAcC","sourcesContent":["import { pathToFileURL } from 'node:url'\nimport path from 'node:path'\n\nexport async function importCode(specifier: string, cwd: string): Promise<any> {\n try {\n let normalized: URL | string = specifier\n if (specifier.startsWith('.')) {\n normalized = pathToFileURL(path.resolve(cwd, specifier))\n } else if (specifier.startsWith('file://')) {\n normalized = new URL(specifier)\n }\n return await import(normalized.toString())\n } catch (e) {\n throw new Error(`Failed to import formatter ${specifier}`, {\n cause: e,\n })\n }\n}\n"]}
@@ -3,6 +3,7 @@
3
3
  import { Writable } from 'node:stream';
4
4
  import { EventEmitter } from 'node:events';
5
5
  import { SupportCodeLibrary } from '../support_code_library_builder/types';
6
+ import { FormatterPlugin } from '../plugin';
6
7
  import { IColorFns } from './get_color_fns';
7
8
  import { EventDataCollector } from './helpers';
8
9
  import StepDefinitionSnippetBuilder from './step_definition_snippet_builder';
@@ -18,6 +19,7 @@ export interface FormatOptions {
18
19
  printAttachments?: boolean;
19
20
  [customKey: string]: any;
20
21
  }
22
+ export type FormatterImplementation = typeof Formatter | FormatterPlugin;
21
23
  export type IFormatterStream = Writable;
22
24
  export type IFormatterLogFn = (buffer: string | Uint8Array) => void;
23
25
  export type IFormatterCleanupFn = () => Promise<any>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/formatter/index.ts"],"names":[],"mappings":";;AAGA,oDAAiD;AAoCjD,MAAqB,SAAS;IAClB,QAAQ,CAAW;IACnB,GAAG,CAAQ;IACX,kBAAkB,CAAoB;IACtC,GAAG,CAAiB;IACpB,cAAc,CAA8B;IAC5C,MAAM,CAAU;IAChB,kBAAkB,CAAoB;IACtC,gBAAgB,CAAS;IAClB,OAAO,CAAqB;IAC7C,MAAM,CAAU,aAAa,CAAQ;IAErC,YAAY,OAA0B;QACpC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;QAChC,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;QACtB,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAA;QACpD,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;QACtB,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;QAC5C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;QAC5B,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAA;QACpD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,CAAC,gBAAgB,GAAG,IAAA,8BAAc,EACpC,OAAO,CAAC,iBAAiB,CAAC,gBAAgB,EAC1C,IAAI,CACL,CAAA;IACH,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,MAAM,IAAI,CAAC,OAAO,EAAE,CAAA;IACtB,CAAC;CACF;AA9BD,4BA8BC","sourcesContent":["import { Writable } from 'node:stream'\nimport { EventEmitter } from 'node:events'\nimport { SupportCodeLibrary } from '../support_code_library_builder/types'\nimport { valueOrDefault } from '../value_checker'\nimport { IColorFns } from './get_color_fns'\nimport { EventDataCollector } from './helpers'\nimport StepDefinitionSnippetBuilder from './step_definition_snippet_builder'\nimport { SnippetInterface } from './step_definition_snippet_builder/snippet_syntax'\n\nexport interface FormatRerunOptions {\n separator?: string\n}\n\nexport interface FormatOptions {\n colorsEnabled?: boolean\n rerun?: FormatRerunOptions\n snippetInterface?: SnippetInterface\n snippetSyntax?: string\n printAttachments?: boolean\n [customKey: string]: any\n}\n\nexport type IFormatterStream = Writable\nexport type IFormatterLogFn = (buffer: string | Uint8Array) => void\nexport type IFormatterCleanupFn = () => Promise<any>\n\nexport interface IFormatterOptions {\n colorFns: IColorFns\n cwd: string\n eventBroadcaster: EventEmitter\n eventDataCollector: EventDataCollector\n log: IFormatterLogFn\n parsedArgvOptions: FormatOptions\n snippetBuilder: StepDefinitionSnippetBuilder\n stream: Writable\n cleanup: IFormatterCleanupFn\n supportCodeLibrary: SupportCodeLibrary\n}\n\nexport default class Formatter {\n protected colorFns: IColorFns\n protected cwd: string\n protected eventDataCollector: EventDataCollector\n protected log: IFormatterLogFn\n protected snippetBuilder: StepDefinitionSnippetBuilder\n protected stream: Writable\n protected supportCodeLibrary: SupportCodeLibrary\n protected printAttachments: boolean\n private readonly cleanup: IFormatterCleanupFn\n static readonly documentation: string\n\n constructor(options: IFormatterOptions) {\n this.colorFns = options.colorFns\n this.cwd = options.cwd\n this.eventDataCollector = options.eventDataCollector\n this.log = options.log\n this.snippetBuilder = options.snippetBuilder\n this.stream = options.stream\n this.supportCodeLibrary = options.supportCodeLibrary\n this.cleanup = options.cleanup\n this.printAttachments = valueOrDefault(\n options.parsedArgvOptions.printAttachments,\n true\n )\n }\n\n async finished(): Promise<void> {\n await this.cleanup()\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/formatter/index.ts"],"names":[],"mappings":";;AAGA,oDAAiD;AAsCjD,MAAqB,SAAS;IAClB,QAAQ,CAAW;IACnB,GAAG,CAAQ;IACX,kBAAkB,CAAoB;IACtC,GAAG,CAAiB;IACpB,cAAc,CAA8B;IAC5C,MAAM,CAAU;IAChB,kBAAkB,CAAoB;IACtC,gBAAgB,CAAS;IAClB,OAAO,CAAqB;IAC7C,MAAM,CAAU,aAAa,CAAQ;IAErC,YAAY,OAA0B;QACpC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;QAChC,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;QACtB,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAA;QACpD,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAA;QACtB,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;QAC5C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;QAC5B,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAA;QACpD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,CAAC,gBAAgB,GAAG,IAAA,8BAAc,EACpC,OAAO,CAAC,iBAAiB,CAAC,gBAAgB,EAC1C,IAAI,CACL,CAAA;IACH,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,MAAM,IAAI,CAAC,OAAO,EAAE,CAAA;IACtB,CAAC;CACF;AA9BD,4BA8BC","sourcesContent":["import { Writable } from 'node:stream'\nimport { EventEmitter } from 'node:events'\nimport { SupportCodeLibrary } from '../support_code_library_builder/types'\nimport { valueOrDefault } from '../value_checker'\nimport { FormatterPlugin } from '../plugin'\nimport { IColorFns } from './get_color_fns'\nimport { EventDataCollector } from './helpers'\nimport StepDefinitionSnippetBuilder from './step_definition_snippet_builder'\nimport { SnippetInterface } from './step_definition_snippet_builder/snippet_syntax'\n\nexport interface FormatRerunOptions {\n separator?: string\n}\n\nexport interface FormatOptions {\n colorsEnabled?: boolean\n rerun?: FormatRerunOptions\n snippetInterface?: SnippetInterface\n snippetSyntax?: string\n printAttachments?: boolean\n [customKey: string]: any\n}\n\nexport type FormatterImplementation = typeof Formatter | FormatterPlugin\nexport type IFormatterStream = Writable\nexport type IFormatterLogFn = (buffer: string | Uint8Array) => void\nexport type IFormatterCleanupFn = () => Promise<any>\n\nexport interface IFormatterOptions {\n colorFns: IColorFns\n cwd: string\n eventBroadcaster: EventEmitter\n eventDataCollector: EventDataCollector\n log: IFormatterLogFn\n parsedArgvOptions: FormatOptions\n snippetBuilder: StepDefinitionSnippetBuilder\n stream: Writable\n cleanup: IFormatterCleanupFn\n supportCodeLibrary: SupportCodeLibrary\n}\n\nexport default class Formatter {\n protected colorFns: IColorFns\n protected cwd: string\n protected eventDataCollector: EventDataCollector\n protected log: IFormatterLogFn\n protected snippetBuilder: StepDefinitionSnippetBuilder\n protected stream: Writable\n protected supportCodeLibrary: SupportCodeLibrary\n protected printAttachments: boolean\n private readonly cleanup: IFormatterCleanupFn\n static readonly documentation: string\n\n constructor(options: IFormatterOptions) {\n this.colorFns = options.colorFns\n this.cwd = options.cwd\n this.eventDataCollector = options.eventDataCollector\n this.log = options.log\n this.snippetBuilder = options.snippetBuilder\n this.stream = options.stream\n this.supportCodeLibrary = options.supportCodeLibrary\n this.cleanup = options.cleanup\n this.printAttachments = valueOrDefault(\n options.parsedArgvOptions.printAttachments,\n true\n )\n }\n\n async finished(): Promise<void> {\n await this.cleanup()\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { FormatterImplementation } from './index';
2
+ export declare function resolveImplementation(specifier: string, cwd: string): Promise<FormatterImplementation>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveImplementation = void 0;
7
+ const builtin_1 = __importDefault(require("./builtin"));
8
+ const import_code_1 = require("./import_code");
9
+ const find_class_or_plugin_1 = require("./find_class_or_plugin");
10
+ async function resolveImplementation(specifier, cwd) {
11
+ if (builtin_1.default[specifier]) {
12
+ return builtin_1.default[specifier];
13
+ }
14
+ else {
15
+ const imported = await (0, import_code_1.importCode)(specifier, cwd);
16
+ const found = (0, find_class_or_plugin_1.findClassOrPlugin)(imported);
17
+ if (!found) {
18
+ throw new Error(`${specifier} does not export a function/class`);
19
+ }
20
+ return found;
21
+ }
22
+ }
23
+ exports.resolveImplementation = resolveImplementation;
24
+ //# sourceMappingURL=resolve_implementation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve_implementation.js","sourceRoot":"","sources":["../../src/formatter/resolve_implementation.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA+B;AAC/B,+CAA0C;AAC1C,iEAA0D;AAGnD,KAAK,UAAU,qBAAqB,CACzC,SAAiB,EACjB,GAAW;IAEX,IAAI,iBAAO,CAAC,SAAS,CAAC,EAAE;QACtB,OAAO,iBAAO,CAAC,SAAS,CAAC,CAAA;KAC1B;SAAM;QACL,MAAM,QAAQ,GAAG,MAAM,IAAA,wBAAU,EAAC,SAAS,EAAE,GAAG,CAAC,CAAA;QACjD,MAAM,KAAK,GAAG,IAAA,wCAAiB,EAAC,QAAQ,CAAC,CAAA;QACzC,IAAI,CAAC,KAAK,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,GAAG,SAAS,mCAAmC,CAAC,CAAA;SACjE;QACD,OAAO,KAAK,CAAA;KACb;AACH,CAAC;AAdD,sDAcC","sourcesContent":["import builtin from './builtin'\nimport { importCode } from './import_code'\nimport { findClassOrPlugin } from './find_class_or_plugin'\nimport { FormatterImplementation } from './index'\n\nexport async function resolveImplementation(\n specifier: string,\n cwd: string\n): Promise<FormatterImplementation> {\n if (builtin[specifier]) {\n return builtin[specifier]\n } else {\n const imported = await importCode(specifier, cwd)\n const found = findClassOrPlugin(imported)\n if (!found) {\n throw new Error(`${specifier} does not export a function/class`)\n }\n return found\n }\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -43,6 +43,8 @@ export declare const setParallelCanAssign: (fn: import("./support_code_library_b
43
43
  export declare const Then: import("./support_code_library_builder/types").IDefineStep;
44
44
  export declare const When: import("./support_code_library_builder/types").IDefineStep;
45
45
  export { default as World, IWorld, IWorldOptions, } from './support_code_library_builder/world';
46
+ export { IContext } from './support_code_library_builder/context';
47
+ export { worldProxy as world, contextProxy as context } from './runtime/scope';
46
48
  export { parallelCanAssignHelpers };
47
49
  export { ITestCaseHookParameter, ITestStepHookParameter, } from './support_code_library_builder/types';
48
50
  export declare const Status: typeof messages.TestStepResultStatus;
package/lib/index.js CHANGED
@@ -34,7 +34,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
34
34
  return (mod && mod.__esModule) ? mod : { "default": mod };
35
35
  };
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.Runtime = exports.PickleFilter = exports.parseGherkinMessageStream = exports.Cli = exports.wrapPromiseWithTimeout = exports.Status = exports.parallelCanAssignHelpers = exports.World = exports.When = exports.Then = exports.setParallelCanAssign = exports.setWorldConstructor = exports.setDefinitionFunctionWrapper = exports.setDefaultTimeout = exports.Given = exports.defineParameterType = exports.defineStep = exports.BeforeStep = exports.BeforeAll = exports.Before = exports.AfterStep = exports.AfterAll = exports.After = exports.formatterHelpers = exports.UsageJsonFormatter = exports.UsageFormatter = exports.SummaryFormatter = exports.SnippetsFormatter = exports.RerunFormatter = exports.ProgressFormatter = exports.JsonFormatter = exports.FormatterBuilder = exports.Formatter = exports.TestCaseHookDefinition = exports.DataTable = exports.supportCodeLibraryBuilder = exports.version = void 0;
37
+ exports.Runtime = exports.PickleFilter = exports.parseGherkinMessageStream = exports.Cli = exports.wrapPromiseWithTimeout = exports.Status = exports.parallelCanAssignHelpers = exports.context = exports.world = exports.World = exports.When = exports.Then = exports.setParallelCanAssign = exports.setWorldConstructor = exports.setDefinitionFunctionWrapper = exports.setDefaultTimeout = exports.Given = exports.defineParameterType = exports.defineStep = exports.BeforeStep = exports.BeforeAll = exports.Before = exports.AfterStep = exports.AfterAll = exports.After = exports.formatterHelpers = exports.UsageJsonFormatter = exports.UsageFormatter = exports.SummaryFormatter = exports.SnippetsFormatter = exports.RerunFormatter = exports.ProgressFormatter = exports.JsonFormatter = exports.FormatterBuilder = exports.Formatter = exports.TestCaseHookDefinition = exports.DataTable = exports.supportCodeLibraryBuilder = exports.version = void 0;
38
38
  const node_util_1 = require("node:util");
39
39
  const messages = __importStar(require("@cucumber/messages"));
40
40
  const cli_1 = __importDefault(require("./cli"));
@@ -94,6 +94,9 @@ exports.Then = methods.Then;
94
94
  exports.When = methods.When;
95
95
  var world_1 = require("./support_code_library_builder/world");
96
96
  Object.defineProperty(exports, "World", { enumerable: true, get: function () { return __importDefault(world_1).default; } });
97
+ var scope_1 = require("./runtime/scope");
98
+ Object.defineProperty(exports, "world", { enumerable: true, get: function () { return scope_1.worldProxy; } });
99
+ Object.defineProperty(exports, "context", { enumerable: true, get: function () { return scope_1.contextProxy; } });
97
100
  exports.Status = messages.TestStepResultStatus;
98
101
  // Time helpers
99
102
  var time_1 = require("./time");
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,yCAAqC;AACrC,6DAA8C;AAC9C,gDAAuC;AACvC,0DAA2C;AAC3C,sEAAuD;AAyB9C,4CAAgB;AAxBzB,oEAA0D;AAC1D,qHAAsG;AA+C7F,4DAAwB;AA9CjC,wDAA+C;AAC/C,kGAAsE;AACtE,uCAA+C;AAE/C,uEAAuE;AAC1D,QAAA,OAAO,GAAG,iBAAkB,CAAA;AAEzC,YAAY;AACZ,+EAAqF;AAA5E,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IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;AACnB,QAAA,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;AAChC,8DAI6C;AAH3C,+GAAA,OAAO,OAAS;AAUL,QAAA,MAAM,GAAG,QAAQ,CAAC,oBAAoB,CAAA;AAEnD,eAAe;AACf,+BAA+C;AAAtC,8GAAA,sBAAsB,OAAA;AAE/B,aAAa;AACb;;GAEG;AACU,QAAA,GAAG,GAAG,IAAA,qBAAS,EAC1B,aAAI,EACJ,4HAA4H,CAC7H,CAAA;AACD;;GAEG;AACU,QAAA,yBAAyB,GAAG,IAAA,qBAAS,EAChD,UAAU,CAAC,yBAAyB,EACpC,kJAAkJ,CACnJ,CAAA;AACD;;GAEG;AACU,QAAA,YAAY,GAAG,IAAA,qBAAS,EACnC,uBAAa,EACb,qIAAqI,CACtI,CAAA;AACD;;GAEG;AACU,QAAA,OAAO,GAAG,IAAA,qBAAS,EAC9B,iBAAQ,EACR,gIAAgI,CACjI,CAAA","sourcesContent":["/**\n * User code functions and helpers\n *\n * @packageDocumentation\n * @module (root)\n * @remarks\n * These docs cover the functions and helpers for user code registration and test setup. The entry point is `@cucumber/cucumber`.\n */\n\nimport { deprecate } from 'node:util'\nimport * as messages from '@cucumber/messages'\nimport { default as _Cli } from './cli'\nimport * as cliHelpers from './cli/helpers'\nimport * as formatterHelpers from './formatter/helpers'\nimport { default as _PickleFilter } from './pickle_filter'\nimport * as parallelCanAssignHelpers from './support_code_library_builder/parallel_can_assign_helpers'\nimport { default as _Runtime } from './runtime'\nimport supportCodeLibraryBuilder from './support_code_library_builder'\nimport { version as _version } from './version'\n\n// type version as string to avoid tripping api-extractor every release\nexport const version = _version as string\n\n// Top level\nexport { default as supportCodeLibraryBuilder } from './support_code_library_builder'\nexport { default as DataTable } from './models/data_table'\nexport { default as TestCaseHookDefinition } from './models/test_case_hook_definition'\n\n// Formatters\nexport { default as Formatter, IFormatterOptions } from './formatter'\nexport { default as FormatterBuilder } from './formatter/builder'\nexport { default as JsonFormatter } from './formatter/json_formatter'\nexport { default as ProgressFormatter } from './formatter/progress_formatter'\nexport { default as RerunFormatter } from './formatter/rerun_formatter'\nexport { default as SnippetsFormatter } from './formatter/snippets_formatter'\nexport { default as SummaryFormatter } from './formatter/summary_formatter'\nexport { default as UsageFormatter } from './formatter/usage_formatter'\nexport { default as UsageJsonFormatter } from './formatter/usage_json_formatter'\nexport { formatterHelpers }\n\n// Support Code Functions\nconst { methods } = supportCodeLibraryBuilder\nexport const After = methods.After\nexport const AfterAll = methods.AfterAll\nexport const AfterStep = methods.AfterStep\nexport const Before = methods.Before\nexport const BeforeAll = methods.BeforeAll\nexport const BeforeStep = methods.BeforeStep\nexport const defineStep = methods.defineStep\nexport const defineParameterType = methods.defineParameterType\nexport const Given = methods.Given\nexport const setDefaultTimeout = methods.setDefaultTimeout\nexport const setDefinitionFunctionWrapper = methods.setDefinitionFunctionWrapper\nexport const setWorldConstructor = methods.setWorldConstructor\nexport const setParallelCanAssign = methods.setParallelCanAssign\nexport const Then = methods.Then\nexport const When = methods.When\nexport {\n default as World,\n IWorld,\n IWorldOptions,\n} from './support_code_library_builder/world'\nexport { parallelCanAssignHelpers }\n\nexport {\n ITestCaseHookParameter,\n ITestStepHookParameter,\n} from './support_code_library_builder/types'\nexport const Status = messages.TestStepResultStatus\n\n// Time helpers\nexport { wrapPromiseWithTimeout } from './time'\n\n// Deprecated\n/**\n * @deprecated use `runCucumber` instead; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md\n */\nexport const Cli = deprecate(\n _Cli,\n '`Cli` is deprecated, use `runCucumber` instead; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md'\n)\n/**\n * @deprecated use `loadSources` instead; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md\n */\nexport const parseGherkinMessageStream = deprecate(\n cliHelpers.parseGherkinMessageStream,\n '`parseGherkinMessageStream` is deprecated, use `loadSources` instead; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md'\n)\n/**\n * @deprecated use `loadSources` instead; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md\n */\nexport const PickleFilter = deprecate(\n _PickleFilter,\n '`PickleFilter` is deprecated, use `loadSources` instead; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md'\n)\n/**\n * @deprecated use `runCucumber` instead; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md\n */\nexport const Runtime = deprecate(\n _Runtime,\n '`Runtime` is deprecated, use `runCucumber` instead; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md'\n)\nexport { INewRuntimeOptions, IRuntimeOptions } from './runtime'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,yCAAqC;AACrC,6DAA8C;AAC9C,gDAAuC;AACvC,0DAA2C;AAC3C,sEAAuD;AAyB9C,4CAAgB;AAxBzB,oEAA0D;AAC1D,qHAAsG;AAiD7F,4DAAwB;AAhDjC,wDAA+C;AAC/C,kGAAsE;AACtE,uCAA+C;AAE/C,uEAAuE;AAC1D,QAAA,OAAO,GAAG,iBAAkB,CAAA;AAEzC,YAAY;AACZ,+EAAqF;AAA5E,0JAAA,OAAO,OAA6B;AAC7C,kDAA0D;AAAjD,wHAAA,OAAO,OAAa;AAC7B,gFAAsF;AAA7E,oJAAA,OAAO,OAA0B;AAE1C,aAAa;AACb,yCAAqE;AAA5D,uHAAA,OAAO,OAAa;AAC7B,+CAAiE;AAAxD,4HAAA,OAAO,OAAoB;AACpC,6DAAqE;AAA5D,gIAAA,OAAO,OAAiB;AACjC,qEAA6E;AAApE,wIAAA,OAAO,OAAqB;AACrC,+DAAuE;AAA9D,kIAAA,OAAO,OAAkB;AAClC,qEAA6E;AAApE,wIAAA,OAAO,OAAqB;AACrC,mEAA2E;AAAlE,sIAAA,OAAO,OAAoB;AACpC,+DAAuE;AAA9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yB,GAAG,IAAA,qBAAS,EAChD,UAAU,CAAC,yBAAyB,EACpC,kJAAkJ,CACnJ,CAAA;AACD;;GAEG;AACU,QAAA,YAAY,GAAG,IAAA,qBAAS,EACnC,uBAAa,EACb,qIAAqI,CACtI,CAAA;AACD;;GAEG;AACU,QAAA,OAAO,GAAG,IAAA,qBAAS,EAC9B,iBAAQ,EACR,gIAAgI,CACjI,CAAA","sourcesContent":["/**\n * User code functions and helpers\n *\n * @packageDocumentation\n * @module (root)\n * @remarks\n * These docs cover the functions and helpers for user code registration and test setup. The entry point is `@cucumber/cucumber`.\n */\n\nimport { deprecate } from 'node:util'\nimport * as messages from '@cucumber/messages'\nimport { default as _Cli } from './cli'\nimport * as cliHelpers from './cli/helpers'\nimport * as formatterHelpers from './formatter/helpers'\nimport { default as _PickleFilter } from './pickle_filter'\nimport * as parallelCanAssignHelpers from './support_code_library_builder/parallel_can_assign_helpers'\nimport { default as _Runtime } from './runtime'\nimport supportCodeLibraryBuilder from './support_code_library_builder'\nimport { version as _version } from './version'\n\n// type version as string to avoid tripping api-extractor every release\nexport const version = _version as string\n\n// Top level\nexport { default as supportCodeLibraryBuilder } from './support_code_library_builder'\nexport { default as DataTable } from './models/data_table'\nexport { default as TestCaseHookDefinition } from './models/test_case_hook_definition'\n\n// Formatters\nexport { default as Formatter, IFormatterOptions } from './formatter'\nexport { default as FormatterBuilder } from './formatter/builder'\nexport { default as JsonFormatter } from './formatter/json_formatter'\nexport { default as ProgressFormatter } from './formatter/progress_formatter'\nexport { default as RerunFormatter } from './formatter/rerun_formatter'\nexport { default as SnippetsFormatter } from './formatter/snippets_formatter'\nexport { default as SummaryFormatter } from './formatter/summary_formatter'\nexport { default as UsageFormatter } from './formatter/usage_formatter'\nexport { default as UsageJsonFormatter } from './formatter/usage_json_formatter'\nexport { formatterHelpers }\n\n// Support Code Functions\nconst { methods } = supportCodeLibraryBuilder\nexport const After = methods.After\nexport const AfterAll = methods.AfterAll\nexport const AfterStep = methods.AfterStep\nexport const Before = methods.Before\nexport const BeforeAll = methods.BeforeAll\nexport const BeforeStep = methods.BeforeStep\nexport const defineStep = methods.defineStep\nexport const defineParameterType = methods.defineParameterType\nexport const Given = methods.Given\nexport const setDefaultTimeout = methods.setDefaultTimeout\nexport const setDefinitionFunctionWrapper = methods.setDefinitionFunctionWrapper\nexport const setWorldConstructor = methods.setWorldConstructor\nexport const setParallelCanAssign = methods.setParallelCanAssign\nexport const Then = methods.Then\nexport const When = methods.When\nexport {\n default as World,\n IWorld,\n IWorldOptions,\n} from './support_code_library_builder/world'\nexport { IContext } from './support_code_library_builder/context'\nexport { worldProxy as world, contextProxy as context } from './runtime/scope'\nexport { parallelCanAssignHelpers }\n\nexport {\n ITestCaseHookParameter,\n ITestStepHookParameter,\n} from './support_code_library_builder/types'\nexport const Status = messages.TestStepResultStatus\n\n// Time helpers\nexport { wrapPromiseWithTimeout } from './time'\n\n// Deprecated\n/**\n * @deprecated use `runCucumber` instead; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md\n */\nexport const Cli = deprecate(\n _Cli,\n '`Cli` is deprecated, use `runCucumber` instead; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md'\n)\n/**\n * @deprecated use `loadSources` instead; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md\n */\nexport const parseGherkinMessageStream = deprecate(\n cliHelpers.parseGherkinMessageStream,\n '`parseGherkinMessageStream` is deprecated, use `loadSources` instead; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md'\n)\n/**\n * @deprecated use `loadSources` instead; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md\n */\nexport const PickleFilter = deprecate(\n _PickleFilter,\n '`PickleFilter` is deprecated, use `loadSources` instead; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md'\n)\n/**\n * @deprecated use `runCucumber` instead; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md\n */\nexport const Runtime = deprecate(\n _Runtime,\n '`Runtime` is deprecated, use `runCucumber` instead; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md'\n)\nexport { INewRuntimeOptions, IRuntimeOptions } from './runtime'\n"]}
@@ -1,11 +1,12 @@
1
1
  import { IRunEnvironment } from '../api';
2
2
  import { ILogger } from '../logger';
3
- import { InternalPlugin, CoordinatorPluginEventValues, CoordinatorPluginEventKey, CoordinatorPluginTransformEventKey, Operation } from './types';
3
+ import { InternalPlugin, CoordinatorPluginEventValues, CoordinatorPluginEventKey, CoordinatorPluginTransformEventKey, Operation, FormatterPlugin } from './types';
4
4
  export declare class PluginManager {
5
5
  private handlers;
6
6
  private cleanupFns;
7
7
  private register;
8
- init<OptionsType>(operation: Operation, plugin: InternalPlugin<OptionsType>, options: OptionsType, logger: ILogger, environment: Required<IRunEnvironment>): Promise<void>;
8
+ initFormatter<OptionsType>(plugin: FormatterPlugin<OptionsType>, options: OptionsType, write: (buffer: string | Uint8Array) => void): Promise<void>;
9
+ initCoordinator<OptionsType>(operation: Operation, plugin: InternalPlugin<OptionsType>, options: OptionsType, logger: ILogger, environment: Required<IRunEnvironment>): Promise<void>;
9
10
  emit<K extends CoordinatorPluginEventKey>(event: K, value: CoordinatorPluginEventValues[K]): void;
10
11
  transform<K extends CoordinatorPluginTransformEventKey>(event: K, value: CoordinatorPluginEventValues[K]): Promise<CoordinatorPluginEventValues[K]>;
11
12
  cleanup(): Promise<void>;
@@ -10,9 +10,19 @@ class PluginManager {
10
10
  };
11
11
  cleanupFns = [];
12
12
  async register(event, handler) {
13
- this.handlers[event].push(handler);
13
+ this.handlers[event]?.push(handler);
14
14
  }
15
- async init(operation, plugin, options, logger, environment) {
15
+ async initFormatter(plugin, options, write) {
16
+ const cleanupFn = await plugin.formatter({
17
+ on: (key, handler) => this.register(key, handler),
18
+ options,
19
+ write,
20
+ });
21
+ if (typeof cleanupFn === 'function') {
22
+ this.cleanupFns.push(cleanupFn);
23
+ }
24
+ }
25
+ async initCoordinator(operation, plugin, options, logger, environment) {
16
26
  const cleanupFn = await plugin.coordinator({
17
27
  operation,
18
28
  on: this.register.bind(this),
@@ -1 +1 @@
1
- {"version":3,"file":"plugin_manager.js","sourceRoot":"","sources":["../../src/plugin/plugin_manager.ts"],"names":[],"mappings":";;;AAgBA,MAAa,aAAa;IAChB,QAAQ,GAAoB;QAClC,OAAO,EAAE,EAAE;QACX,eAAe,EAAE,EAAE;QACnB,gBAAgB,EAAE,EAAE;QACpB,eAAe,EAAE,EAAE;KACpB,CAAA;IACO,UAAU,GAAoB,EAAE,CAAA;IAEhC,KAAK,CAAC,QAAQ,CACpB,KAAQ,EACR,OAAyC;QAEzC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACpC,CAAC;IAED,KAAK,CAAC,IAAI,CACR,SAAoB,EACpB,MAAmC,EACnC,OAAoB,EACpB,MAAe,EACf,WAAsC;QAEtC,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC;YACzC,SAAS;YACT,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;YAC5B,OAAO;YACP,MAAM;YACN,WAAW;SACZ,CAAC,CAAA;QACF,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE;YACnC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;SAChC;IACH,CAAC;IAED,IAAI,CACF,KAAQ,EACR,KAAsC;QAEtC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;IAC3D,CAAC;IAED,KAAK,CAAC,SAAS,CACb,KAAQ,EACR,KAAsC;QAEtC,IAAI,WAAW,GAAG,KAAK,CAAA;QACvB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;YAC1C,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC,CAAA;YAC3C,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;gBACnC,WAAW,GAAG,QAAQ,CAAA;aACvB;SACF;QACD,OAAO,WAAW,CAAA;IACpB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE;YACvC,MAAM,SAAS,EAAE,CAAA;SAClB;IACH,CAAC;CACF;AA7DD,sCA6DC","sourcesContent":["import { IRunEnvironment } from '../api'\nimport { ILogger } from '../logger'\nimport {\n CoordinatorPluginEventHandler,\n InternalPlugin,\n PluginCleanup,\n CoordinatorPluginEventValues,\n CoordinatorPluginEventKey,\n CoordinatorPluginTransformEventKey,\n Operation,\n} from './types'\n\ntype HandlerRegistry = {\n [K in CoordinatorPluginEventKey]: Array<CoordinatorPluginEventHandler<K>>\n}\n\nexport class PluginManager {\n private handlers: HandlerRegistry = {\n message: [],\n 'paths:resolve': [],\n 'pickles:filter': [],\n 'pickles:order': [],\n }\n private cleanupFns: PluginCleanup[] = []\n\n private async register<K extends CoordinatorPluginEventKey>(\n event: K,\n handler: CoordinatorPluginEventHandler<K>\n ) {\n this.handlers[event].push(handler)\n }\n\n async init<OptionsType>(\n operation: Operation,\n plugin: InternalPlugin<OptionsType>,\n options: OptionsType,\n logger: ILogger,\n environment: Required<IRunEnvironment>\n ) {\n const cleanupFn = await plugin.coordinator({\n operation,\n on: this.register.bind(this),\n options,\n logger,\n environment,\n })\n if (typeof cleanupFn === 'function') {\n this.cleanupFns.push(cleanupFn)\n }\n }\n\n emit<K extends CoordinatorPluginEventKey>(\n event: K,\n value: CoordinatorPluginEventValues[K]\n ): void {\n this.handlers[event].forEach((handler) => handler(value))\n }\n\n async transform<K extends CoordinatorPluginTransformEventKey>(\n event: K,\n value: CoordinatorPluginEventValues[K]\n ): Promise<CoordinatorPluginEventValues[K]> {\n let transformed = value\n for (const handler of this.handlers[event]) {\n const returned = await handler(transformed)\n if (typeof returned !== 'undefined') {\n transformed = returned\n }\n }\n return transformed\n }\n\n async cleanup(): Promise<void> {\n for (const cleanupFn of this.cleanupFns) {\n await cleanupFn()\n }\n }\n}\n"]}
1
+ {"version":3,"file":"plugin_manager.js","sourceRoot":"","sources":["../../src/plugin/plugin_manager.ts"],"names":[],"mappings":";;;AAiBA,MAAa,aAAa;IAChB,QAAQ,GAAoB;QAClC,OAAO,EAAE,EAAE;QACX,eAAe,EAAE,EAAE;QACnB,gBAAgB,EAAE,EAAE;QACpB,eAAe,EAAE,EAAE;KACpB,CAAA;IACO,UAAU,GAAoB,EAAE,CAAA;IAEhC,KAAK,CAAC,QAAQ,CACpB,KAAQ,EACR,OAAyC;QAEzC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;IACrC,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,MAAoC,EACpC,OAAoB,EACpB,KAA4C;QAE5C,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC;YACvC,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;YACjD,OAAO;YACP,KAAK;SACN,CAAC,CAAA;QACF,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE;YACnC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;SAChC;IACH,CAAC;IAED,KAAK,CAAC,eAAe,CACnB,SAAoB,EACpB,MAAmC,EACnC,OAAoB,EACpB,MAAe,EACf,WAAsC;QAEtC,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC;YACzC,SAAS;YACT,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;YAC5B,OAAO;YACP,MAAM;YACN,WAAW;SACZ,CAAC,CAAA;QACF,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE;YACnC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;SAChC;IACH,CAAC;IAED,IAAI,CACF,KAAQ,EACR,KAAsC;QAEtC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;IAC3D,CAAC;IAED,KAAK,CAAC,SAAS,CACb,KAAQ,EACR,KAAsC;QAEtC,IAAI,WAAW,GAAG,KAAK,CAAA;QACvB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;YAC1C,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC,CAAA;YAC3C,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;gBACnC,WAAW,GAAG,QAAQ,CAAA;aACvB;SACF;QACD,OAAO,WAAW,CAAA;IACpB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE;YACvC,MAAM,SAAS,EAAE,CAAA;SAClB;IACH,CAAC;CACF;AA5ED,sCA4EC","sourcesContent":["import { IRunEnvironment } from '../api'\nimport { ILogger } from '../logger'\nimport {\n CoordinatorPluginEventHandler,\n InternalPlugin,\n PluginCleanup,\n CoordinatorPluginEventValues,\n CoordinatorPluginEventKey,\n CoordinatorPluginTransformEventKey,\n Operation,\n FormatterPlugin,\n} from './types'\n\ntype HandlerRegistry = {\n [K in CoordinatorPluginEventKey]: Array<CoordinatorPluginEventHandler<K>>\n}\n\nexport class PluginManager {\n private handlers: HandlerRegistry = {\n message: [],\n 'paths:resolve': [],\n 'pickles:filter': [],\n 'pickles:order': [],\n }\n private cleanupFns: PluginCleanup[] = []\n\n private async register<K extends CoordinatorPluginEventKey>(\n event: K,\n handler: CoordinatorPluginEventHandler<K>\n ) {\n this.handlers[event]?.push(handler)\n }\n\n async initFormatter<OptionsType>(\n plugin: FormatterPlugin<OptionsType>,\n options: OptionsType,\n write: (buffer: string | Uint8Array) => void\n ) {\n const cleanupFn = await plugin.formatter({\n on: (key, handler) => this.register(key, handler),\n options,\n write,\n })\n if (typeof cleanupFn === 'function') {\n this.cleanupFns.push(cleanupFn)\n }\n }\n\n async initCoordinator<OptionsType>(\n operation: Operation,\n plugin: InternalPlugin<OptionsType>,\n options: OptionsType,\n logger: ILogger,\n environment: Required<IRunEnvironment>\n ) {\n const cleanupFn = await plugin.coordinator({\n operation,\n on: this.register.bind(this),\n options,\n logger,\n environment,\n })\n if (typeof cleanupFn === 'function') {\n this.cleanupFns.push(cleanupFn)\n }\n }\n\n emit<K extends CoordinatorPluginEventKey>(\n event: K,\n value: CoordinatorPluginEventValues[K]\n ): void {\n this.handlers[event].forEach((handler) => handler(value))\n }\n\n async transform<K extends CoordinatorPluginTransformEventKey>(\n event: K,\n value: CoordinatorPluginEventValues[K]\n ): Promise<CoordinatorPluginEventValues[K]> {\n let transformed = value\n for (const handler of this.handlers[event]) {\n const returned = await handler(transformed)\n if (typeof returned !== 'undefined') {\n transformed = returned\n }\n }\n return transformed\n }\n\n async cleanup(): Promise<void> {\n for (const cleanupFn of this.cleanupFns) {\n await cleanupFn()\n }\n }\n}\n"]}
@@ -36,3 +36,14 @@ export interface InternalPlugin<OptionsType = any> {
36
36
  type: 'plugin';
37
37
  coordinator: CoordinatorPluginFunction<OptionsType>;
38
38
  }
39
+ export interface FormatterPluginContext<OptionsType> {
40
+ on: (key: 'message', handler: (value: Envelope) => void) => void;
41
+ options: OptionsType;
42
+ write: (buffer: string | Uint8Array) => void;
43
+ }
44
+ export type FormatterPluginFunction<OptionsType> = (context: FormatterPluginContext<OptionsType>) => Promisable<PluginCleanup | void>;
45
+ export interface FormatterPlugin<OptionsType = any> {
46
+ type: 'formatter';
47
+ formatter: FormatterPluginFunction<OptionsType>;
48
+ documentation: string;
49
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/plugin/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Envelope } from '@cucumber/messages'\nimport { ArrayValues, Promisable } from 'type-fest'\nimport { IRunEnvironment } from '../api'\nimport { ILogger } from '../logger'\nimport { IFilterablePickle } from '../filter'\nimport { IResolvedPaths } from '../paths'\nimport { coordinatorTransformKeys, coordinatorVoidKeys } from './events'\n\nexport type Operation = 'loadSources' | 'loadSupport' | 'runCucumber'\n\nexport type CoordinatorPluginVoidEventKey = ArrayValues<\n typeof coordinatorVoidKeys\n>\nexport type CoordinatorPluginTransformEventKey = ArrayValues<\n typeof coordinatorTransformKeys\n>\nexport type CoordinatorPluginEventKey =\n | CoordinatorPluginVoidEventKey\n | CoordinatorPluginTransformEventKey\n\nexport type CoordinatorPluginEventValues = {\n // void\n message: Readonly<Envelope>\n 'paths:resolve': Readonly<IResolvedPaths>\n // transform\n 'pickles:filter': Readonly<Array<IFilterablePickle>>\n 'pickles:order': Readonly<Array<IFilterablePickle>>\n}\n\nexport type CoordinatorPluginEventHandler<K extends CoordinatorPluginEventKey> =\n (\n value: CoordinatorPluginEventValues[K]\n ) => K extends CoordinatorPluginTransformEventKey\n ? Promisable<CoordinatorPluginEventValues[K]>\n : void\n\nexport interface CoordinatorPluginContext<OptionsType> {\n operation: Operation\n on: <EventKey extends CoordinatorPluginEventKey>(\n event: EventKey,\n handler: CoordinatorPluginEventHandler<EventKey>\n ) => void\n options: OptionsType\n logger: ILogger\n environment: Required<IRunEnvironment>\n}\n\nexport type CoordinatorPluginFunction<OptionsType> = (\n context: CoordinatorPluginContext<OptionsType>\n) => Promisable<PluginCleanup | void>\n\nexport type PluginCleanup = () => Promisable<void>\n\n/**\n * A plugin to implement Cucumber built-in functionality.\n *\n * Uses the same events and mechanisms as user-authored plugins, but is free to require configuration and context from\n * inside of Cucumber as its `options`, whereas user-authored plugins will be limited to `pluginOptions` from the\n * project configuration.\n */\nexport interface InternalPlugin<OptionsType = any> {\n type: 'plugin'\n coordinator: CoordinatorPluginFunction<OptionsType>\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/plugin/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Envelope } from '@cucumber/messages'\nimport { ArrayValues, Promisable } from 'type-fest'\nimport { IRunEnvironment } from '../api'\nimport { ILogger } from '../logger'\nimport { IFilterablePickle } from '../filter'\nimport { IResolvedPaths } from '../paths'\nimport { coordinatorTransformKeys, coordinatorVoidKeys } from './events'\n\nexport type Operation = 'loadSources' | 'loadSupport' | 'runCucumber'\n\nexport type CoordinatorPluginVoidEventKey = ArrayValues<\n typeof coordinatorVoidKeys\n>\nexport type CoordinatorPluginTransformEventKey = ArrayValues<\n typeof coordinatorTransformKeys\n>\nexport type CoordinatorPluginEventKey =\n | CoordinatorPluginVoidEventKey\n | CoordinatorPluginTransformEventKey\n\nexport type CoordinatorPluginEventValues = {\n // void\n message: Readonly<Envelope>\n 'paths:resolve': Readonly<IResolvedPaths>\n // transform\n 'pickles:filter': Readonly<Array<IFilterablePickle>>\n 'pickles:order': Readonly<Array<IFilterablePickle>>\n}\n\nexport type CoordinatorPluginEventHandler<K extends CoordinatorPluginEventKey> =\n (\n value: CoordinatorPluginEventValues[K]\n ) => K extends CoordinatorPluginTransformEventKey\n ? Promisable<CoordinatorPluginEventValues[K]>\n : void\n\nexport interface CoordinatorPluginContext<OptionsType> {\n operation: Operation\n on: <EventKey extends CoordinatorPluginEventKey>(\n event: EventKey,\n handler: CoordinatorPluginEventHandler<EventKey>\n ) => void\n options: OptionsType\n logger: ILogger\n environment: Required<IRunEnvironment>\n}\n\nexport type CoordinatorPluginFunction<OptionsType> = (\n context: CoordinatorPluginContext<OptionsType>\n) => Promisable<PluginCleanup | void>\n\nexport type PluginCleanup = () => Promisable<void>\n\n/**\n * A plugin to implement Cucumber built-in functionality.\n *\n * Uses the same events and mechanisms as user-authored plugins, but is free to require configuration and context from\n * inside of Cucumber as its `options`, whereas user-authored plugins will be limited to `pluginOptions` from the\n * project configuration.\n */\nexport interface InternalPlugin<OptionsType = any> {\n type: 'plugin'\n coordinator: CoordinatorPluginFunction<OptionsType>\n}\n\nexport interface FormatterPluginContext<OptionsType> {\n on: (key: 'message', handler: (value: Envelope) => void) => void\n options: OptionsType\n write: (buffer: string | Uint8Array) => void\n}\n\nexport type FormatterPluginFunction<OptionsType> = (\n context: FormatterPluginContext<OptionsType>\n) => Promisable<PluginCleanup | void>\n\nexport interface FormatterPlugin<OptionsType = any> {\n type: 'formatter'\n formatter: FormatterPluginFunction<OptionsType>\n documentation: string\n}\n"]}
@@ -57,7 +57,7 @@ export default class Coordinator implements IRuntime {
57
57
  awakenWorkers(triggeringWorker: IWorker): void;
58
58
  startWorker(id: string, total: number): void;
59
59
  onWorkerProcessClose(exitCode: number): void;
60
- parseTestCaseResult(testCaseFinished: messages.TestCaseFinished): void;
60
+ parseTestCaseResult(testCaseFinished: messages.TestCaseFinished, workerId: string): void;
61
61
  start(): Promise<boolean>;
62
62
  nextPicklePlacement(): IPicklePlacement;
63
63
  placementAt(index: number): IPicklePlacement;
@@ -52,8 +52,7 @@ class Coordinator {
52
52
  const envelope = message.jsonEnvelope;
53
53
  this.eventBroadcaster.emit('envelope', envelope);
54
54
  if ((0, value_checker_1.doesHaveValue)(envelope.testCaseFinished)) {
55
- delete this.inProgressPickles[worker.id];
56
- this.parseTestCaseResult(envelope.testCaseFinished);
55
+ this.parseTestCaseResult(envelope.testCaseFinished, worker.id);
57
56
  }
58
57
  }
59
58
  else {
@@ -122,11 +121,13 @@ class Coordinator {
122
121
  this.onFinish(this.success);
123
122
  }
124
123
  }
125
- parseTestCaseResult(testCaseFinished) {
124
+ parseTestCaseResult(testCaseFinished, workerId) {
126
125
  const { worstTestStepResult } = this.eventDataCollector.getTestCaseAttempt(testCaseFinished.testCaseStartedId);
127
- if (!testCaseFinished.willBeRetried &&
128
- (0, helpers_1.shouldCauseFailure)(worstTestStepResult.status, this.options)) {
129
- this.success = false;
126
+ if (!testCaseFinished.willBeRetried) {
127
+ delete this.inProgressPickles[workerId];
128
+ if ((0, helpers_1.shouldCauseFailure)(worstTestStepResult.status, this.options)) {
129
+ this.success = false;
130
+ }
130
131
  }
131
132
  }
132
133
  async start() {
@@ -1 +1 @@
1
- {"version":3,"file":"coordinator.js","sourceRoot":"","sources":["../../../src/runtime/parallel/coordinator.ts"],"names":[],"mappings":";;;;;AAAA,2DAAuD;AACvD,0DAA4B;AAI5B,wCAAiE;AAIjE,uDAAmD;AACnD,4CAAiD;AACjD,gEAA+E;AAI/E,MAAM,aAAa,GAAG,mBAAI,CAAC,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC,CAAA;AAgC9D,MAAqB,WAAW;IACb,GAAG,CAAQ;IACX,gBAAgB,CAAc;IAC9B,kBAAkB,CAAoB;IACtC,SAAS,CAAY;IAC9B,QAAQ,CAA4B;IAC3B,OAAO,CAAiB;IACxB,KAAK,CAAmB;IACxB,SAAS,CAAU;IAC5B,kBAAkB,CAAqB;IAC9B,iBAAiB,CAAiC;IAClD,OAAO,CAAyB;IAChC,kBAAkB,CAAoB;IACtC,eAAe,CAAQ;IACvB,MAAM,CAAS;IACxB,OAAO,CAAS;IAChB,iBAAiB,CAAQ;IAEjC,YAAY,EACV,GAAG,EACH,MAAM,EACN,gBAAgB,EAChB,kBAAkB,EAClB,SAAS,EACT,OAAO,EACP,KAAK,EACL,kBAAkB,EAClB,eAAe,GACQ;QACvB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;QACxC,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAA;QAC5C,IAAI,CAAC,SAAS,GAAG,IAAA,kBAAM,GAAE,CAAA;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAA;QA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QAED,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,eAAe,CAAA;QAE1D,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC,CAAA;QACzC,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,MAAM,CAAA;QAC1C,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QACnD,MAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,CAAC,kBAAkB,CAChE,MAAM,CAAC,GAAG,CACX,CAAA;QACD,MAAM,OAAO,GAAG,IAAA,0BAAgB,EAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;QACtD,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC5E,MAAM,UAAU,GAAmB;YACjC,GAAG,EAAE;gBACH,OAAO;gBACP,IAAI;gBACJ,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;gBAClC,MAAM;gBACN,QAAQ;gBACR,eAAe;aAChB;SACF,CAAA;QACD,MAAM,CAAC,KAAK,8BAAsB,CAAA;QAClC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACjC,CAAC;CACF;AAxPD,8BAwPC","sourcesContent":["import { ChildProcess, fork } from 'node:child_process'\nimport path from 'node:path'\nimport { EventEmitter } from 'node:events'\nimport * as messages from '@cucumber/messages'\nimport { IdGenerator } from '@cucumber/messages'\nimport { retriesForPickle, shouldCauseFailure } from '../helpers'\nimport { EventDataCollector } from '../../formatter/helpers'\nimport { IRuntime, IRuntimeOptions } from '..'\nimport { SupportCodeLibrary } from '../../support_code_library_builder/types'\nimport { doesHaveValue } from '../../value_checker'\nimport { IStopwatch, create } from '../stopwatch'\nimport { assembleTestCases, IAssembledTestCases } from '../assemble_test_cases'\nimport { ILogger } from '../../logger'\nimport { ICoordinatorReport, IWorkerCommand } from './command_types'\n\nconst runWorkerPath = path.resolve(__dirname, 'run_worker.js')\n\nexport interface INewCoordinatorOptions {\n cwd: string\n logger: ILogger\n eventBroadcaster: EventEmitter\n eventDataCollector: EventDataCollector\n options: IRuntimeOptions\n newId: IdGenerator.NewId\n pickleIds: string[]\n supportCodeLibrary: SupportCodeLibrary\n numberOfWorkers: number\n}\n\nconst enum WorkerState {\n 'idle',\n 'closed',\n 'running',\n 'new',\n}\n\ninterface IWorker {\n state: WorkerState\n process: ChildProcess\n id: string\n}\n\ninterface IPicklePlacement {\n index: number\n pickle: messages.Pickle\n}\n\nexport default class Coordinator implements IRuntime {\n private readonly cwd: string\n private readonly eventBroadcaster: EventEmitter\n private readonly eventDataCollector: EventDataCollector\n private readonly stopwatch: IStopwatch\n private onFinish: (success: boolean) => void\n private readonly options: IRuntimeOptions\n private readonly newId: IdGenerator.NewId\n private readonly pickleIds: string[]\n private assembledTestCases: IAssembledTestCases\n private readonly inProgressPickles: Record<string, messages.Pickle>\n private readonly workers: Record<string, IWorker>\n private readonly supportCodeLibrary: SupportCodeLibrary\n private readonly numberOfWorkers: number\n private readonly logger: ILogger\n private success: boolean\n private idleInterventions: number\n\n constructor({\n cwd,\n logger,\n eventBroadcaster,\n eventDataCollector,\n pickleIds,\n options,\n newId,\n supportCodeLibrary,\n numberOfWorkers,\n }: INewCoordinatorOptions) {\n this.cwd = cwd\n this.logger = logger\n this.eventBroadcaster = eventBroadcaster\n this.eventDataCollector = eventDataCollector\n this.stopwatch = create()\n this.options = options\n this.newId = newId\n this.supportCodeLibrary = supportCodeLibrary\n this.pickleIds = Array.from(pickleIds)\n this.numberOfWorkers = numberOfWorkers\n this.success = true\n this.workers = {}\n this.inProgressPickles = {}\n this.idleInterventions = 0\n }\n\n parseWorkerMessage(worker: IWorker, message: ICoordinatorReport): void {\n if (message.ready) {\n worker.state = WorkerState.idle\n this.awakenWorkers(worker)\n } else if (doesHaveValue(message.jsonEnvelope)) {\n const envelope = message.jsonEnvelope\n this.eventBroadcaster.emit('envelope', envelope)\n if (doesHaveValue(envelope.testCaseFinished)) {\n delete this.inProgressPickles[worker.id]\n this.parseTestCaseResult(envelope.testCaseFinished)\n }\n } else {\n throw new Error(\n `Unexpected message from worker: ${JSON.stringify(message)}`\n )\n }\n }\n\n awakenWorkers(triggeringWorker: IWorker): 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 (\n Object.keys(this.inProgressPickles).length == 0 &&\n this.pickleIds.length > 0\n ) {\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.cwd,\n env: {\n ...process.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: ICoordinatorReport) => {\n this.parseWorkerMessage(worker, message)\n })\n worker.process.on('close', (exitCode) => {\n worker.state = WorkerState.closed\n this.onWorkerProcessClose(exitCode)\n })\n const initializeCommand: IWorkerCommand = {\n 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(\n (h) => h.id\n ),\n },\n options: this.options,\n },\n }\n worker.process.send(initializeCommand)\n }\n\n onWorkerProcessClose(exitCode: number): void {\n const success = exitCode === 0\n if (!success) {\n this.success = false\n }\n\n if (\n Object.values(this.workers).every((x) => x.state === WorkerState.closed)\n ) {\n const envelope: messages.Envelope = {\n testRunFinished: {\n timestamp: this.stopwatch.timestamp(),\n success,\n },\n }\n this.eventBroadcaster.emit('envelope', envelope)\n this.onFinish(this.success)\n }\n }\n\n parseTestCaseResult(testCaseFinished: messages.TestCaseFinished): void {\n const { worstTestStepResult } = this.eventDataCollector.getTestCaseAttempt(\n testCaseFinished.testCaseStartedId\n )\n if (\n !testCaseFinished.willBeRetried &&\n shouldCauseFailure(worstTestStepResult.status, this.options)\n ) {\n this.success = false\n }\n }\n\n async start(): Promise<boolean> {\n const envelope: messages.Envelope = {\n testRunStarted: {\n timestamp: this.stopwatch.timestamp(),\n },\n }\n this.eventBroadcaster.emit('envelope', envelope)\n this.stopwatch.start()\n this.assembledTestCases = await assembleTestCases({\n eventBroadcaster: this.eventBroadcaster,\n newId: this.newId,\n pickles: this.pickleIds.map((pickleId) =>\n this.eventDataCollector.getPickle(pickleId)\n ),\n supportCodeLibrary: this.supportCodeLibrary,\n })\n return await new Promise<boolean>((resolve) => {\n for (let i = 0; i < this.numberOfWorkers; i++) {\n this.startWorker(i.toString(), this.numberOfWorkers)\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 nextPicklePlacement(): IPicklePlacement {\n for (let index = 0; index < this.pickleIds.length; index++) {\n const placement = this.placementAt(index)\n if (\n this.supportCodeLibrary.parallelCanAssign(\n placement.pickle,\n Object.values(this.inProgressPickles)\n )\n ) {\n return placement\n }\n }\n\n return null\n }\n\n placementAt(index: number): IPicklePlacement {\n return {\n index,\n pickle: this.eventDataCollector.getPickle(this.pickleIds[index]),\n }\n }\n\n giveWork(worker: IWorker, force: boolean = false): void {\n if (this.pickleIds.length < 1) {\n const finalizeCommand: IWorkerCommand = { finalize: true }\n worker.state = WorkerState.running\n worker.process.send(finalizeCommand)\n return\n }\n\n const picklePlacement = force\n ? this.placementAt(0)\n : this.nextPicklePlacement()\n\n if (picklePlacement === null) {\n return\n }\n\n const { index: nextPickleIndex, pickle } = picklePlacement\n\n this.pickleIds.splice(nextPickleIndex, 1)\n this.inProgressPickles[worker.id] = pickle\n const testCase = this.assembledTestCases[pickle.id]\n const gherkinDocument = this.eventDataCollector.getGherkinDocument(\n pickle.uri\n )\n const retries = retriesForPickle(pickle, this.options)\n const skip = this.options.dryRun || (this.options.failFast && !this.success)\n const runCommand: IWorkerCommand = {\n run: {\n retries,\n skip,\n elapsed: this.stopwatch.duration(),\n pickle,\n testCase,\n gherkinDocument,\n },\n }\n worker.state = WorkerState.running\n worker.process.send(runCommand)\n }\n}\n"]}
1
+ {"version":3,"file":"coordinator.js","sourceRoot":"","sources":["../../../src/runtime/parallel/coordinator.ts"],"names":[],"mappings":";;;;;AAAA,2DAAuD;AACvD,0DAA4B;AAI5B,wCAAiE;AAIjE,uDAAmD;AACnD,4CAAiD;AACjD,gEAA+E;AAI/E,MAAM,aAAa,GAAG,mBAAI,CAAC,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC,CAAA;AAgC9D,MAAqB,WAAW;IACb,GAAG,CAAQ;IACX,gBAAgB,CAAc;IAC9B,kBAAkB,CAAoB;IACtC,SAAS,CAAY;IAC9B,QAAQ,CAA4B;IAC3B,OAAO,CAAiB;IACxB,KAAK,CAAmB;IACxB,SAAS,CAAU;IAC5B,kBAAkB,CAAqB;IAC9B,iBAAiB,CAAiC;IAClD,OAAO,CAAyB;IAChC,kBAAkB,CAAoB;IACtC,eAAe,CAAQ;IACvB,MAAM,CAAS;IACxB,OAAO,CAAS;IAChB,iBAAiB,CAAQ;IAEjC,YAAY,EACV,GAAG,EACH,MAAM,EACN,gBAAgB,EAChB,kBAAkB,EAClB,SAAS,EACT,OAAO,EACP,KAAK,E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B;SACF,CAAA;QACD,MAAM,CAAC,KAAK,8BAAsB,CAAA;QAClC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACjC,CAAC;CACF;AA3PD,8BA2PC","sourcesContent":["import { ChildProcess, fork } from 'node:child_process'\nimport path from 'node:path'\nimport { EventEmitter } from 'node:events'\nimport * as messages from '@cucumber/messages'\nimport { IdGenerator } from '@cucumber/messages'\nimport { retriesForPickle, shouldCauseFailure } from '../helpers'\nimport { EventDataCollector } from '../../formatter/helpers'\nimport { IRuntime, IRuntimeOptions } from '..'\nimport { SupportCodeLibrary } from '../../support_code_library_builder/types'\nimport { doesHaveValue } from '../../value_checker'\nimport { IStopwatch, create } from '../stopwatch'\nimport { assembleTestCases, IAssembledTestCases } from '../assemble_test_cases'\nimport { ILogger } from '../../logger'\nimport { ICoordinatorReport, IWorkerCommand } from './command_types'\n\nconst runWorkerPath = path.resolve(__dirname, 'run_worker.js')\n\nexport interface INewCoordinatorOptions {\n cwd: string\n logger: ILogger\n eventBroadcaster: EventEmitter\n eventDataCollector: EventDataCollector\n options: IRuntimeOptions\n newId: IdGenerator.NewId\n pickleIds: string[]\n supportCodeLibrary: SupportCodeLibrary\n numberOfWorkers: number\n}\n\nconst enum WorkerState {\n 'idle',\n 'closed',\n 'running',\n 'new',\n}\n\ninterface IWorker {\n state: WorkerState\n process: ChildProcess\n id: string\n}\n\ninterface IPicklePlacement {\n index: number\n pickle: messages.Pickle\n}\n\nexport default class Coordinator implements IRuntime {\n private readonly cwd: string\n private readonly eventBroadcaster: EventEmitter\n private readonly eventDataCollector: EventDataCollector\n private readonly stopwatch: IStopwatch\n private onFinish: (success: boolean) => void\n private readonly options: IRuntimeOptions\n private readonly newId: IdGenerator.NewId\n private readonly pickleIds: string[]\n private assembledTestCases: IAssembledTestCases\n private readonly inProgressPickles: Record<string, messages.Pickle>\n private readonly workers: Record<string, IWorker>\n private readonly supportCodeLibrary: SupportCodeLibrary\n private readonly numberOfWorkers: number\n private readonly logger: ILogger\n private success: boolean\n private idleInterventions: number\n\n constructor({\n cwd,\n logger,\n eventBroadcaster,\n eventDataCollector,\n pickleIds,\n options,\n newId,\n supportCodeLibrary,\n numberOfWorkers,\n }: INewCoordinatorOptions) {\n this.cwd = cwd\n this.logger = logger\n this.eventBroadcaster = eventBroadcaster\n this.eventDataCollector = eventDataCollector\n this.stopwatch = create()\n this.options = options\n this.newId = newId\n this.supportCodeLibrary = supportCodeLibrary\n this.pickleIds = Array.from(pickleIds)\n this.numberOfWorkers = numberOfWorkers\n this.success = true\n this.workers = {}\n this.inProgressPickles = {}\n this.idleInterventions = 0\n }\n\n parseWorkerMessage(worker: IWorker, message: ICoordinatorReport): void {\n if (message.ready) {\n worker.state = WorkerState.idle\n this.awakenWorkers(worker)\n } else if (doesHaveValue(message.jsonEnvelope)) {\n const envelope = message.jsonEnvelope\n this.eventBroadcaster.emit('envelope', envelope)\n if (doesHaveValue(envelope.testCaseFinished)) {\n this.parseTestCaseResult(envelope.testCaseFinished, worker.id)\n }\n } else {\n throw new Error(\n `Unexpected message from worker: ${JSON.stringify(message)}`\n )\n }\n }\n\n awakenWorkers(triggeringWorker: IWorker): 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 (\n Object.keys(this.inProgressPickles).length == 0 &&\n this.pickleIds.length > 0\n ) {\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.cwd,\n env: {\n ...process.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: ICoordinatorReport) => {\n this.parseWorkerMessage(worker, message)\n })\n worker.process.on('close', (exitCode) => {\n worker.state = WorkerState.closed\n this.onWorkerProcessClose(exitCode)\n })\n const initializeCommand: IWorkerCommand = {\n 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(\n (h) => h.id\n ),\n },\n options: this.options,\n },\n }\n worker.process.send(initializeCommand)\n }\n\n onWorkerProcessClose(exitCode: number): void {\n const success = exitCode === 0\n if (!success) {\n this.success = false\n }\n\n if (\n Object.values(this.workers).every((x) => x.state === WorkerState.closed)\n ) {\n const envelope: messages.Envelope = {\n testRunFinished: {\n timestamp: this.stopwatch.timestamp(),\n success,\n },\n }\n this.eventBroadcaster.emit('envelope', envelope)\n this.onFinish(this.success)\n }\n }\n\n parseTestCaseResult(\n testCaseFinished: messages.TestCaseFinished,\n workerId: string\n ): void {\n const { worstTestStepResult } = this.eventDataCollector.getTestCaseAttempt(\n testCaseFinished.testCaseStartedId\n )\n if (!testCaseFinished.willBeRetried) {\n delete this.inProgressPickles[workerId]\n\n if (shouldCauseFailure(worstTestStepResult.status, this.options)) {\n this.success = false\n }\n }\n }\n\n async start(): Promise<boolean> {\n const envelope: messages.Envelope = {\n testRunStarted: {\n timestamp: this.stopwatch.timestamp(),\n },\n }\n this.eventBroadcaster.emit('envelope', envelope)\n this.stopwatch.start()\n this.assembledTestCases = await assembleTestCases({\n eventBroadcaster: this.eventBroadcaster,\n newId: this.newId,\n pickles: this.pickleIds.map((pickleId) =>\n this.eventDataCollector.getPickle(pickleId)\n ),\n supportCodeLibrary: this.supportCodeLibrary,\n })\n return await new Promise<boolean>((resolve) => {\n for (let i = 0; i < this.numberOfWorkers; i++) {\n this.startWorker(i.toString(), this.numberOfWorkers)\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 nextPicklePlacement(): IPicklePlacement {\n for (let index = 0; index < this.pickleIds.length; index++) {\n const placement = this.placementAt(index)\n if (\n this.supportCodeLibrary.parallelCanAssign(\n placement.pickle,\n Object.values(this.inProgressPickles)\n )\n ) {\n return placement\n }\n }\n\n return null\n }\n\n placementAt(index: number): IPicklePlacement {\n return {\n index,\n pickle: this.eventDataCollector.getPickle(this.pickleIds[index]),\n }\n }\n\n giveWork(worker: IWorker, force: boolean = false): void {\n if (this.pickleIds.length < 1) {\n const finalizeCommand: IWorkerCommand = { finalize: true }\n worker.state = WorkerState.running\n worker.process.send(finalizeCommand)\n return\n }\n\n const picklePlacement = force\n ? this.placementAt(0)\n : this.nextPicklePlacement()\n\n if (picklePlacement === null) {\n return\n }\n\n const { index: nextPickleIndex, pickle } = picklePlacement\n\n this.pickleIds.splice(nextPickleIndex, 1)\n this.inProgressPickles[worker.id] = pickle\n const testCase = this.assembledTestCases[pickle.id]\n const gherkinDocument = this.eventDataCollector.getGherkinDocument(\n pickle.uri\n )\n const retries = retriesForPickle(pickle, this.options)\n const skip = this.options.dryRun || (this.options.failFast && !this.success)\n const runCommand: IWorkerCommand = {\n run: {\n retries,\n skip,\n elapsed: this.stopwatch.duration(),\n pickle,\n testCase,\n gherkinDocument,\n },\n }\n worker.state = WorkerState.running\n worker.process.send(runCommand)\n }\n}\n"]}
@@ -7,16 +7,18 @@ exports.makeRunTestRunHooks = void 0;
7
7
  const user_code_runner_1 = __importDefault(require("../user_code_runner"));
8
8
  const helpers_1 = require("../formatter/helpers");
9
9
  const value_checker_1 = require("../value_checker");
10
+ const scope_1 = require("./scope");
10
11
  const makeRunTestRunHooks = (dryRun, defaultTimeout, worldParameters, errorMessage) => dryRun
11
12
  ? async () => { }
12
13
  : async (definitions, name) => {
14
+ const context = { parameters: worldParameters };
13
15
  for (const hookDefinition of definitions) {
14
- const { error } = await user_code_runner_1.default.run({
16
+ const { error } = await (0, scope_1.runInTestRunScope)({ context }, () => user_code_runner_1.default.run({
15
17
  argsArray: [],
16
18
  fn: hookDefinition.code,
17
- thisArg: { parameters: worldParameters },
19
+ thisArg: context,
18
20
  timeoutInMilliseconds: (0, value_checker_1.valueOrDefault)(hookDefinition.options.timeout, defaultTimeout),
19
- });
21
+ }));
20
22
  if ((0, value_checker_1.doesHaveValue)(error)) {
21
23
  const location = (0, helpers_1.formatLocation)(hookDefinition);
22
24
  throw new Error(errorMessage(name, location), { cause: error });
@@ -1 +1 @@
1
- {"version":3,"file":"run_test_run_hooks.js","sourceRoot":"","sources":["../../src/runtime/run_test_run_hooks.ts"],"names":[],"mappings":";;;;;;AACA,2EAAgD;AAChD,kDAAqD;AACrD,oDAAgE;AAQzD,MAAM,mBAAmB,GAAG,CACjC,MAAe,EACf,cAAsB,EACtB,eAA2B,EAC3B,YAAwD,EACtC,EAAE,CACpB,MAAM;IACJ,CAAC,CAAC,KAAK,IAAI,EAAE,GAAE,CAAC;IAChB,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE;QAC1B,KAAK,MAAM,cAAc,IAAI,WAAW,EAAE;YACxC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,0BAAc,CAAC,GAAG,CAAC;gBACzC,SAAS,EAAE,EAAE;gBACb,EAAE,EAAE,cAAc,CAAC,IAAI;gBACvB,OAAO,EAAE,EAAE,UAAU,EAAE,eAAe,EAAE;gBACxC,qBAAqB,EAAE,IAAA,8BAAc,EACnC,cAAc,CAAC,OAAO,CAAC,OAAO,EAC9B,cAAc,CACf;aACF,CAAC,CAAA;YACF,IAAI,IAAA,6BAAa,EAAC,KAAK,CAAC,EAAE;gBACxB,MAAM,QAAQ,GAAG,IAAA,wBAAc,EAAC,cAAc,CAAC,CAAA;gBAC/C,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;aAChE;SACF;IACH,CAAC,CAAA;AAxBM,QAAA,mBAAmB,uBAwBzB","sourcesContent":["import { JsonObject } from 'type-fest'\nimport UserCodeRunner from '../user_code_runner'\nimport { formatLocation } from '../formatter/helpers'\nimport { doesHaveValue, valueOrDefault } from '../value_checker'\nimport TestRunHookDefinition from '../models/test_run_hook_definition'\n\nexport type RunsTestRunHooks = (\n definitions: TestRunHookDefinition[],\n name: string\n) => Promise<void>\n\nexport const makeRunTestRunHooks = (\n dryRun: boolean,\n defaultTimeout: number,\n worldParameters: JsonObject,\n errorMessage: (name: string, location: string) => string\n): RunsTestRunHooks =>\n dryRun\n ? async () => {}\n : async (definitions, name) => {\n for (const hookDefinition of definitions) {\n const { error } = await UserCodeRunner.run({\n argsArray: [],\n fn: hookDefinition.code,\n thisArg: { parameters: worldParameters },\n timeoutInMilliseconds: valueOrDefault(\n hookDefinition.options.timeout,\n defaultTimeout\n ),\n })\n if (doesHaveValue(error)) {\n const location = formatLocation(hookDefinition)\n throw new Error(errorMessage(name, location), { cause: error })\n }\n }\n }\n"]}
1
+ {"version":3,"file":"run_test_run_hooks.js","sourceRoot":"","sources":["../../src/runtime/run_test_run_hooks.ts"],"names":[],"mappings":";;;;;;AACA,2EAAgD;AAChD,kDAAqD;AACrD,oDAAgE;AAEhE,mCAA2C;AAOpC,MAAM,mBAAmB,GAAG,CACjC,MAAe,EACf,cAAsB,EACtB,eAA2B,EAC3B,YAAwD,EACtC,EAAE,CACpB,MAAM;IACJ,CAAC,CAAC,KAAK,IAAI,EAAE,GAAE,CAAC;IAChB,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE;QAC1B,MAAM,OAAO,GAAG,EAAE,UAAU,EAAE,eAAe,EAAE,CAAA;QAC/C,KAAK,MAAM,cAAc,IAAI,WAAW,EAAE;YACxC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAA,yBAAiB,EAAC,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,CAC1D,0BAAc,CAAC,GAAG,CAAC;gBACjB,SAAS,EAAE,EAAE;gBACb,EAAE,EAAE,cAAc,CAAC,IAAI;gBACvB,OAAO,EAAE,OAAO;gBAChB,qBAAqB,EAAE,IAAA,8BAAc,EACnC,cAAc,CAAC,OAAO,CAAC,OAAO,EAC9B,cAAc,CACf;aACF,CAAC,CACH,CAAA;YACD,IAAI,IAAA,6BAAa,EAAC,KAAK,CAAC,EAAE;gBACxB,MAAM,QAAQ,GAAG,IAAA,wBAAc,EAAC,cAAc,CAAC,CAAA;gBAC/C,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;aAChE;SACF;IACH,CAAC,CAAA;AA3BM,QAAA,mBAAmB,uBA2BzB","sourcesContent":["import { JsonObject } from 'type-fest'\nimport UserCodeRunner from '../user_code_runner'\nimport { formatLocation } from '../formatter/helpers'\nimport { doesHaveValue, valueOrDefault } from '../value_checker'\nimport TestRunHookDefinition from '../models/test_run_hook_definition'\nimport { runInTestRunScope } from './scope'\n\nexport type RunsTestRunHooks = (\n definitions: TestRunHookDefinition[],\n name: string\n) => Promise<void>\n\nexport const makeRunTestRunHooks = (\n dryRun: boolean,\n defaultTimeout: number,\n worldParameters: JsonObject,\n errorMessage: (name: string, location: string) => string\n): RunsTestRunHooks =>\n dryRun\n ? async () => {}\n : async (definitions, name) => {\n const context = { parameters: worldParameters }\n for (const hookDefinition of definitions) {\n const { error } = await runInTestRunScope({ context }, () =>\n UserCodeRunner.run({\n argsArray: [],\n fn: hookDefinition.code,\n thisArg: context,\n timeoutInMilliseconds: valueOrDefault(\n hookDefinition.options.timeout,\n defaultTimeout\n ),\n })\n )\n if (doesHaveValue(error)) {\n const location = formatLocation(hookDefinition)\n throw new Error(errorMessage(name, location), { cause: error })\n }\n }\n }\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './test_case_scope';
2
+ export * from './test_run_scope';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./test_case_scope"), exports);
18
+ __exportStar(require("./test_run_scope"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/runtime/scope/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,mDAAgC","sourcesContent":["export * from './test_case_scope'\nexport * from './test_run_scope'\n"]}
@@ -0,0 +1 @@
1
+ export declare function makeProxy<T>(getThing: () => any): T;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeProxy = void 0;
4
+ function makeProxy(getThing) {
5
+ return new Proxy({}, {
6
+ defineProperty(_, property, attributes) {
7
+ return Reflect.defineProperty(getThing(), property, attributes);
8
+ },
9
+ deleteProperty(_, property) {
10
+ return Reflect.get(getThing(), property);
11
+ },
12
+ get(_, property) {
13
+ return Reflect.get(getThing(), property, getThing());
14
+ },
15
+ getOwnPropertyDescriptor(_, property) {
16
+ return Reflect.getOwnPropertyDescriptor(getThing(), property);
17
+ },
18
+ getPrototypeOf(_) {
19
+ return Reflect.getPrototypeOf(getThing());
20
+ },
21
+ has(_, key) {
22
+ return Reflect.has(getThing(), key);
23
+ },
24
+ isExtensible(_) {
25
+ return Reflect.isExtensible(getThing());
26
+ },
27
+ ownKeys(_) {
28
+ return Reflect.ownKeys(getThing());
29
+ },
30
+ preventExtensions(_) {
31
+ return Reflect.preventExtensions(getThing());
32
+ },
33
+ set(_, property, value) {
34
+ return Reflect.set(getThing(), property, value, getThing());
35
+ },
36
+ setPrototypeOf(_, proto) {
37
+ return Reflect.setPrototypeOf(getThing(), proto);
38
+ },
39
+ });
40
+ }
41
+ exports.makeProxy = makeProxy;
42
+ //# sourceMappingURL=make_proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"make_proxy.js","sourceRoot":"","sources":["../../../src/runtime/scope/make_proxy.ts"],"names":[],"mappings":";;;AAAA,SAAgB,SAAS,CAAI,QAAmB;IAC9C,OAAO,IAAI,KAAK,CACd,EAAE,EACF;QACE,cAAc,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU;YACpC,OAAO,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAA;QACjE,CAAC;QACD,cAAc,CAAC,CAAC,EAAE,QAAQ;YACxB,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAAA;QAC1C,CAAC;QACD,GAAG,CAAC,CAAC,EAAE,QAAQ;YACb,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAA;QACtD,CAAC;QACD,wBAAwB,CAAC,CAAC,EAAE,QAAQ;YAClC,OAAO,OAAO,CAAC,wBAAwB,CAAC,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAAA;QAC/D,CAAC;QACD,cAAc,CAAC,CAAC;YACd,OAAO,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC3C,CAAC;QACD,GAAG,CAAC,CAAC,EAAE,GAAG;YACR,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,GAAG,CAAC,CAAA;QACrC,CAAC;QACD,YAAY,CAAC,CAAC;YACZ,OAAO,OAAO,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAA;QACzC,CAAC;QACD,OAAO,CAAC,CAAC;YACP,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;QACpC,CAAC;QACD,iBAAiB,CAAC,CAAC;YACjB,OAAO,OAAO,CAAC,iBAAiB,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC9C,CAAC;QACD,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK;YACpB,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAA;QAC7D,CAAC;QACD,cAAc,CAAC,CAAC,EAAE,KAAK;YACrB,OAAO,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,EAAE,KAAK,CAAC,CAAA;QAClD,CAAC;KACF,CACG,CAAA;AACR,CAAC;AAvCD,8BAuCC","sourcesContent":["export function makeProxy<T>(getThing: () => any): T {\n return new Proxy(\n {},\n {\n defineProperty(_, property, attributes) {\n return Reflect.defineProperty(getThing(), property, attributes)\n },\n deleteProperty(_, property) {\n return Reflect.get(getThing(), property)\n },\n get(_, property) {\n return Reflect.get(getThing(), property, getThing())\n },\n getOwnPropertyDescriptor(_, property) {\n return Reflect.getOwnPropertyDescriptor(getThing(), property)\n },\n getPrototypeOf(_) {\n return Reflect.getPrototypeOf(getThing())\n },\n has(_, key) {\n return Reflect.has(getThing(), key)\n },\n isExtensible(_) {\n return Reflect.isExtensible(getThing())\n },\n ownKeys(_) {\n return Reflect.ownKeys(getThing())\n },\n preventExtensions(_) {\n return Reflect.preventExtensions(getThing())\n },\n set(_, property, value) {\n return Reflect.set(getThing(), property, value, getThing())\n },\n setPrototypeOf(_, proto) {\n return Reflect.setPrototypeOf(getThing(), proto)\n },\n }\n ) as T\n}\n"]}