@cucumber/cucumber 12.3.0 → 12.5.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 (52) hide show
  1. package/README.md +2 -0
  2. package/lib/api/convert_configuration.js +4 -0
  3. package/lib/api/convert_configuration.js.map +1 -1
  4. package/lib/api/index.d.ts +4 -2
  5. package/lib/api/index.js.map +1 -1
  6. package/lib/api/plugins.d.ts +1 -1
  7. package/lib/api/plugins.js +51 -2
  8. package/lib/api/plugins.js.map +1 -1
  9. package/lib/api/types.d.ts +25 -0
  10. package/lib/api/types.js.map +1 -1
  11. package/lib/configuration/argv_parser.d.ts +2 -0
  12. package/lib/configuration/argv_parser.js +2 -0
  13. package/lib/configuration/argv_parser.js.map +1 -1
  14. package/lib/configuration/default_configuration.js +2 -0
  15. package/lib/configuration/default_configuration.js.map +1 -1
  16. package/lib/configuration/from_file.js +66 -37
  17. package/lib/configuration/from_file.js.map +1 -1
  18. package/lib/configuration/types.d.ts +20 -0
  19. package/lib/configuration/types.js.map +1 -1
  20. package/lib/environment/console_logger.d.ts +1 -0
  21. package/lib/environment/console_logger.js +3 -0
  22. package/lib/environment/console_logger.js.map +1 -1
  23. package/lib/environment/types.d.ts +7 -0
  24. package/lib/environment/types.js.map +1 -1
  25. package/lib/filter/filter_plugin.d.ts +2 -3
  26. package/lib/filter/filter_plugin.js +3 -3
  27. package/lib/filter/filter_plugin.js.map +1 -1
  28. package/lib/filter/types.d.ts +4 -0
  29. package/lib/filter/types.js.map +1 -1
  30. package/lib/formatter/helpers/event_data_collector.js +0 -1
  31. package/lib/formatter/helpers/event_data_collector.js.map +1 -1
  32. package/lib/paths/types.d.ts +7 -0
  33. package/lib/paths/types.js.map +1 -1
  34. package/lib/plugin/plugin_manager.d.ts +9 -7
  35. package/lib/plugin/plugin_manager.js +67 -16
  36. package/lib/plugin/plugin_manager.js.map +1 -1
  37. package/lib/plugin/types.d.ts +120 -32
  38. package/lib/plugin/types.js.map +1 -1
  39. package/lib/publish/publish_plugin.d.ts +2 -3
  40. package/lib/publish/publish_plugin.js +18 -12
  41. package/lib/publish/publish_plugin.js.map +1 -1
  42. package/lib/sharding/sharding_plugin.d.ts +2 -3
  43. package/lib/sharding/sharding_plugin.js +2 -2
  44. package/lib/sharding/sharding_plugin.js.map +1 -1
  45. package/lib/tsconfig.node.tsbuildinfo +1 -1
  46. package/lib/version.d.ts +1 -1
  47. package/lib/version.js +1 -1
  48. package/lib/version.js.map +1 -1
  49. package/package.json +8 -8
  50. package/lib/plugin/events.d.ts +0 -2
  51. package/lib/plugin/events.js +0 -9
  52. package/lib/plugin/events.js.map +0 -1
package/README.md CHANGED
@@ -113,9 +113,11 @@ The following documentation is for `main`, which might contain some unreleased f
113
113
  * [Filtering which scenarios run](./docs/filtering.md)
114
114
  * [Formatters for feedback and reporting](./docs/formatters.md)
115
115
  * [Parallel running for speed](./docs/parallel.md)
116
+ * [Plugins for extending functionality](./docs/plugins.md)
116
117
  * [Profiles for composable configuration](./docs/profiles.md)
117
118
  * [Rerunning just failures](./docs/rerun.md)
118
119
  * [Retrying flaky scenarios](./docs/retry.md)
120
+ * [Sharding to split tests across machines](./docs/sharding.md)
119
121
  * [JavaScript API for running programmatically](./docs/javascript_api.md)
120
122
  * [Snippets for undefined steps](./docs/snippets.md)
121
123
  * [Transpiling (from TypeScript etc)](./docs/transpiling.md)
@@ -29,6 +29,10 @@ async function convertConfiguration(logger, flatConfiguration, env) {
29
29
  worldParameters: flatConfiguration.worldParameters,
30
30
  },
31
31
  formats: convertFormats(logger, flatConfiguration, env),
32
+ plugins: {
33
+ specifiers: flatConfiguration.plugin,
34
+ options: flatConfiguration.pluginOptions,
35
+ },
32
36
  };
33
37
  }
34
38
  function convertFormats(logger, flatConfiguration, env) {
@@ -1 +1 @@
1
- {"version":3,"file":"convert_configuration.js","sourceRoot":"","sources":["../../src/api/convert_configuration.ts"],"names":[],"mappings":";;AASA,oDAgCC;AAzCD,oDAIyB;AAKlB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D,OAAO;QACL,MAAM,EACJ,CAAC,GAAG,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;YAC9D,UAAU;QACZ,KAAK,EAAE,YAAY;aAChB,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;aAChC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE;YACjC,OAAO;gBACL,GAAG,MAAM;gBACT,CAAC,MAAM,CAAC,EAAE,IAAI;aACf,CAAA;QACH,CAAC,EAAE,EAAE,CAAC;QACR,OAAO,EAAE,iBAAiB,CAAC,iBAAiB,EAAE,GAAG,CAAC;QAClD,OAAO,EAAE,iBAAiB,CAAC,aAAa;KACzC,CAAA;AACH,CAAC;AAED,SAAS,iBAAiB,CACxB,iBAAiC,EACjC,GAAsB;IAEtB,MAAM,OAAO,GAAG,YAAY,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAA;IACpD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,KAAK,CAAA;IACd,CAAC;IACD,OAAO;QACL,GAAG,EAAE,GAAG,CAAC,oBAAoB;QAC7B,KAAK,EAAE,GAAG,CAAC,sBAAsB;KAClC,CAAA;AACH,CAAC;AAED,SAAS,YAAY,CACnB,iBAAiC,EACjC,GAAsB;IAEtB,OAAO,CACL,iBAAiB,CAAC,OAAO;QACzB,IAAA,8BAAc,EAAC,GAAG,CAAC,wBAAwB,CAAC;QAC5C,GAAG,CAAC,sBAAsB,KAAK,SAAS,CACzC,CAAA;AACH,CAAC","sourcesContent":["import {\n IConfiguration,\n isTruthyString,\n splitFormatDescriptor,\n} from '../configuration'\nimport { IPublishConfig } from '../publish'\nimport { ILogger } from '../environment'\nimport { IRunConfiguration } from './types'\n\nexport async function convertConfiguration(\n logger: ILogger,\n flatConfiguration: IConfiguration,\n env: NodeJS.ProcessEnv\n): Promise<IRunConfiguration> {\n return {\n sources: {\n paths: flatConfiguration.paths,\n defaultDialect: flatConfiguration.language,\n names: flatConfiguration.name,\n tagExpression: flatConfiguration.tags,\n order: flatConfiguration.order,\n shard: flatConfiguration.shard,\n },\n support: {\n requireModules: flatConfiguration.requireModule,\n requirePaths: flatConfiguration.require,\n importPaths: flatConfiguration.import,\n loaders: flatConfiguration.loader,\n },\n runtime: {\n dryRun: flatConfiguration.dryRun,\n failFast: flatConfiguration.failFast,\n filterStacktraces: !flatConfiguration.backtrace,\n parallel: flatConfiguration.parallel,\n retry: flatConfiguration.retry,\n retryTagFilter: flatConfiguration.retryTagFilter,\n strict: flatConfiguration.strict,\n worldParameters: flatConfiguration.worldParameters,\n },\n formats: convertFormats(logger, flatConfiguration, env),\n }\n}\n\nfunction convertFormats(\n logger: ILogger,\n flatConfiguration: IConfiguration,\n env: NodeJS.ProcessEnv\n) {\n const splitFormats: string[][] = flatConfiguration.format.map((item) =>\n Array.isArray(item) ? item : splitFormatDescriptor(logger, item)\n )\n return {\n stdout:\n [...splitFormats].reverse().find(([, target]) => !target)?.[0] ??\n 'progress',\n files: splitFormats\n .filter(([, target]) => !!target)\n .reduce((mapped, [type, target]) => {\n return {\n ...mapped,\n [target]: type,\n }\n }, {}),\n publish: makePublishConfig(flatConfiguration, env),\n options: flatConfiguration.formatOptions,\n }\n}\n\nfunction makePublishConfig(\n flatConfiguration: IConfiguration,\n env: NodeJS.ProcessEnv\n): IPublishConfig | false {\n const enabled = isPublishing(flatConfiguration, env)\n if (!enabled) {\n return false\n }\n return {\n url: env.CUCUMBER_PUBLISH_URL,\n token: env.CUCUMBER_PUBLISH_TOKEN,\n }\n}\n\nfunction isPublishing(\n flatConfiguration: IConfiguration,\n env: NodeJS.ProcessEnv\n): boolean {\n return (\n flatConfiguration.publish ||\n isTruthyString(env.CUCUMBER_PUBLISH_ENABLED) ||\n env.CUCUMBER_PUBLISH_TOKEN !== undefined\n )\n}\n"]}
1
+ {"version":3,"file":"convert_configuration.js","sourceRoot":"","sources":["../../src/api/convert_configuration.ts"],"names":[],"mappings":";;AASA,oDAoCC;AA7CD,oDAIyB;AAKlB,KAAK,UAAU,oBAAoB,CACxC,MAAe,EACf,iBAAiC,EACjC,GAAsB;IAEtB,OAAO;QACL,OAAO,EAAE;YACP,KAAK,EAAE,iBAAiB,CAAC,KAAK;YAC9B,cAAc,EAAE,iBAAiB,CAAC,QAAQ;YAC1C,KAAK,EAAE,iBAAiB,CAAC,IAAI;YAC7B,aAAa,EAAE,iBAAiB,CAAC,IAAI;YACrC,KAAK,EAAE,iBAAiB,CAAC,KAAK;YAC9B,KAAK,EAAE,iBAAiB,CAAC,KAAK;SAC/B;QACD,OAAO,EAAE;YACP,cAAc,EAAE,iBAAiB,CAAC,aAAa;YAC/C,YAAY,EAAE,iBAAiB,CAAC,OAAO;YACvC,WAAW,EAAE,iBAAiB,CAAC,MAAM;YACrC,OAAO,EAAE,iBAAiB,CAAC,MAAM;SAClC;QACD,OAAO,EAAE;YACP,MAAM,EAAE,iBAAiB,CAAC,MAAM;YAChC,QAAQ,EAAE,iBAAiB,CAAC,QAAQ;YACpC,iBAAiB,EAAE,CAAC,iBAAiB,CAAC,SAAS;YAC/C,QAAQ,EAAE,iBAAiB,CAAC,QAAQ;YACpC,KAAK,EAAE,iBAAiB,CAAC,KAAK;YAC9B,cAAc,EAAE,iBAAiB,CAAC,cAAc;YAChD,MAAM,EAAE,iBAAiB,CAAC,MAAM;YAChC,eAAe,EAAE,iBAAiB,CAAC,eAAe;SACnD;QACD,OAAO,EAAE,cAAc,CAAC,MAAM,EAAE,iBAAiB,EAAE,GAAG,CAAC;QACvD,OAAO,EAAE;YACP,UAAU,EAAE,iBAAiB,CAAC,MAAM;YACpC,OAAO,EAAE,iBAAiB,CAAC,aAAa;SACzC;KACF,CAAA;AACH,CAAC;AAED,SAAS,cAAc,CACrB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BAAiB,CAAC,OAAO;QACzB,IAAA,8BAAc,EAAC,GAAG,CAAC,wBAAwB,CAAC;QAC5C,GAAG,CAAC,sBAAsB,KAAK,SAAS,CACzC,CAAA;AACH,CAAC","sourcesContent":["import {\n IConfiguration,\n isTruthyString,\n splitFormatDescriptor,\n} from '../configuration'\nimport { IPublishConfig } from '../publish'\nimport { ILogger } from '../environment'\nimport { IRunConfiguration } from './types'\n\nexport async function convertConfiguration(\n logger: ILogger,\n flatConfiguration: IConfiguration,\n env: NodeJS.ProcessEnv\n): Promise<IRunConfiguration> {\n return {\n sources: {\n paths: flatConfiguration.paths,\n defaultDialect: flatConfiguration.language,\n names: flatConfiguration.name,\n tagExpression: flatConfiguration.tags,\n order: flatConfiguration.order,\n shard: flatConfiguration.shard,\n },\n support: {\n requireModules: flatConfiguration.requireModule,\n requirePaths: flatConfiguration.require,\n importPaths: flatConfiguration.import,\n loaders: flatConfiguration.loader,\n },\n runtime: {\n dryRun: flatConfiguration.dryRun,\n failFast: flatConfiguration.failFast,\n filterStacktraces: !flatConfiguration.backtrace,\n parallel: flatConfiguration.parallel,\n retry: flatConfiguration.retry,\n retryTagFilter: flatConfiguration.retryTagFilter,\n strict: flatConfiguration.strict,\n worldParameters: flatConfiguration.worldParameters,\n },\n formats: convertFormats(logger, flatConfiguration, env),\n plugins: {\n specifiers: flatConfiguration.plugin,\n options: flatConfiguration.pluginOptions,\n },\n }\n}\n\nfunction convertFormats(\n logger: ILogger,\n flatConfiguration: IConfiguration,\n env: NodeJS.ProcessEnv\n) {\n const splitFormats: string[][] = flatConfiguration.format.map((item) =>\n Array.isArray(item) ? item : splitFormatDescriptor(logger, item)\n )\n return {\n stdout:\n [...splitFormats].reverse().find(([, target]) => !target)?.[0] ??\n 'progress',\n files: splitFormats\n .filter(([, target]) => !!target)\n .reduce((mapped, [type, target]) => {\n return {\n ...mapped,\n [target]: type,\n }\n }, {}),\n publish: makePublishConfig(flatConfiguration, env),\n options: flatConfiguration.formatOptions,\n }\n}\n\nfunction makePublishConfig(\n flatConfiguration: IConfiguration,\n env: NodeJS.ProcessEnv\n): IPublishConfig | false {\n const enabled = isPublishing(flatConfiguration, env)\n if (!enabled) {\n return false\n }\n return {\n url: env.CUCUMBER_PUBLISH_URL,\n token: env.CUCUMBER_PUBLISH_TOKEN,\n }\n}\n\nfunction isPublishing(\n flatConfiguration: IConfiguration,\n env: NodeJS.ProcessEnv\n): boolean {\n return (\n flatConfiguration.publish ||\n isTruthyString(env.CUCUMBER_PUBLISH_ENABLED) ||\n env.CUCUMBER_PUBLISH_TOKEN !== undefined\n )\n}\n"]}
@@ -7,8 +7,10 @@
7
7
  * These docs cover the API used for running Cucumber programmatically. The entry point is `@cucumber/cucumber/api`.
8
8
  */
9
9
  export { IConfiguration } from '../configuration';
10
- export { IRunEnvironment } from '../environment';
11
- export { IPickleOrder } from '../filter';
10
+ export { ILogger, IRunEnvironment } from '../environment';
11
+ export { IFilterablePickle, IPickleOrder } from '../filter';
12
+ export { IResolvedPaths } from '../paths';
13
+ export { CoordinatorEventKey, CoordinatorEventValues, CoordinatorEventHandler, CoordinatorTransformKey, CoordinatorTransformValues, CoordinatorTransformer, CoordinatorContext, CoordinatorEnvironment, Plugin, PluginCleanup, PluginOperation, } from '../plugin';
12
14
  export { IPublishConfig } from '../publish';
13
15
  export * from './load_configuration';
14
16
  export * from './load_sources';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;AAMH,uDAAoC;AACpC,iDAA8B;AAC9B,iDAA8B;AAC9B,iDAA8B;AAC9B,0CAAuB","sourcesContent":["/**\n * JavaScript API for running and extending Cucumber\n *\n * @packageDocumentation\n * @module api\n * @remarks\n * These docs cover the API used for running Cucumber programmatically. The entry point is `@cucumber/cucumber/api`.\n */\n\nexport { IConfiguration } from '../configuration'\nexport { IRunEnvironment } from '../environment'\nexport { IPickleOrder } from '../filter'\nexport { IPublishConfig } from '../publish'\nexport * from './load_configuration'\nexport * from './load_sources'\nexport * from './load_support'\nexport * from './run_cucumber'\nexport * from './types'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;AAoBH,uDAAoC;AACpC,iDAA8B;AAC9B,iDAA8B;AAC9B,iDAA8B;AAC9B,0CAAuB","sourcesContent":["/**\n * JavaScript API for running and extending Cucumber\n *\n * @packageDocumentation\n * @module api\n * @remarks\n * These docs cover the API used for running Cucumber programmatically. The entry point is `@cucumber/cucumber/api`.\n */\n\nexport { IConfiguration } from '../configuration'\nexport { ILogger, IRunEnvironment } from '../environment'\nexport { IFilterablePickle, IPickleOrder } from '../filter'\nexport { IResolvedPaths } from '../paths'\nexport {\n CoordinatorEventKey,\n CoordinatorEventValues,\n CoordinatorEventHandler,\n CoordinatorTransformKey,\n CoordinatorTransformValues,\n CoordinatorTransformer,\n CoordinatorContext,\n CoordinatorEnvironment,\n Plugin,\n PluginCleanup,\n PluginOperation,\n} from '../plugin'\nexport { IPublishConfig } from '../publish'\nexport * from './load_configuration'\nexport * from './load_sources'\nexport * from './load_support'\nexport * from './run_cucumber'\nexport * from './types'\n"]}
@@ -1,5 +1,5 @@
1
- import { PluginManager } from '../plugin';
2
1
  import { UsableEnvironment } from '../environment';
2
+ import { PluginManager } from '../plugin';
3
3
  import { IRunConfiguration, ISourcesCoordinates } from './types';
4
4
  export declare function initializeForLoadSources(coordinates: ISourcesCoordinates, environment: UsableEnvironment): Promise<PluginManager>;
5
5
  export declare function initializeForLoadSupport(environment: UsableEnvironment): Promise<PluginManager>;
@@ -6,10 +6,54 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.initializeForLoadSources = initializeForLoadSources;
7
7
  exports.initializeForLoadSupport = initializeForLoadSupport;
8
8
  exports.initializeForRunCucumber = initializeForRunCucumber;
9
+ const node_url_1 = require("node:url");
10
+ const node_path_1 = __importDefault(require("node:path"));
11
+ const filter_1 = __importDefault(require("../filter"));
9
12
  const plugin_1 = require("../plugin");
10
13
  const publish_1 = __importDefault(require("../publish"));
11
- const filter_1 = __importDefault(require("../filter"));
12
14
  const sharding_1 = __importDefault(require("../sharding"));
15
+ const value_checker_1 = require("../value_checker");
16
+ async function importPlugin(specifier, cwd) {
17
+ try {
18
+ let normalized = specifier;
19
+ if (specifier.startsWith('.')) {
20
+ normalized = (0, node_url_1.pathToFileURL)(node_path_1.default.resolve(cwd, specifier));
21
+ }
22
+ else if (specifier.startsWith('file://')) {
23
+ normalized = new URL(specifier);
24
+ }
25
+ return await import(normalized.toString());
26
+ }
27
+ catch (e) {
28
+ throw new Error(`Failed to import plugin ${specifier}`, {
29
+ cause: e,
30
+ });
31
+ }
32
+ }
33
+ function findPlugin(imported) {
34
+ return findPluginRecursive(imported, 3);
35
+ }
36
+ function findPluginRecursive(thing, depth) {
37
+ if ((0, value_checker_1.doesNotHaveValue)(thing)) {
38
+ return null;
39
+ }
40
+ if (typeof thing === 'object' && thing.type === 'plugin') {
41
+ return thing;
42
+ }
43
+ depth--;
44
+ if (depth > 0) {
45
+ return findPluginRecursive(thing.default, depth);
46
+ }
47
+ return null;
48
+ }
49
+ async function loadPlugin(specifier, cwd) {
50
+ const imported = await importPlugin(specifier, cwd);
51
+ const found = findPlugin(imported);
52
+ if (!found) {
53
+ throw new Error(`${specifier} does not export a plugin`);
54
+ }
55
+ return found;
56
+ }
13
57
  async function initializeForLoadSources(coordinates, environment) {
14
58
  // eventually we'll load plugin packages here
15
59
  const pluginManager = new plugin_1.PluginManager(environment);
@@ -21,11 +65,16 @@ async function initializeForLoadSupport(environment) {
21
65
  return new plugin_1.PluginManager(environment);
22
66
  }
23
67
  async function initializeForRunCucumber(configuration, environment) {
24
- // eventually we'll load plugin packages here
25
68
  const pluginManager = new plugin_1.PluginManager(environment);
26
69
  await pluginManager.initCoordinator('runCucumber', publish_1.default, configuration.formats.publish);
27
70
  await pluginManager.initCoordinator('runCucumber', filter_1.default, configuration.sources);
28
71
  await pluginManager.initCoordinator('runCucumber', sharding_1.default, configuration.sources);
72
+ if (configuration.plugins) {
73
+ for (const specifier of configuration.plugins.specifiers) {
74
+ const plugin = await loadPlugin(specifier, environment.cwd);
75
+ await pluginManager.initCoordinator('runCucumber', plugin, configuration.plugins.options, specifier);
76
+ }
77
+ }
29
78
  return pluginManager;
30
79
  }
31
80
  //# sourceMappingURL=plugins.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../src/api/plugins.ts"],"names":[],"mappings":";;;;;AAOA,4DAQC;AAED,4DAKC;AAED,4DAsBC;AA9CD,sCAAyC;AACzC,yDAAsC;AACtC,uDAAoC;AACpC,2DAAwC;AAIjC,KAAK,UAAU,wBAAwB,CAC5C,WAAgC,EAChC,WAA8B;IAE9B,6CAA6C;IAC7C,MAAM,aAAa,GAAG,IAAI,sBAAa,CAAC,WAAW,CAAC,CAAA;IACpD,MAAM,aAAa,CAAC,eAAe,CAAC,aAAa,EAAE,gBAAY,EAAE,WAAW,CAAC,CAAA;IAC7E,OAAO,aAAa,CAAA;AACtB,CAAC;AAEM,KAAK,UAAU,wBAAwB,CAC5C,WAA8B;IAE9B,6CAA6C;IAC7C,OAAO,IAAI,sBAAa,CAAC,WAAW,CAAC,CAAA;AACvC,CAAC;AAEM,KAAK,UAAU,wBAAwB,CAC5C,aAAgC,EAChC,WAA8B;IAE9B,6CAA6C;IAC7C,MAAM,aAAa,GAAG,IAAI,sBAAa,CAAC,WAAW,CAAC,CAAA;IACpD,MAAM,aAAa,CAAC,eAAe,CACjC,aAAa,EACb,iBAAa,EACb,aAAa,CAAC,OAAO,CAAC,OAAO,CAC9B,CAAA;IACD,MAAM,aAAa,CAAC,eAAe,CACjC,aAAa,EACb,gBAAY,EACZ,aAAa,CAAC,OAAO,CACtB,CAAA;IACD,MAAM,aAAa,CAAC,eAAe,CACjC,aAAa,EACb,kBAAc,EACd,aAAa,CAAC,OAAO,CACtB,CAAA;IACD,OAAO,aAAa,CAAA;AACtB,CAAC","sourcesContent":["import { PluginManager } from '../plugin'\nimport publishPlugin from '../publish'\nimport filterPlugin from '../filter'\nimport shardingPlugin from '../sharding'\nimport { UsableEnvironment } from '../environment'\nimport { IRunConfiguration, ISourcesCoordinates } from './types'\n\nexport async function initializeForLoadSources(\n coordinates: ISourcesCoordinates,\n environment: UsableEnvironment\n): Promise<PluginManager> {\n // eventually we'll load plugin packages here\n const pluginManager = new PluginManager(environment)\n await pluginManager.initCoordinator('loadSources', filterPlugin, coordinates)\n return pluginManager\n}\n\nexport async function initializeForLoadSupport(\n environment: UsableEnvironment\n): Promise<PluginManager> {\n // eventually we'll load plugin packages here\n return new PluginManager(environment)\n}\n\nexport async function initializeForRunCucumber(\n configuration: IRunConfiguration,\n environment: UsableEnvironment\n): Promise<PluginManager> {\n // eventually we'll load plugin packages here\n const pluginManager = new PluginManager(environment)\n await pluginManager.initCoordinator(\n 'runCucumber',\n publishPlugin,\n configuration.formats.publish\n )\n await pluginManager.initCoordinator(\n 'runCucumber',\n filterPlugin,\n configuration.sources\n )\n await pluginManager.initCoordinator(\n 'runCucumber',\n shardingPlugin,\n configuration.sources\n )\n return pluginManager\n}\n"]}
1
+ {"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../src/api/plugins.ts"],"names":[],"mappings":";;;;;AAqDA,4DAQC;AAED,4DAKC;AAED,4DAmCC;AAzGD,uCAAwC;AACxC,0DAA4B;AAE5B,uDAAoC;AACpC,sCAAiD;AACjD,yDAAsC;AACtC,2DAAwC;AACxC,oDAAmD;AAGnD,KAAK,UAAU,YAAY,CAAC,SAAiB,EAAE,GAAW;IACxD,IAAI,CAAC;QACH,IAAI,UAAU,GAAiB,SAAS,CAAA;QACxC,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9B,UAAU,GAAG,IAAA,wBAAa,EAAC,mBAAI,CAAC,OAAO,CAAC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OAAO,KAAK,CAAA;AACd,CAAC;AAEM,KAAK,UAAU,wBAAwB,CAC5C,WAAgC,EAChC,WAA8B;IAE9B,6CAA6C;IAC7C,MAAM,aAAa,GAAG,IAAI,sBAAa,CAAC,WAAW,CAAC,CAAA;IACpD,MAAM,aAAa,CAAC,eAAe,CAAC,aAAa,EAAE,gBAAY,EAAE,WAAW,CAAC,CAAA;IAC7E,OAAO,aAAa,CAAA;AACtB,CAAC;AAEM,KAAK,UAAU,wBAAwB,CAC5C,WAA8B;IAE9B,6CAA6C;IAC7C,OAAO,IAAI,sBAAa,CAAC,WAAW,CAAC,CAAA;AACvC,CAAC;AAEM,KAAK,UAAU,wBAAwB,CAC5C,aAAgC,EAChC,WAA8B;IAE9B,MAAM,aAAa,GAAG,IAAI,sBAAa,CAAC,WAAW,CAAC,CAAA;IAEpD,MAAM,aAAa,CAAC,eAAe,CACjC,aAAa,EACb,iBAAa,EACb,aAAa,CAAC,OAAO,CAAC,OAAO,CAC9B,CAAA;IACD,MAAM,aAAa,CAAC,eAAe,CACjC,aAAa,EACb,gBAAY,EACZ,aAAa,CAAC,OAAO,CACtB,CAAA;IACD,MAAM,aAAa,CAAC,eAAe,CACjC,aAAa,EACb,kBAAc,EACd,aAAa,CAAC,OAAO,CACtB,CAAA;IAED,IAAI,aAAa,CAAC,OAAO,EAAE,CAAC;QAC1B,KAAK,MAAM,SAAS,IAAI,aAAa,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;YACzD,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,SAAS,EAAE,WAAW,CAAC,GAAG,CAAC,CAAA;YAC3D,MAAM,aAAa,CAAC,eAAe,CACjC,aAAa,EACb,MAAM,EACN,aAAa,CAAC,OAAO,CAAC,OAAO,EAC7B,SAAS,CACV,CAAA;QACH,CAAC;IACH,CAAC;IAED,OAAO,aAAa,CAAA;AACtB,CAAC","sourcesContent":["import { pathToFileURL } from 'node:url'\nimport path from 'node:path'\nimport { UsableEnvironment } from '../environment'\nimport filterPlugin from '../filter'\nimport { PluginManager, Plugin } from '../plugin'\nimport publishPlugin from '../publish'\nimport shardingPlugin from '../sharding'\nimport { doesNotHaveValue } from '../value_checker'\nimport { IRunConfiguration, ISourcesCoordinates } from './types'\n\nasync function importPlugin(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 plugin ${specifier}`, {\n cause: e,\n })\n }\n}\n\nfunction findPlugin(imported: any): Plugin | null {\n return findPluginRecursive(imported, 3)\n}\n\nfunction findPluginRecursive(thing: any, depth: number): Plugin | null {\n if (doesNotHaveValue(thing)) {\n return null\n }\n if (typeof thing === 'object' && thing.type === 'plugin') {\n return thing\n }\n depth--\n if (depth > 0) {\n return findPluginRecursive(thing.default, depth)\n }\n return null\n}\n\nasync function loadPlugin(specifier: string, cwd: string): Promise<Plugin> {\n const imported = await importPlugin(specifier, cwd)\n const found = findPlugin(imported)\n if (!found) {\n throw new Error(`${specifier} does not export a plugin`)\n }\n return found\n}\n\nexport async function initializeForLoadSources(\n coordinates: ISourcesCoordinates,\n environment: UsableEnvironment\n): Promise<PluginManager> {\n // eventually we'll load plugin packages here\n const pluginManager = new PluginManager(environment)\n await pluginManager.initCoordinator('loadSources', filterPlugin, coordinates)\n return pluginManager\n}\n\nexport async function initializeForLoadSupport(\n environment: UsableEnvironment\n): Promise<PluginManager> {\n // eventually we'll load plugin packages here\n return new PluginManager(environment)\n}\n\nexport async function initializeForRunCucumber(\n configuration: IRunConfiguration,\n environment: UsableEnvironment\n): Promise<PluginManager> {\n const pluginManager = new PluginManager(environment)\n\n await pluginManager.initCoordinator(\n 'runCucumber',\n publishPlugin,\n configuration.formats.publish\n )\n await pluginManager.initCoordinator(\n 'runCucumber',\n filterPlugin,\n configuration.sources\n )\n await pluginManager.initCoordinator(\n 'runCucumber',\n shardingPlugin,\n configuration.sources\n )\n\n if (configuration.plugins) {\n for (const specifier of configuration.plugins.specifiers) {\n const plugin = await loadPlugin(specifier, environment.cwd)\n await pluginManager.initCoordinator(\n 'runCucumber',\n plugin,\n configuration.plugins.options,\n specifier\n )\n }\n }\n\n return pluginManager\n}\n"]}
@@ -239,6 +239,29 @@ export interface IRunOptionsFormats {
239
239
  */
240
240
  options: JsonObject;
241
241
  }
242
+ /**
243
+ * Options relating to plugins - which ones to use and how they should behave
244
+ * @public
245
+ */
246
+ export interface IRunOptionsPlugins {
247
+ /**
248
+ * Specifiers of plugins to load
249
+ * @example
250
+ * [
251
+ * "\@cucumber/my-plugin",
252
+ * "./custom-plugin.js"
253
+ * ]
254
+ * @remarks
255
+ * Each item is a module specifier for a plugin to be loaded.
256
+ */
257
+ specifiers: string[];
258
+ /**
259
+ * Options to be provided to plugins
260
+ * @remarks
261
+ * The value must be a JSON-serializable object.
262
+ */
263
+ options: JsonObject;
264
+ }
242
265
  /**
243
266
  * Structured configuration object suitable for passing to {@link runCucumber}
244
267
  * @public
@@ -248,6 +271,7 @@ export interface IRunConfiguration {
248
271
  support: Partial<ISupportCodeCoordinates>;
249
272
  runtime: IRunOptionsRuntime;
250
273
  formats: IRunOptionsFormats;
274
+ plugins?: IRunOptionsPlugins;
251
275
  }
252
276
  /**
253
277
  * A collection of user-defined code and setup ("support code") that can be
@@ -283,6 +307,7 @@ export interface IRunOptions {
283
307
  support: ISupportCodeCoordinatesOrLibrary;
284
308
  runtime: IRunOptionsRuntime;
285
309
  formats: IRunOptionsFormats;
310
+ plugins?: IRunOptionsPlugins;
286
311
  }
287
312
  /**
288
313
  * Response from {@link runCucumber}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonObject } from 'type-fest'\nimport { IPublishConfig } from '../publish'\nimport { IConfiguration } from '../configuration'\nimport { IPickleOrder } from '../filter'\n\n/**\n * Options for {@link loadConfiguration}\n * @public\n */\nexport interface ILoadConfigurationOptions {\n /**\n * Path to load configuration file from, or `false` to skip\n * @default `cucumber.(json|yaml|yml|js|cjs|mjs)`\n */\n file?: string | false\n /**\n * Zero or more profile names from which to source configuration in the file\n * @remarks\n * If omitted or empty, the `default` profile will be used.\n */\n profiles?: string[]\n /**\n * Ad-hoc configuration options to be merged over the top of whatever is\n * loaded from the configuration file/profiles\n * @example\n * \\{\n * failFast: true,\n * parallel: 2\n * \\}\n * @example [\"--fail-fast\", \"--parallel\", \"2\"]\n * @example \"--fail-fast --parallel 2\"\n * @remarks\n * This can also be provided as an array or single string of argv-style\n * arguments.\n */\n provided?: Partial<IConfiguration> | string[] | string\n}\n\n/**\n * Response from {@link loadConfiguration}\n * @public\n */\nexport interface IResolvedConfiguration {\n /**\n * The final flat configuration object resolved from the configuration\n * file/profiles plus any extra provided\n */\n useConfiguration: IConfiguration\n /**\n * The format that can be passed into {@link runCucumber}\n */\n runConfiguration: IRunConfiguration\n}\n\n/**\n * Options relating to sources (i.e. feature files) - where to load them from,\n * how to interpret, filter and order them\n * @public\n */\nexport interface ISourcesCoordinates {\n /**\n * Default Gherkin dialect\n * @remarks\n * Used if no dialect is specified in the feature file itself.\n */\n defaultDialect: string\n /**\n * Paths and/or glob expressions to feature files\n */\n paths: string[]\n /**\n * Regular expressions of which scenario names should match one of to be run\n */\n names: string[]\n /**\n * Tag expression to filter which scenarios should be run\n */\n tagExpression: string\n /**\n * Run in the order defined, or in a random order\n */\n order: IPickleOrder\n /**\n * Shard tests and execute only the selected shard, format `<index>/<total>`\n * @example 1/4\n * @remarks\n * Shards use 1-based numbering\n */\n shard?: string\n}\n\n/**\n * A pickle that has been successfully compiled from a source\n * @public\n */\nexport interface IPlannedPickle {\n /**\n * Name of the pickle (after parameter resolution)\n */\n name: string\n uri: string\n location: {\n line: number\n column?: number\n }\n}\n\n/**\n * An error encountered when parsing a source\n * @public\n */\nexport interface ISourcesError {\n uri: string\n location: {\n line: number\n column?: number\n }\n /**\n * Error message explaining what went wrong with the parse\n */\n message: string\n}\n\n/**\n * Response from {@link loadSources}\n * @public\n */\nexport interface ILoadSourcesResult {\n /**\n * Pickles that have been successfully compiled, in the order they would be\n * run in\n */\n plan: IPlannedPickle[]\n /**\n * Any errors encountered when parsing sources\n */\n errors: ISourcesError[]\n}\n\n/**\n * Options relating to user code (aka support code) - where to load it from and\n * how to preprocess it\n * @public\n */\nexport interface ISupportCodeCoordinates {\n /**\n * Names of transpilation modules to load, via `require()`\n */\n requireModules: string[]\n /**\n * Paths and/or glob expressions of user code to load, via `require()`\n */\n requirePaths: string[]\n /**\n * Paths and/or glob expressions of user code to load, via `import()`\n */\n importPaths: string[]\n /**\n * Specifiers of loaders to register, via `register()`\n */\n loaders: string[]\n}\n\n/**\n * Options for {@link loadSupport}\n * @public\n * @remarks\n * A subset of {@link IRunConfiguration}\n */\nexport interface ILoadSupportOptions {\n /**\n * @remarks\n * This is needed because the default support path locations are derived from\n * feature file locations.\n */\n sources: ISourcesCoordinates\n support: Partial<ISupportCodeCoordinates>\n}\n\n/**\n * Options relating to behaviour when actually running tests\n * @public\n */\nexport interface IRunOptionsRuntime {\n /**\n * Perform a dry run, where a test run is prepared but nothing is executed\n */\n dryRun: boolean\n /**\n * Stop running tests when a test fails\n */\n failFast: boolean\n /**\n * Filter out stack frames from Cucumber's code when formatting stack traces\n */\n filterStacktraces: boolean\n /**\n * Run tests in parallel with the given number of worker processes\n */\n parallel: number\n /**\n * Retry failing tests up to the given number of times\n */\n retry: number\n /**\n * Tag expression to filter which scenarios can be retried\n */\n retryTagFilter: string\n /**\n * Fail the test run if there are pending steps\n */\n strict: boolean\n /**\n * Parameters to be passed to the World\n * @remarks\n * The value must be a JSON-serializable object.\n */\n worldParameters: JsonObject\n}\n\n/**\n * Options relating to formatters - which ones to use, where to write their\n * output, how they should behave\n * @public\n */\nexport interface IRunOptionsFormats {\n /**\n * Name/path of the formatter to use for `stdout` output\n */\n stdout: string\n /**\n * Zero or more mappings of file output path (key) to name/path of the\n * formatter to use (value)\n * @example\n * \\{\n * \"./reports/cucumber.html\": \"html\",\n * \"./reports/custom.txt\": \"./custom-formatter.js\"\n * \\}\n */\n files: Record<string, string>\n /**\n * Options for report publication, or `false` to disable publication\n */\n publish: IPublishConfig | false\n /**\n * Options to be provided to formatters\n * @remarks\n * The value must be a JSON-serializable object.\n */\n options: JsonObject\n}\n\n/**\n * Structured configuration object suitable for passing to {@link runCucumber}\n * @public\n */\nexport interface IRunConfiguration {\n sources: ISourcesCoordinates\n support: Partial<ISupportCodeCoordinates>\n runtime: IRunOptionsRuntime\n formats: IRunOptionsFormats\n}\n\n/**\n * A collection of user-defined code and setup (\"support code\") that can be\n * used for a test run\n * @public\n * @remarks\n * This is mostly a marker interface. The actual instance is a complex object\n * that you shouldn't interact with directly, but some functions return and/or\n * accept it as a means of optimising a test workflow.\n */\nexport interface ISupportCodeLibrary {\n readonly originalCoordinates: ISupportCodeCoordinates\n}\n\n/**\n * Either an actual {@link ISupportCodeLibrary | support code library}, or the\n * {@link ISupportCodeCoordinates | coordinates} required to create and\n * populate one\n * @public\n * @remarks\n * This alias exists because {@link runCucumber} will accept an existing\n * support code library in its options and thus avoid trying to load it again,\n * improving performance and avoiding cache issues for use cases where multiple\n * test runs happen within the same process. Note this is only useful in serial\n * mode, as parallel workers will each load the support code themselves anyway.\n */\nexport type ISupportCodeCoordinatesOrLibrary =\n | Partial<ISupportCodeCoordinates>\n | ISupportCodeLibrary\n\n/**\n * Options for {@link runCucumber}\n * @public\n */\nexport interface IRunOptions {\n sources: ISourcesCoordinates\n support: ISupportCodeCoordinatesOrLibrary\n runtime: IRunOptionsRuntime\n formats: IRunOptionsFormats\n}\n\n/**\n * Response from {@link runCucumber}\n * @public\n */\nexport interface IRunResult {\n /**\n * Whether the test run was overall successful\n * @remarks\n * The exact meaning can vary based on the `strict` configuration option.\n */\n success: boolean\n /**\n * The support code library that was used in the test run\n * @remarks\n * This can be reused in subsequent {@link runCucumber} calls,\n * see {@link ISupportCodeCoordinatesOrLibrary}\n */\n support: ISupportCodeLibrary\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonObject } from 'type-fest'\nimport { IPublishConfig } from '../publish'\nimport { IConfiguration } from '../configuration'\nimport { IPickleOrder } from '../filter'\n\n/**\n * Options for {@link loadConfiguration}\n * @public\n */\nexport interface ILoadConfigurationOptions {\n /**\n * Path to load configuration file from, or `false` to skip\n * @default `cucumber.(json|yaml|yml|js|cjs|mjs)`\n */\n file?: string | false\n /**\n * Zero or more profile names from which to source configuration in the file\n * @remarks\n * If omitted or empty, the `default` profile will be used.\n */\n profiles?: string[]\n /**\n * Ad-hoc configuration options to be merged over the top of whatever is\n * loaded from the configuration file/profiles\n * @example\n * \\{\n * failFast: true,\n * parallel: 2\n * \\}\n * @example [\"--fail-fast\", \"--parallel\", \"2\"]\n * @example \"--fail-fast --parallel 2\"\n * @remarks\n * This can also be provided as an array or single string of argv-style\n * arguments.\n */\n provided?: Partial<IConfiguration> | string[] | string\n}\n\n/**\n * Response from {@link loadConfiguration}\n * @public\n */\nexport interface IResolvedConfiguration {\n /**\n * The final flat configuration object resolved from the configuration\n * file/profiles plus any extra provided\n */\n useConfiguration: IConfiguration\n /**\n * The format that can be passed into {@link runCucumber}\n */\n runConfiguration: IRunConfiguration\n}\n\n/**\n * Options relating to sources (i.e. feature files) - where to load them from,\n * how to interpret, filter and order them\n * @public\n */\nexport interface ISourcesCoordinates {\n /**\n * Default Gherkin dialect\n * @remarks\n * Used if no dialect is specified in the feature file itself.\n */\n defaultDialect: string\n /**\n * Paths and/or glob expressions to feature files\n */\n paths: string[]\n /**\n * Regular expressions of which scenario names should match one of to be run\n */\n names: string[]\n /**\n * Tag expression to filter which scenarios should be run\n */\n tagExpression: string\n /**\n * Run in the order defined, or in a random order\n */\n order: IPickleOrder\n /**\n * Shard tests and execute only the selected shard, format `<index>/<total>`\n * @example 1/4\n * @remarks\n * Shards use 1-based numbering\n */\n shard?: string\n}\n\n/**\n * A pickle that has been successfully compiled from a source\n * @public\n */\nexport interface IPlannedPickle {\n /**\n * Name of the pickle (after parameter resolution)\n */\n name: string\n uri: string\n location: {\n line: number\n column?: number\n }\n}\n\n/**\n * An error encountered when parsing a source\n * @public\n */\nexport interface ISourcesError {\n uri: string\n location: {\n line: number\n column?: number\n }\n /**\n * Error message explaining what went wrong with the parse\n */\n message: string\n}\n\n/**\n * Response from {@link loadSources}\n * @public\n */\nexport interface ILoadSourcesResult {\n /**\n * Pickles that have been successfully compiled, in the order they would be\n * run in\n */\n plan: IPlannedPickle[]\n /**\n * Any errors encountered when parsing sources\n */\n errors: ISourcesError[]\n}\n\n/**\n * Options relating to user code (aka support code) - where to load it from and\n * how to preprocess it\n * @public\n */\nexport interface ISupportCodeCoordinates {\n /**\n * Names of transpilation modules to load, via `require()`\n */\n requireModules: string[]\n /**\n * Paths and/or glob expressions of user code to load, via `require()`\n */\n requirePaths: string[]\n /**\n * Paths and/or glob expressions of user code to load, via `import()`\n */\n importPaths: string[]\n /**\n * Specifiers of loaders to register, via `register()`\n */\n loaders: string[]\n}\n\n/**\n * Options for {@link loadSupport}\n * @public\n * @remarks\n * A subset of {@link IRunConfiguration}\n */\nexport interface ILoadSupportOptions {\n /**\n * @remarks\n * This is needed because the default support path locations are derived from\n * feature file locations.\n */\n sources: ISourcesCoordinates\n support: Partial<ISupportCodeCoordinates>\n}\n\n/**\n * Options relating to behaviour when actually running tests\n * @public\n */\nexport interface IRunOptionsRuntime {\n /**\n * Perform a dry run, where a test run is prepared but nothing is executed\n */\n dryRun: boolean\n /**\n * Stop running tests when a test fails\n */\n failFast: boolean\n /**\n * Filter out stack frames from Cucumber's code when formatting stack traces\n */\n filterStacktraces: boolean\n /**\n * Run tests in parallel with the given number of worker processes\n */\n parallel: number\n /**\n * Retry failing tests up to the given number of times\n */\n retry: number\n /**\n * Tag expression to filter which scenarios can be retried\n */\n retryTagFilter: string\n /**\n * Fail the test run if there are pending steps\n */\n strict: boolean\n /**\n * Parameters to be passed to the World\n * @remarks\n * The value must be a JSON-serializable object.\n */\n worldParameters: JsonObject\n}\n\n/**\n * Options relating to formatters - which ones to use, where to write their\n * output, how they should behave\n * @public\n */\nexport interface IRunOptionsFormats {\n /**\n * Name/path of the formatter to use for `stdout` output\n */\n stdout: string\n /**\n * Zero or more mappings of file output path (key) to name/path of the\n * formatter to use (value)\n * @example\n * \\{\n * \"./reports/cucumber.html\": \"html\",\n * \"./reports/custom.txt\": \"./custom-formatter.js\"\n * \\}\n */\n files: Record<string, string>\n /**\n * Options for report publication, or `false` to disable publication\n */\n publish: IPublishConfig | false\n /**\n * Options to be provided to formatters\n * @remarks\n * The value must be a JSON-serializable object.\n */\n options: JsonObject\n}\n\n/**\n * Options relating to plugins - which ones to use and how they should behave\n * @public\n */\nexport interface IRunOptionsPlugins {\n /**\n * Specifiers of plugins to load\n * @example\n * [\n * \"\\@cucumber/my-plugin\",\n * \"./custom-plugin.js\"\n * ]\n * @remarks\n * Each item is a module specifier for a plugin to be loaded.\n */\n specifiers: string[]\n /**\n * Options to be provided to plugins\n * @remarks\n * The value must be a JSON-serializable object.\n */\n options: JsonObject\n}\n\n/**\n * Structured configuration object suitable for passing to {@link runCucumber}\n * @public\n */\nexport interface IRunConfiguration {\n sources: ISourcesCoordinates\n support: Partial<ISupportCodeCoordinates>\n runtime: IRunOptionsRuntime\n formats: IRunOptionsFormats\n plugins?: IRunOptionsPlugins\n}\n\n/**\n * A collection of user-defined code and setup (\"support code\") that can be\n * used for a test run\n * @public\n * @remarks\n * This is mostly a marker interface. The actual instance is a complex object\n * that you shouldn't interact with directly, but some functions return and/or\n * accept it as a means of optimising a test workflow.\n */\nexport interface ISupportCodeLibrary {\n readonly originalCoordinates: ISupportCodeCoordinates\n}\n\n/**\n * Either an actual {@link ISupportCodeLibrary | support code library}, or the\n * {@link ISupportCodeCoordinates | coordinates} required to create and\n * populate one\n * @public\n * @remarks\n * This alias exists because {@link runCucumber} will accept an existing\n * support code library in its options and thus avoid trying to load it again,\n * improving performance and avoiding cache issues for use cases where multiple\n * test runs happen within the same process. Note this is only useful in serial\n * mode, as parallel workers will each load the support code themselves anyway.\n */\nexport type ISupportCodeCoordinatesOrLibrary =\n | Partial<ISupportCodeCoordinates>\n | ISupportCodeLibrary\n\n/**\n * Options for {@link runCucumber}\n * @public\n */\nexport interface IRunOptions {\n sources: ISourcesCoordinates\n support: ISupportCodeCoordinatesOrLibrary\n runtime: IRunOptionsRuntime\n formats: IRunOptionsFormats\n plugins?: IRunOptionsPlugins\n}\n\n/**\n * Response from {@link runCucumber}\n * @public\n */\nexport interface IRunResult {\n /**\n * Whether the test run was overall successful\n * @remarks\n * The exact meaning can vary based on the `strict` configuration option.\n */\n success: boolean\n /**\n * The support code library that was used in the test run\n * @remarks\n * This can be reused in subsequent {@link runCucumber} calls,\n * see {@link ISupportCodeCoordinatesOrLibrary}\n */\n support: ISupportCodeLibrary\n}\n"]}
@@ -4,6 +4,8 @@ export interface IParsedArgvOptions {
4
4
  i18nKeywords?: string;
5
5
  i18nLanguages?: boolean;
6
6
  profile: string[];
7
+ plugin?: string[];
8
+ pluginOptions?: object;
7
9
  }
8
10
  export interface IParsedArgv {
9
11
  options: IParsedArgvOptions;
@@ -71,6 +71,8 @@ const ArgvParser = {
71
71
  .option('--order <TYPE[:SEED]>', 'run scenarios in the specified order. Type should be `defined`, `reverse` or `random`')
72
72
  .option('-p, --profile <NAME>', 'specify the profile to use (repeatable)', ArgvParser.collect, [])
73
73
  .option('--parallel <NUMBER_OF_WORKERS>', 'run in parallel with the given number of workers', (val) => ArgvParser.validateCountOption(val, '--parallel'))
74
+ .option('--plugin <SPECIFIER>', 'load a plugin (repeatable)', ArgvParser.collect)
75
+ .option('--plugin-options <JSON>', 'provide options for plugins (repeatable)', ArgvParser.mergeJson('--plugin-options'))
74
76
  .option('--publish', 'Publish a report to https://reports.cucumber.io')
75
77
  .option('-r, --require <GLOB|DIR|FILE>', 'require files before executing features (repeatable)', ArgvParser.collect)
76
78
  .option('--require-module <NODE_MODULE>', 'require node modules before requiring files (repeatable)', ArgvParser.collect)
@@ -1 +1 @@
1
- {"version":3,"file":"argv_parser.js","sourceRoot":"","sources":["../../src/configuration/argv_parser.ts"],"names":[],"mappings":";;;;;AAAA,yCAAmC;AACnC,gEAAgC;AAChC,+CAA4C;AAC5C,wCAAoC;AACpC,kDAAoD;AAkBpD,MAAM,UAAU,GAAG;IACjB,OAAO,CAAI,GAAM,EAAE,OAAY,EAAE;QAC/B,IAAI,GAAG,EAAE,CAAC;YACR,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,CAAA;QACvB,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,SAAS,CAAC,MAAc;QACtB,OAAO,UAAU,GAAW,EAAE,OAAe,EAAE;YAC7C,IAAI,GAAW,CAAA;YACf,IAAI,CAAC;gBACH,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACvB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,CAAC,GAAU,KAAK,CAAA;gBACtB,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,yBAAyB,CAAC,CAAC,OAAO,KAAK,GAAG,EAAE,CAAC,CAAA;YACxE,CAAC;YACD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;gBAClD,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,sCAAsC,GAAG,EAAE,CAAC,CAAA;YACvE,CAAC;YACD,OAAO,IAAA,sBAAK,EAAC,IAAI,EAAE,GAAG,CAAC,CAAA;QACzB,CAAC,CAAA;IACH,CAAC;IAED,SAAS,CAAC,KAAa,EAAE,IAAa;QACpC,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,SAAS,KAAK,GAAG,C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,UAAU,EAAE,iCAAiC,CAAC;aACrD,MAAM,CAAC,aAAa,EAAE,yCAAyC,CAAC;aAChE,MAAM,CACL,yBAAyB,EACzB,uFAAuF,EACvF,UAAU,CAAC,SAAS,CACrB;aACA,MAAM,CACL,2BAA2B,EAC3B,8EAA8E,EAC9E,UAAU,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAC3C,CAAA;QAEH,OAAO,CAAC,WAAW,CACjB,UAAU,EACV,6FAA6F,CAC9F,CAAA;QAED,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACnB,MAAM,EACJ,MAAM,EACN,YAAY,EACZ,aAAa,EACb,OAAO,EACP,GAAG,YAAY,EAChB,GAAoB,OAAO,CAAC,IAAI,EAAE,CAAA;QACnC,MAAM,aAAa,GAA4B,YAAY,CAAA;QAC3D,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,aAAa,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,CAAA;QACpC,CAAC;QAED,OAAO;YACL,OAAO,EAAE;gBACP,MAAM;gBACN,YAAY;gBACZ,aAAa;gBACb,OAAO;aACR;YACD,aAAa;SACd,CAAA;IACH,CAAC;CACF,CAAA;AAED,kBAAe,UAAU,CAAA","sourcesContent":["import { Command } from 'commander'\nimport merge from 'lodash.merge'\nimport { dialects } from '@cucumber/gherkin'\nimport { version } from '../version'\nimport { documentation } from '../formatter/builtin'\nimport { IConfiguration } from './types'\n\nexport interface IParsedArgvOptions {\n config?: string\n i18nKeywords?: string\n i18nLanguages?: boolean\n profile: string[]\n}\n\nexport interface IParsedArgv {\n options: IParsedArgvOptions\n configuration: Partial<IConfiguration>\n}\n\ntype IRawArgvOptions = Partial<Omit<IConfiguration, 'paths'>> &\n IParsedArgvOptions\n\nconst ArgvParser = {\n collect<T>(val: T, memo: T[] = []): T[] {\n if (val) {\n return [...memo, val]\n }\n return undefined\n },\n\n mergeJson(option: string): (str: string, memo?: object) => object {\n return function (str: string, memo: object = {}) {\n let val: object\n try {\n val = JSON.parse(str)\n } catch (error) {\n const e: Error = error\n throw new Error(`${option} passed invalid JSON: ${e.message}: ${str}`)\n }\n if (typeof val !== 'object' || Array.isArray(val)) {\n throw new Error(`${option} must be passed JSON of an object: ${str}`)\n }\n return merge(memo, val)\n }\n },\n\n mergeTags(value: string, memo?: string): string {\n return memo ? `${memo} and (${value})` : `(${value})`\n },\n\n validateCountOption(value: string, optionName: string): number {\n const numericValue = parseInt(value)\n if (isNaN(numericValue) || numericValue < 0) {\n throw new Error(`${optionName} must be a non negative integer`)\n }\n return numericValue\n },\n\n validateLanguage(value: string): string {\n if (!Object.keys(dialects).includes(value)) {\n throw new Error(`Unsupported ISO 639-1: ${value}`)\n }\n return value\n },\n\n parse(argv: string[]): IParsedArgv {\n const program = new Command('cucumber-js')\n\n program\n .allowExcessArguments(true)\n .storeOptionsAsProperties(false)\n .usage('[options] [<GLOB|DIR|FILE[:LINE]>...]')\n .version(version, '-v, --version')\n .option('-b, --backtrace', 'show full backtrace for errors')\n .option('-c, --config <PATH>', 'specify configuration file')\n .option('-d, --dry-run', 'invoke formatters without executing steps')\n .option(\n '--exit, --force-exit',\n 'force shutdown of the event loop when the test run has finished: cucumber will call process.exit'\n )\n .option('--fail-fast', 'abort the run on first failure')\n .option(\n '-f, --format <TYPE[:PATH]>',\n 'specify the output format, optionally supply PATH to redirect formatter output (repeatable). Available formats:\\n' +\n Object.entries(documentation).reduce(\n (previous, [key, description]) =>\n previous + ` ${key}: ${description}\\n`,\n ''\n ),\n ArgvParser.collect\n )\n .option(\n '--format-options <JSON>',\n 'provide options for formatters (repeatable)',\n ArgvParser.mergeJson('--format-options')\n )\n .option(\n '--i18n-keywords <ISO 639-1>',\n 'list language keywords',\n ArgvParser.validateLanguage\n )\n .option('--i18n-languages', 'list languages')\n .option(\n '-i, --import <GLOB|DIR|FILE>',\n 'import files before executing features (repeatable)',\n ArgvParser.collect\n )\n .option(\n '-l, --loader <NODE_MODULE>',\n 'module specifier(s) for loaders to be registered ahead of loading support code',\n ArgvParser.collect\n )\n .option(\n '--language <ISO 639-1>',\n 'provide the default language for feature files'\n )\n .option(\n '--name <REGEXP>',\n 'only execute the scenarios with name matching the expression (repeatable)',\n ArgvParser.collect\n )\n .option(\n '--order <TYPE[:SEED]>',\n 'run scenarios in the specified order. Type should be `defined`, `reverse` or `random`'\n )\n .option(\n '-p, --profile <NAME>',\n 'specify the profile to use (repeatable)',\n ArgvParser.collect,\n []\n )\n .option(\n '--parallel <NUMBER_OF_WORKERS>',\n 'run in parallel with the given number of workers',\n (val) => ArgvParser.validateCountOption(val, '--parallel')\n )\n .option('--publish', 'Publish a report to https://reports.cucumber.io')\n .option(\n '-r, --require <GLOB|DIR|FILE>',\n 'require files before executing features (repeatable)',\n ArgvParser.collect\n )\n .option(\n '--require-module <NODE_MODULE>',\n 'require node modules before requiring files (repeatable)',\n ArgvParser.collect\n )\n .option(\n '--retry <NUMBER_OF_RETRIES>',\n 'specify the number of times to retry failing test cases (default: 0)',\n (val) => ArgvParser.validateCountOption(val, '--retry')\n )\n .option(\n '--retry-tag-filter <EXPRESSION>',\n `only retries the features or scenarios with tags matching the expression (repeatable).\n This option requires '--retry' to be specified.`,\n ArgvParser.mergeTags\n )\n .option(\n '--shard <INDEX/TOTAL>',\n 'run shard INDEX of TOTAL shards. The index starts at 1'\n )\n .option('--strict', 'fail if there are pending steps')\n .option('--no-strict', 'succeed even if there are pending steps')\n .option(\n '-t, --tags <EXPRESSION>',\n 'only execute the features or scenarios with tags matching the expression (repeatable)',\n ArgvParser.mergeTags\n )\n .option(\n '--world-parameters <JSON>',\n 'provide parameters that will be passed to the world constructor (repeatable)',\n ArgvParser.mergeJson('--world-parameters')\n )\n\n program.addHelpText(\n 'afterAll',\n 'For more details please visit https://github.com/cucumber/cucumber-js/blob/main/docs/cli.md'\n )\n\n program.parse(argv)\n const {\n config,\n i18nKeywords,\n i18nLanguages,\n profile,\n ...regularStuff\n }: IRawArgvOptions = program.opts()\n const configuration: Partial<IConfiguration> = regularStuff\n if (program.args.length > 0) {\n configuration.paths = program.args\n }\n\n return {\n options: {\n config,\n i18nKeywords,\n i18nLanguages,\n profile,\n },\n configuration,\n }\n },\n}\n\nexport default ArgvParser\n"]}
1
+ {"version":3,"file":"argv_parser.js","sourceRoot":"","sources":["../../src/configuration/argv_parser.ts"],"names":[],"mappings":";;;;;AAAA,yCAAmC;AACnC,gEAAgC;AAChC,+CAA4C;AAC5C,wCAAoC;AACpC,kDAAoD;AAoBpD,MAAM,UAAU,GAAG;IACjB,OAAO,CAAI,GAAM,EAAE,OAAY,EAAE;QAC/B,IAAI,GAAG,EAAE,CAAC;YACR,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,CAAA;QACvB,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,SAAS,CAAC,MAAc;QACtB,OAAO,UAAU,GAAW,EAAE,OAAe,EAAE;YAC7C,IAAI,GAAW,CAAA;YACf,IAAI,CAAC;gBACH,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACvB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,CAAC,GAAU,KAAK,CAAA;gBACtB,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,yBAAyB,CAAC,CAAC,OAAO,KAAK,GAAG,EAAE,CAAC,CAAA;YACxE,CAAC;YACD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;gBAClD,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,sCAAsC,GAAG,EAAE,CAAC,CAAA;YACvE,CAAC;YACD,OAAO,IAAA,sBAAK,EAAC,IAAI,EAAE,GAAG,CAAC,CAAA;QACzB,CAAC,CAAA;IACH,CAAC;IAED,SAAS,CAAC,KAAa,EAAE,IAAa;QACpC,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,SAAS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C,mBAAmB,CAAC,GAAG,EAAE,SAAS,CAAC,CACxD;aACA,MAAM,CACL,iCAAiC,EACjC;wDACgD,EAChD,UAAU,CAAC,SAAS,CACrB;aACA,MAAM,CACL,uBAAuB,EACvB,wDAAwD,CACzD;aACA,MAAM,CAAC,UAAU,EAAE,iCAAiC,CAAC;aACrD,MAAM,CAAC,aAAa,EAAE,yCAAyC,CAAC;aAChE,MAAM,CACL,yBAAyB,EACzB,uFAAuF,EACvF,UAAU,CAAC,SAAS,CACrB;aACA,MAAM,CACL,2BAA2B,EAC3B,8EAA8E,EAC9E,UAAU,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAC3C,CAAA;QAEH,OAAO,CAAC,WAAW,CACjB,UAAU,EACV,6FAA6F,CAC9F,CAAA;QAED,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACnB,MAAM,EACJ,MAAM,EACN,YAAY,EACZ,aAAa,EACb,OAAO,EACP,GAAG,YAAY,EAChB,GAAoB,OAAO,CAAC,IAAI,EAAE,CAAA;QACnC,MAAM,aAAa,GAA4B,YAAY,CAAA;QAC3D,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,aAAa,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,CAAA;QACpC,CAAC;QAED,OAAO;YACL,OAAO,EAAE;gBACP,MAAM;gBACN,YAAY;gBACZ,aAAa;gBACb,OAAO;aACR;YACD,aAAa;SACd,CAAA;IACH,CAAC;CACF,CAAA;AAED,kBAAe,UAAU,CAAA","sourcesContent":["import { Command } from 'commander'\nimport merge from 'lodash.merge'\nimport { dialects } from '@cucumber/gherkin'\nimport { version } from '../version'\nimport { documentation } from '../formatter/builtin'\nimport { IConfiguration } from './types'\n\nexport interface IParsedArgvOptions {\n config?: string\n i18nKeywords?: string\n i18nLanguages?: boolean\n profile: string[]\n plugin?: string[]\n pluginOptions?: object\n}\n\nexport interface IParsedArgv {\n options: IParsedArgvOptions\n configuration: Partial<IConfiguration>\n}\n\ntype IRawArgvOptions = Partial<Omit<IConfiguration, 'paths'>> &\n IParsedArgvOptions\n\nconst ArgvParser = {\n collect<T>(val: T, memo: T[] = []): T[] {\n if (val) {\n return [...memo, val]\n }\n return undefined\n },\n\n mergeJson(option: string): (str: string, memo?: object) => object {\n return function (str: string, memo: object = {}) {\n let val: object\n try {\n val = JSON.parse(str)\n } catch (error) {\n const e: Error = error\n throw new Error(`${option} passed invalid JSON: ${e.message}: ${str}`)\n }\n if (typeof val !== 'object' || Array.isArray(val)) {\n throw new Error(`${option} must be passed JSON of an object: ${str}`)\n }\n return merge(memo, val)\n }\n },\n\n mergeTags(value: string, memo?: string): string {\n return memo ? `${memo} and (${value})` : `(${value})`\n },\n\n validateCountOption(value: string, optionName: string): number {\n const numericValue = parseInt(value)\n if (isNaN(numericValue) || numericValue < 0) {\n throw new Error(`${optionName} must be a non negative integer`)\n }\n return numericValue\n },\n\n validateLanguage(value: string): string {\n if (!Object.keys(dialects).includes(value)) {\n throw new Error(`Unsupported ISO 639-1: ${value}`)\n }\n return value\n },\n\n parse(argv: string[]): IParsedArgv {\n const program = new Command('cucumber-js')\n\n program\n .allowExcessArguments(true)\n .storeOptionsAsProperties(false)\n .usage('[options] [<GLOB|DIR|FILE[:LINE]>...]')\n .version(version, '-v, --version')\n .option('-b, --backtrace', 'show full backtrace for errors')\n .option('-c, --config <PATH>', 'specify configuration file')\n .option('-d, --dry-run', 'invoke formatters without executing steps')\n .option(\n '--exit, --force-exit',\n 'force shutdown of the event loop when the test run has finished: cucumber will call process.exit'\n )\n .option('--fail-fast', 'abort the run on first failure')\n .option(\n '-f, --format <TYPE[:PATH]>',\n 'specify the output format, optionally supply PATH to redirect formatter output (repeatable). Available formats:\\n' +\n Object.entries(documentation).reduce(\n (previous, [key, description]) =>\n previous + ` ${key}: ${description}\\n`,\n ''\n ),\n ArgvParser.collect\n )\n .option(\n '--format-options <JSON>',\n 'provide options for formatters (repeatable)',\n ArgvParser.mergeJson('--format-options')\n )\n .option(\n '--i18n-keywords <ISO 639-1>',\n 'list language keywords',\n ArgvParser.validateLanguage\n )\n .option('--i18n-languages', 'list languages')\n .option(\n '-i, --import <GLOB|DIR|FILE>',\n 'import files before executing features (repeatable)',\n ArgvParser.collect\n )\n .option(\n '-l, --loader <NODE_MODULE>',\n 'module specifier(s) for loaders to be registered ahead of loading support code',\n ArgvParser.collect\n )\n .option(\n '--language <ISO 639-1>',\n 'provide the default language for feature files'\n )\n .option(\n '--name <REGEXP>',\n 'only execute the scenarios with name matching the expression (repeatable)',\n ArgvParser.collect\n )\n .option(\n '--order <TYPE[:SEED]>',\n 'run scenarios in the specified order. Type should be `defined`, `reverse` or `random`'\n )\n .option(\n '-p, --profile <NAME>',\n 'specify the profile to use (repeatable)',\n ArgvParser.collect,\n []\n )\n .option(\n '--parallel <NUMBER_OF_WORKERS>',\n 'run in parallel with the given number of workers',\n (val) => ArgvParser.validateCountOption(val, '--parallel')\n )\n .option(\n '--plugin <SPECIFIER>',\n 'load a plugin (repeatable)',\n ArgvParser.collect\n )\n .option(\n '--plugin-options <JSON>',\n 'provide options for plugins (repeatable)',\n ArgvParser.mergeJson('--plugin-options')\n )\n .option('--publish', 'Publish a report to https://reports.cucumber.io')\n .option(\n '-r, --require <GLOB|DIR|FILE>',\n 'require files before executing features (repeatable)',\n ArgvParser.collect\n )\n .option(\n '--require-module <NODE_MODULE>',\n 'require node modules before requiring files (repeatable)',\n ArgvParser.collect\n )\n .option(\n '--retry <NUMBER_OF_RETRIES>',\n 'specify the number of times to retry failing test cases (default: 0)',\n (val) => ArgvParser.validateCountOption(val, '--retry')\n )\n .option(\n '--retry-tag-filter <EXPRESSION>',\n `only retries the features or scenarios with tags matching the expression (repeatable).\n This option requires '--retry' to be specified.`,\n ArgvParser.mergeTags\n )\n .option(\n '--shard <INDEX/TOTAL>',\n 'run shard INDEX of TOTAL shards. The index starts at 1'\n )\n .option('--strict', 'fail if there are pending steps')\n .option('--no-strict', 'succeed even if there are pending steps')\n .option(\n '-t, --tags <EXPRESSION>',\n 'only execute the features or scenarios with tags matching the expression (repeatable)',\n ArgvParser.mergeTags\n )\n .option(\n '--world-parameters <JSON>',\n 'provide parameters that will be passed to the world constructor (repeatable)',\n ArgvParser.mergeJson('--world-parameters')\n )\n\n program.addHelpText(\n 'afterAll',\n 'For more details please visit https://github.com/cucumber/cucumber-js/blob/main/docs/cli.md'\n )\n\n program.parse(argv)\n const {\n config,\n i18nKeywords,\n i18nLanguages,\n profile,\n ...regularStuff\n }: IRawArgvOptions = program.opts()\n const configuration: Partial<IConfiguration> = regularStuff\n if (program.args.length > 0) {\n configuration.paths = program.args\n }\n\n return {\n options: {\n config,\n i18nKeywords,\n i18nLanguages,\n profile,\n },\n configuration,\n }\n },\n}\n\nexport default ArgvParser\n"]}
@@ -8,6 +8,8 @@ exports.DEFAULT_CONFIGURATION = {
8
8
  failFast: false,
9
9
  format: [],
10
10
  formatOptions: {},
11
+ plugin: [],
12
+ pluginOptions: {},
11
13
  import: [],
12
14
  language: 'en',
13
15
  loader: [],
@@ -1 +1 @@
1
- {"version":3,"file":"default_configuration.js","sourceRoot":"","sources":["../../src/configuration/default_configuration.ts"],"names":[],"mappings":";;;AAEa,QAAA,qBAAqB,GAAmB;IACnD,SAAS,EAAE,KAAK;IAChB,MAAM,EAAE,KAAK;IACb,SAAS,EAAE,KAAK;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,EAAE;IACV,aAAa,EAAE,EAAE;IACjB,MAAM,EAAE,EAAE;IACV,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,EAAE;IACV,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,EAAE;IACT,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,KAAK;IACd,OAAO,EAAE,EAAE;IACX,aAAa,EAAE,EAAE;IACjB,KAAK,EAAE,CAAC;IACR,cAAc,EAAE,EAAE;IAClB,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,EAAE;IACR,eAAe,EAAE,EAAE;CACpB,CAAA","sourcesContent":["import { IConfiguration } from './types'\n\nexport const DEFAULT_CONFIGURATION: IConfiguration = {\n backtrace: false,\n dryRun: false,\n forceExit: false,\n failFast: false,\n format: [],\n formatOptions: {},\n import: [],\n language: 'en',\n loader: [],\n name: [],\n order: 'defined',\n paths: [],\n parallel: 0,\n publish: false,\n require: [],\n requireModule: [],\n retry: 0,\n retryTagFilter: '',\n shard: '',\n strict: true,\n tags: '',\n worldParameters: {},\n}\n"]}
1
+ {"version":3,"file":"default_configuration.js","sourceRoot":"","sources":["../../src/configuration/default_configuration.ts"],"names":[],"mappings":";;;AAEa,QAAA,qBAAqB,GAAmB;IACnD,SAAS,EAAE,KAAK;IAChB,MAAM,EAAE,KAAK;IACb,SAAS,EAAE,KAAK;IAChB,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,EAAE;IACV,aAAa,EAAE,EAAE;IACjB,MAAM,EAAE,EAAE;IACV,aAAa,EAAE,EAAE;IACjB,MAAM,EAAE,EAAE;IACV,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,EAAE;IACV,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,EAAE;IACT,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,KAAK;IACd,OAAO,EAAE,EAAE;IACX,aAAa,EAAE,EAAE;IACjB,KAAK,EAAE,CAAC;IACR,cAAc,EAAE,EAAE;IAClB,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,EAAE;IACR,eAAe,EAAE,EAAE;CACpB,CAAA","sourcesContent":["import { IConfiguration } from './types'\n\nexport const DEFAULT_CONFIGURATION: IConfiguration = {\n backtrace: false,\n dryRun: false,\n forceExit: false,\n failFast: false,\n format: [],\n formatOptions: {},\n plugin: [],\n pluginOptions: {},\n import: [],\n language: 'en',\n loader: [],\n name: [],\n order: 'defined',\n paths: [],\n parallel: 0,\n publish: false,\n require: [],\n requireModule: [],\n retry: 0,\n retryTagFilter: '',\n shard: '',\n strict: true,\n tags: '',\n worldParameters: {},\n}\n"]}
@@ -11,6 +11,17 @@ const node_url_1 = require("node:url");
11
11
  const yaml_1 = __importDefault(require("yaml"));
12
12
  const merge_configurations_1 = require("./merge_configurations");
13
13
  const parse_configuration_1 = require("./parse_configuration");
14
+ const SUPPORTED_EXTENSIONS = [
15
+ '.json',
16
+ '.yaml',
17
+ '.yml',
18
+ '.js',
19
+ '.cjs',
20
+ '.mjs',
21
+ '.ts',
22
+ '.cts',
23
+ '.mts',
24
+ ];
14
25
  async function fromFile(logger, cwd, file, profiles = []) {
15
26
  let definitions = await loadFile(logger, cwd, file);
16
27
  const defaultDefinition = definitions.default;
@@ -49,45 +60,63 @@ async function handleDefaultFunctionDefinition(definitions, defaultDefinition) {
49
60
  async function loadFile(logger, cwd, file) {
50
61
  const filePath = node_path_1.default.join(cwd, file);
51
62
  const extension = node_path_1.default.extname(filePath);
63
+ if (!SUPPORTED_EXTENSIONS.includes(extension)) {
64
+ throw new Error(`Unsupported configuration file extension "${extension}"`);
65
+ }
52
66
  let definitions;
53
- switch (extension) {
54
- case '.json':
55
- definitions = JSON.parse(await (0, node_util_1.promisify)(node_fs_1.default.readFile)(filePath, { encoding: 'utf-8' }));
56
- break;
57
- case '.yaml':
58
- case '.yml':
59
- definitions = yaml_1.default.parse(await (0, node_util_1.promisify)(node_fs_1.default.readFile)(filePath, { encoding: 'utf-8' }));
60
- break;
61
- case '.cjs':
62
- logger.debug(`Loading configuration file "${file}" as CommonJS based on extension`);
63
- // eslint-disable-next-line @typescript-eslint/no-require-imports
64
- definitions = require(filePath);
65
- break;
66
- case '.mjs':
67
- logger.debug(`Loading configuration file "${file}" as ESM based on extension`);
68
- definitions = await import((0, node_url_1.pathToFileURL)(filePath).toString());
69
- break;
70
- case '.js':
71
- {
72
- const parentPackage = await readPackageJson(filePath);
73
- if (!parentPackage) {
74
- logger.debug(`Loading configuration file "${file}" as CommonJS based on absence of a parent package`);
75
- // eslint-disable-next-line @typescript-eslint/no-require-imports
76
- definitions = require(filePath);
77
- }
78
- else if (parentPackage.type === 'module') {
79
- logger.debug(`Loading configuration file "${file}" as ESM based on "${parentPackage.name}" package type`);
80
- definitions = await import((0, node_url_1.pathToFileURL)(filePath).toString());
81
- }
82
- else {
83
- logger.debug(`Loading configuration file "${file}" as CommonJS based on "${parentPackage.name}" package type`);
84
- // eslint-disable-next-line @typescript-eslint/no-require-imports
85
- definitions = require(filePath);
67
+ try {
68
+ switch (extension) {
69
+ case '.json':
70
+ definitions = JSON.parse(await (0, node_util_1.promisify)(node_fs_1.default.readFile)(filePath, { encoding: 'utf-8' }));
71
+ break;
72
+ case '.yaml':
73
+ case '.yml':
74
+ definitions = yaml_1.default.parse(await (0, node_util_1.promisify)(node_fs_1.default.readFile)(filePath, { encoding: 'utf-8' }));
75
+ break;
76
+ case '.cjs':
77
+ logger.debug(`Loading configuration file "${file}" as CommonJS based on extension`);
78
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
79
+ definitions = require(filePath);
80
+ break;
81
+ case '.cts':
82
+ logger.debug(`Loading configuration file "${file}" as TypeScript based on extension`);
83
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
84
+ definitions = require(filePath);
85
+ break;
86
+ case '.mjs':
87
+ logger.debug(`Loading configuration file "${file}" as ESM based on extension`);
88
+ definitions = await import((0, node_url_1.pathToFileURL)(filePath).toString());
89
+ break;
90
+ case '.mts':
91
+ case '.ts':
92
+ logger.debug(`Loading configuration file "${file}" as TypeScript based on extension`);
93
+ definitions = await import((0, node_url_1.pathToFileURL)(filePath).toString());
94
+ break;
95
+ case '.js':
96
+ {
97
+ const parentPackage = await readPackageJson(filePath);
98
+ if (!parentPackage) {
99
+ logger.debug(`Loading configuration file "${file}" as CommonJS based on absence of a parent package`);
100
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
101
+ definitions = require(filePath);
102
+ }
103
+ else if (parentPackage.type === 'module') {
104
+ logger.debug(`Loading configuration file "${file}" as ESM based on "${parentPackage.name}" package type`);
105
+ definitions = await import((0, node_url_1.pathToFileURL)(filePath).toString());
106
+ }
107
+ else {
108
+ logger.debug(`Loading configuration file "${file}" as CommonJS based on "${parentPackage.name}" package type`);
109
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
110
+ definitions = require(filePath);
111
+ }
86
112
  }
87
- }
88
- break;
89
- default:
90
- throw new Error(`Unsupported configuration file extension "${extension}"`);
113
+ break;
114
+ }
115
+ }
116
+ catch (error) {
117
+ throw new Error(`Configuration file "${file}" failed to load/parse`, {
118
+ cause: error,
119
+ });
91
120
  }
92
121
  if (typeof definitions !== 'object') {
93
122
  throw new Error(`Configuration file ${filePath} does not export an object`);
@@ -1 +1 @@
1
- {"version":3,"file":"from_file.js","sourceRoot":"","sources":["../../src/configuration/from_file.ts"],"names":[],"mappings":";;;;;AAUA,4BA4CC;AAtDD,sDAAwB;AACxB,0DAA4B;AAC5B,yCAAqC;AACrC,uCAAwC;AACxC,gDAAuB;AAGvB,iEAA4D;AAC5D,+DAA0D;AAEnD,KAAK,UAAU,QAAQ,CAC5B,MAAe,EACf,GAAW,EACX,IAAY,EACZ,WAAqB,EAAE;IAEvB,IAAI,WAAW,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;IAEnD,MAAM,iBAAiB,GAAY,WAAW,CAAC,OAAO,CAAA;IAEtD,IAAI,iBAAiB,EAAE,CAAC;QACtB,IAAI,OAAO,iBAAiB,KAAK,UAAU,EAAE,CAAC;YAC5C,MAAM,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAA;YACxD,WAAW,GAAG,MAAM,+BAA+B,CACjD,WAAW,EACX,iBAAiB,CAClB,CAAA;QACH,CAAC;IACH,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAA;QAChE,WAAW,CAAC,OAAO,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BACD,WAAW,GAAG,MAAM,MAAM,CAAC,IAAA,wBAAa,EAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;gBAChE,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,KAAK,CACV,+BAA+B,IAAI,2BAA2B,aAAa,CAAC,IAAI,gBAAgB,CACjG,CAAA;oBACD,iEAAiE;oBACjE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;gBACjC,CAAC;YACH,CAAC;YACD,MAAK;QACP;YACE,MAAM,IAAI,KAAK,CAAC,6CAA6C,SAAS,GAAG,CAAC,CAAA;IAC9E,CAAC;IACD,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,sBAAsB,QAAQ,4BAA4B,CAAC,CAAA;IAC7E,CAAC;IACD,OAAO,WAAW,CAAA;AACpB,CAAC;AAED,KAAK,UAAU,eAAe,CAAC,QAAgB;IAC7C,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAA;IACzD,MAAM,aAAa,GAAG,MAAM,aAAa,CAAC,EAAE,GAAG,EAAE,mBAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IAC1E,OAAO,aAAa,EAAE,WAAW,CAAA;AACnC,CAAC","sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport { promisify } from 'node:util'\nimport { pathToFileURL } from 'node:url'\nimport YAML from 'yaml'\nimport { ILogger } from '../environment'\nimport { IConfiguration } from './types'\nimport { mergeConfigurations } from './merge_configurations'\nimport { parseConfiguration } from './parse_configuration'\n\nexport async function fromFile(\n logger: ILogger,\n cwd: string,\n file: string,\n profiles: string[] = []\n): Promise<Partial<IConfiguration>> {\n let definitions = await loadFile(logger, cwd, file)\n\n const defaultDefinition: unknown = definitions.default\n\n if (defaultDefinition) {\n if (typeof defaultDefinition === 'function') {\n logger.debug('Default function found; loading profiles')\n definitions = await handleDefaultFunctionDefinition(\n definitions,\n defaultDefinition\n )\n }\n } else {\n logger.debug('No default profile defined in configuration file')\n definitions.default = {}\n }\n\n if (profiles.length < 1) {\n logger.debug('No profiles specified; using default profile')\n profiles = ['default']\n }\n\n const definedKeys = Object.keys(definitions)\n profiles.forEach((profileKey) => {\n if (!definedKeys.includes(profileKey)) {\n throw new Error(`Requested profile \"${profileKey}\" doesn't exist`)\n }\n })\n return mergeConfigurations(\n {},\n ...profiles.map((profileKey) =>\n parseConfiguration(\n logger,\n `Profile \"${profileKey}\"`,\n definitions[profileKey]\n )\n )\n )\n}\n\nasync function handleDefaultFunctionDefinition(\n definitions: Record<string, any>,\n defaultDefinition: Function\n): Promise<Record<string, any>> {\n if (Object.keys(definitions).length > 1) {\n throw new Error(\n 'Invalid profiles specified: if a default function definition is provided, no other static profiles should be specified'\n )\n }\n\n const definitionsFromDefault = await defaultDefinition()\n\n return {\n default: {},\n ...definitionsFromDefault,\n }\n}\n\nasync function loadFile(\n logger: ILogger,\n cwd: string,\n file: string\n): Promise<Record<string, any>> {\n const filePath: string = path.join(cwd, file)\n const extension = path.extname(filePath)\n let definitions\n switch (extension) {\n case '.json':\n definitions = JSON.parse(\n await promisify(fs.readFile)(filePath, { encoding: 'utf-8' })\n )\n break\n case '.yaml':\n case '.yml':\n definitions = YAML.parse(\n await promisify(fs.readFile)(filePath, { encoding: 'utf-8' })\n )\n break\n case '.cjs':\n logger.debug(\n `Loading configuration file \"${file}\" as CommonJS based on extension`\n )\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n definitions = require(filePath)\n break\n case '.mjs':\n logger.debug(\n `Loading configuration file \"${file}\" as ESM based on extension`\n )\n definitions = await import(pathToFileURL(filePath).toString())\n break\n case '.js':\n {\n const parentPackage = await readPackageJson(filePath)\n if (!parentPackage) {\n logger.debug(\n `Loading configuration file \"${file}\" as CommonJS based on absence of a parent package`\n )\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n definitions = require(filePath)\n } else if (parentPackage.type === 'module') {\n logger.debug(\n `Loading configuration file \"${file}\" as ESM based on \"${parentPackage.name}\" package type`\n )\n definitions = await import(pathToFileURL(filePath).toString())\n } else {\n logger.debug(\n `Loading configuration file \"${file}\" as CommonJS based on \"${parentPackage.name}\" package type`\n )\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n definitions = require(filePath)\n }\n }\n break\n default:\n throw new Error(`Unsupported configuration file extension \"${extension}\"`)\n }\n if (typeof definitions !== 'object') {\n throw new Error(`Configuration file ${filePath} does not export an object`)\n }\n return definitions\n}\n\nasync function readPackageJson(filePath: string) {\n const { readPackageUp } = await import('read-package-up')\n const parentPackage = await readPackageUp({ cwd: path.dirname(filePath) })\n return parentPackage?.packageJson\n}\n"]}
1
+ {"version":3,"file":"from_file.js","sourceRoot":"","sources":["../../src/configuration/from_file.ts"],"names":[],"mappings":";;;;;AAsBA,4BA4CC;AAlED,sDAAwB;AACxB,0DAA4B;AAC5B,yCAAqC;AACrC,uCAAwC;AACxC,gDAAuB;AAGvB,iEAA4D;AAC5D,+DAA0D;AAE1D,MAAM,oBAAoB,GAAG;IAC3B,OAAO;IACP,OAAO;IACP,MAAM;IACN,KAAK;IACL,MAAM;IACN,MAAM;IACN,KAAK;IACL,MAAM;IACN,MAAM;CACP,CAAA;AAEM,KAAK,UAAU,QAAQ,CAC5B,MAAe,EACf,GAAW,EACX,IAAY,EACZ,WAAqB,EAAE;IAEvB,IAAI,WAAW,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;IAEnD,MAAM,iBAAiB,GAAY,WAAW,CAAC,OAAO,CAAA;IAEtD,IAAI,iBAAiB,EAAE,CAAC;QACtB,IAAI,OAAO,iBAAiB,KAAK,UAAU,EAAE,CAAC;YAC5C,MAAM,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAA;YACxD,WAAW,GAAG,MAAM,+BAA+B,CACjD,WAAW,EACX,iBAAiB,CAClB,CAAA;QACH,CAAC;IAC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CAAC,CAAA;IAC7E,CAAC;IACD,OAAO,WAAW,CAAA;AACpB,CAAC;AAED,KAAK,UAAU,eAAe,CAAC,QAAgB;IAC7C,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAA;IACzD,MAAM,aAAa,GAAG,MAAM,aAAa,CAAC,EAAE,GAAG,EAAE,mBAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IAC1E,OAAO,aAAa,EAAE,WAAW,CAAA;AACnC,CAAC","sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport { promisify } from 'node:util'\nimport { pathToFileURL } from 'node:url'\nimport YAML from 'yaml'\nimport { ILogger } from '../environment'\nimport { IConfiguration } from './types'\nimport { mergeConfigurations } from './merge_configurations'\nimport { parseConfiguration } from './parse_configuration'\n\nconst SUPPORTED_EXTENSIONS = [\n '.json',\n '.yaml',\n '.yml',\n '.js',\n '.cjs',\n '.mjs',\n '.ts',\n '.cts',\n '.mts',\n]\n\nexport async function fromFile(\n logger: ILogger,\n cwd: string,\n file: string,\n profiles: string[] = []\n): Promise<Partial<IConfiguration>> {\n let definitions = await loadFile(logger, cwd, file)\n\n const defaultDefinition: unknown = definitions.default\n\n if (defaultDefinition) {\n if (typeof defaultDefinition === 'function') {\n logger.debug('Default function found; loading profiles')\n definitions = await handleDefaultFunctionDefinition(\n definitions,\n defaultDefinition\n )\n }\n } else {\n logger.debug('No default profile defined in configuration file')\n definitions.default = {}\n }\n\n if (profiles.length < 1) {\n logger.debug('No profiles specified; using default profile')\n profiles = ['default']\n }\n\n const definedKeys = Object.keys(definitions)\n profiles.forEach((profileKey) => {\n if (!definedKeys.includes(profileKey)) {\n throw new Error(`Requested profile \"${profileKey}\" doesn't exist`)\n }\n })\n return mergeConfigurations(\n {},\n ...profiles.map((profileKey) =>\n parseConfiguration(\n logger,\n `Profile \"${profileKey}\"`,\n definitions[profileKey]\n )\n )\n )\n}\n\nasync function handleDefaultFunctionDefinition(\n definitions: Record<string, any>,\n defaultDefinition: Function\n): Promise<Record<string, any>> {\n if (Object.keys(definitions).length > 1) {\n throw new Error(\n 'Invalid profiles specified: if a default function definition is provided, no other static profiles should be specified'\n )\n }\n\n const definitionsFromDefault = await defaultDefinition()\n\n return {\n default: {},\n ...definitionsFromDefault,\n }\n}\n\nasync function loadFile(\n logger: ILogger,\n cwd: string,\n file: string\n): Promise<Record<string, any>> {\n const filePath: string = path.join(cwd, file)\n const extension = path.extname(filePath)\n if (!SUPPORTED_EXTENSIONS.includes(extension)) {\n throw new Error(`Unsupported configuration file extension \"${extension}\"`)\n }\n let definitions\n try {\n switch (extension) {\n case '.json':\n definitions = JSON.parse(\n await promisify(fs.readFile)(filePath, { encoding: 'utf-8' })\n )\n break\n case '.yaml':\n case '.yml':\n definitions = YAML.parse(\n await promisify(fs.readFile)(filePath, { encoding: 'utf-8' })\n )\n break\n case '.cjs':\n logger.debug(\n `Loading configuration file \"${file}\" as CommonJS based on extension`\n )\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n definitions = require(filePath)\n break\n case '.cts':\n logger.debug(\n `Loading configuration file \"${file}\" as TypeScript based on extension`\n )\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n definitions = require(filePath)\n break\n case '.mjs':\n logger.debug(\n `Loading configuration file \"${file}\" as ESM based on extension`\n )\n definitions = await import(pathToFileURL(filePath).toString())\n break\n case '.mts':\n case '.ts':\n logger.debug(\n `Loading configuration file \"${file}\" as TypeScript based on extension`\n )\n definitions = await import(pathToFileURL(filePath).toString())\n break\n case '.js':\n {\n const parentPackage = await readPackageJson(filePath)\n if (!parentPackage) {\n logger.debug(\n `Loading configuration file \"${file}\" as CommonJS based on absence of a parent package`\n )\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n definitions = require(filePath)\n } else if (parentPackage.type === 'module') {\n logger.debug(\n `Loading configuration file \"${file}\" as ESM based on \"${parentPackage.name}\" package type`\n )\n definitions = await import(pathToFileURL(filePath).toString())\n } else {\n logger.debug(\n `Loading configuration file \"${file}\" as CommonJS based on \"${parentPackage.name}\" package type`\n )\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n definitions = require(filePath)\n }\n }\n break\n }\n } catch (error) {\n throw new Error(`Configuration file \"${file}\" failed to load/parse`, {\n cause: error,\n })\n }\n\n if (typeof definitions !== 'object') {\n throw new Error(`Configuration file ${filePath} does not export an object`)\n }\n return definitions\n}\n\nasync function readPackageJson(filePath: string) {\n const { readPackageUp } = await import('read-package-up')\n const parentPackage = await readPackageUp({ cwd: path.dirname(filePath) })\n return parentPackage?.packageJson\n}\n"]}
@@ -62,6 +62,26 @@ export interface IConfiguration {
62
62
  * The value must be a JSON-serializable object.
63
63
  */
64
64
  formatOptions: JsonObject;
65
+ /**
66
+ * Name/path of each plugin to use
67
+ *
68
+ * @example
69
+ * [
70
+ * "\@cucumber/my-plugin",
71
+ * "./custom-plugin.js"
72
+ * ]
73
+ * @default []
74
+ * @remarks
75
+ * Each item is a module specifier for a plugin to be loaded.
76
+ */
77
+ plugin: string[];
78
+ /**
79
+ * Options to be provided to plugins
80
+ * @default \{\}
81
+ * @remarks
82
+ * The value must be a JSON-serializable object.
83
+ */
84
+ pluginOptions: JsonObject;
65
85
  /**
66
86
  * Paths to where your support code is
67
87
  * @default []
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/configuration/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonObject } from 'type-fest'\nimport { IPickleOrder } from '../filter'\n\n/**\n * User-defined configuration\n *\n * @public\n */\nexport interface IConfiguration {\n /**\n * Paths to where your feature files are\n * @default []\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/configuration.md#finding-your-features}\n */\n paths: string[]\n /**\n * Show the full backtrace for errors\n * @default false\n */\n backtrace: boolean\n /**\n * Perform a dry run, where a test run is prepared but nothing is executed\n * @default false\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/dry_run.md}\n */\n dryRun: boolean\n /**\n * Explicitly call `process.exit()` after the test run\n * @default false\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/cli.md#exiting}\n * @remarks\n * This option is only used by the CLI.\n */\n forceExit: boolean\n /**\n * Stop running tests when a test fails\n * @default false\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/fail_fast.md}\n */\n failFast: boolean\n /**\n * Name/path and (optionally) output file path of each formatter to use\n *\n * @example\n * [\n * \"\\@cucumber/pretty-formatter\",\n * [\"html\", \"./reports/cucumber.html\"],\n * [\"./custom-formatter.js\", \"./reports/custom.txt\"]\n * ]\n * @default []\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/formatters.md}\n * @remarks\n * Each item has one or two values. The first (required) identifies the\n * formatter to be used. The second (optional) specifies where the output\n * should be written.\n */\n format: Array<string | [string, string?]>\n /**\n * Options to be provided to formatters\n * @default \\{\\}\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/formatters.md#options}\n * @remarks\n * The value must be a JSON-serializable object.\n */\n formatOptions: JsonObject\n /**\n * Paths to where your support code is\n * @default []\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/configuration.md#finding-your-code}\n */\n import: string[]\n /**\n * Default language for your feature files\n * @default \"en\"\n */\n language: string\n /**\n * Module specifier(s) for loaders to be registered ahead of loading support code\n * @default []\n */\n loader: string[]\n /**\n * Regular expressions of which scenario names should match one of to be run\n * @default []\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/filtering.md#names}\n */\n name: string[]\n /**\n * Run in the order defined, or in a random order\n * @default \"defined\"\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/filtering.md#order}\n */\n order: IPickleOrder\n /**\n * Run tests in parallel with the given number of worker processes\n * @default 0\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/parallel.md}\n */\n parallel: number\n /**\n * Shard tests and execute only the selected shard, format `<index>/<total>`\n * @default \"\"\n */\n shard: string\n /**\n * Publish a report of your test run to https://reports.cucumber.io/\n * @default false\n */\n publish: boolean\n /**\n * Paths to where your support code is, for CommonJS\n * @default []\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/configuration.md#finding-your-code}\n */\n require: string[]\n /**\n * Names of transpilation modules to load, via `require()`\n * @default []\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/transpiling.md}\n */\n requireModule: string[]\n /**\n * Retry failing tests up to the given number of times\n * @default 0\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/retry.md}\n */\n retry: number\n /**\n * Tag expression to filter which scenarios can be retried\n * @default \"\"\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/retry.md}\n */\n retryTagFilter: string\n /**\n * Fail the test run if there are pending steps\n * @default true\n */\n strict: boolean\n /**\n * Tag expression to filter which scenarios should be run\n * @default \"\"\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/filtering.md#tags}\n */\n tags: string\n /**\n * Parameters to be passed to your World\n * @default \\{\\}\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/world.md}\n * @remarks\n * The value must be a JSON-serializable object.\n */\n worldParameters: JsonObject\n}\n\n/**\n * Collection of named configuration profiles\n * @public\n */\nexport type IProfiles = Record<string, Partial<IConfiguration>>\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/configuration/types.ts"],"names":[],"mappings":"","sourcesContent":["import { JsonObject } from 'type-fest'\nimport { IPickleOrder } from '../filter'\n\n/**\n * User-defined configuration\n *\n * @public\n */\nexport interface IConfiguration {\n /**\n * Paths to where your feature files are\n * @default []\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/configuration.md#finding-your-features}\n */\n paths: string[]\n /**\n * Show the full backtrace for errors\n * @default false\n */\n backtrace: boolean\n /**\n * Perform a dry run, where a test run is prepared but nothing is executed\n * @default false\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/dry_run.md}\n */\n dryRun: boolean\n /**\n * Explicitly call `process.exit()` after the test run\n * @default false\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/cli.md#exiting}\n * @remarks\n * This option is only used by the CLI.\n */\n forceExit: boolean\n /**\n * Stop running tests when a test fails\n * @default false\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/fail_fast.md}\n */\n failFast: boolean\n /**\n * Name/path and (optionally) output file path of each formatter to use\n *\n * @example\n * [\n * \"\\@cucumber/pretty-formatter\",\n * [\"html\", \"./reports/cucumber.html\"],\n * [\"./custom-formatter.js\", \"./reports/custom.txt\"]\n * ]\n * @default []\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/formatters.md}\n * @remarks\n * Each item has one or two values. The first (required) identifies the\n * formatter to be used. The second (optional) specifies where the output\n * should be written.\n */\n format: Array<string | [string, string?]>\n /**\n * Options to be provided to formatters\n * @default \\{\\}\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/formatters.md#options}\n * @remarks\n * The value must be a JSON-serializable object.\n */\n formatOptions: JsonObject\n /**\n * Name/path of each plugin to use\n *\n * @example\n * [\n * \"\\@cucumber/my-plugin\",\n * \"./custom-plugin.js\"\n * ]\n * @default []\n * @remarks\n * Each item is a module specifier for a plugin to be loaded.\n */\n plugin: string[]\n /**\n * Options to be provided to plugins\n * @default \\{\\}\n * @remarks\n * The value must be a JSON-serializable object.\n */\n pluginOptions: JsonObject\n /**\n * Paths to where your support code is\n * @default []\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/configuration.md#finding-your-code}\n */\n import: string[]\n /**\n * Default language for your feature files\n * @default \"en\"\n */\n language: string\n /**\n * Module specifier(s) for loaders to be registered ahead of loading support code\n * @default []\n */\n loader: string[]\n /**\n * Regular expressions of which scenario names should match one of to be run\n * @default []\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/filtering.md#names}\n */\n name: string[]\n /**\n * Run in the order defined, or in a random order\n * @default \"defined\"\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/filtering.md#order}\n */\n order: IPickleOrder\n /**\n * Run tests in parallel with the given number of worker processes\n * @default 0\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/parallel.md}\n */\n parallel: number\n /**\n * Shard tests and execute only the selected shard, format `<index>/<total>`\n * @default \"\"\n */\n shard: string\n /**\n * Publish a report of your test run to https://reports.cucumber.io/\n * @default false\n */\n publish: boolean\n /**\n * Paths to where your support code is, for CommonJS\n * @default []\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/configuration.md#finding-your-code}\n */\n require: string[]\n /**\n * Names of transpilation modules to load, via `require()`\n * @default []\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/transpiling.md}\n */\n requireModule: string[]\n /**\n * Retry failing tests up to the given number of times\n * @default 0\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/retry.md}\n */\n retry: number\n /**\n * Tag expression to filter which scenarios can be retried\n * @default \"\"\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/retry.md}\n */\n retryTagFilter: string\n /**\n * Fail the test run if there are pending steps\n * @default true\n */\n strict: boolean\n /**\n * Tag expression to filter which scenarios should be run\n * @default \"\"\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/filtering.md#tags}\n */\n tags: string\n /**\n * Parameters to be passed to your World\n * @default \\{\\}\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/world.md}\n * @remarks\n * The value must be a JSON-serializable object.\n */\n worldParameters: JsonObject\n}\n\n/**\n * Collection of named configuration profiles\n * @public\n */\nexport type IProfiles = Record<string, Partial<IConfiguration>>\n"]}
@@ -8,4 +8,5 @@ export declare class ConsoleLogger implements ILogger {
8
8
  debug(message?: any, ...optionalParams: any[]): void;
9
9
  error(message?: any, ...optionalParams: any[]): void;
10
10
  warn(message?: any, ...optionalParams: any[]): void;
11
+ info(message?: any, ...optionalParams: any[]): void;
11
12
  }