@cucumber/cucumber 10.1.0 → 10.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +2 -2
  2. package/lib/api/convert_configuration.js.map +1 -1
  3. package/lib/api/environment.d.ts +6 -1
  4. package/lib/api/environment.js +6 -1
  5. package/lib/api/environment.js.map +1 -1
  6. package/lib/api/formatters.d.ts +2 -2
  7. package/lib/api/formatters.js.map +1 -1
  8. package/lib/api/index.d.ts +6 -2
  9. package/lib/api/index.js +4 -2
  10. package/lib/api/index.js.map +1 -1
  11. package/lib/api/load_configuration.d.ts +3 -3
  12. package/lib/api/load_configuration.js +9 -9
  13. package/lib/api/load_configuration.js.map +1 -1
  14. package/lib/api/load_sources.d.ts +4 -3
  15. package/lib/api/load_sources.js +5 -6
  16. package/lib/api/load_sources.js.map +1 -1
  17. package/lib/api/load_support.d.ts +4 -5
  18. package/lib/api/load_support.js +4 -6
  19. package/lib/api/load_support.js.map +1 -1
  20. package/lib/api/run_cucumber.d.ts +5 -5
  21. package/lib/api/run_cucumber.js +16 -18
  22. package/lib/api/run_cucumber.js.map +1 -1
  23. package/lib/api/runtime.d.ts +2 -2
  24. package/lib/api/runtime.js.map +1 -1
  25. package/lib/api/support.d.ts +2 -2
  26. package/lib/api/support.js.map +1 -1
  27. package/lib/api/types.d.ts +179 -27
  28. package/lib/api/types.js.map +1 -1
  29. package/lib/cli/helpers.d.ts +4 -4
  30. package/lib/cli/helpers.js.map +1 -1
  31. package/lib/configuration/check_schema.js +2 -2
  32. package/lib/configuration/check_schema.js.map +1 -1
  33. package/lib/configuration/from_file.js +2 -21
  34. package/lib/configuration/from_file.js.map +1 -1
  35. package/lib/configuration/index.d.ts +2 -0
  36. package/lib/configuration/index.js +2 -0
  37. package/lib/configuration/index.js.map +1 -1
  38. package/lib/configuration/parse_configuration.d.ts +3 -0
  39. package/lib/configuration/parse_configuration.js +31 -0
  40. package/lib/configuration/parse_configuration.js.map +1 -0
  41. package/lib/configuration/types.d.ts +125 -9
  42. package/lib/configuration/types.js.map +1 -1
  43. package/lib/filter/types.d.ts +8 -0
  44. package/lib/filter/types.js.map +1 -1
  45. package/lib/formatter/builder.d.ts +3 -3
  46. package/lib/formatter/builder.js.map +1 -1
  47. package/lib/formatter/helpers/issue_helpers.d.ts +2 -2
  48. package/lib/formatter/helpers/issue_helpers.js.map +1 -1
  49. package/lib/formatter/helpers/test_case_attempt_formatter.d.ts +2 -2
  50. package/lib/formatter/helpers/test_case_attempt_formatter.js.map +1 -1
  51. package/lib/formatter/helpers/test_case_attempt_parser.d.ts +2 -2
  52. package/lib/formatter/helpers/test_case_attempt_parser.js.map +1 -1
  53. package/lib/formatter/index.d.ts +3 -7
  54. package/lib/formatter/index.js.map +1 -1
  55. package/lib/index.d.ts +13 -5
  56. package/lib/index.js +16 -7
  57. package/lib/index.js.map +1 -1
  58. package/lib/publish/index.d.ts +1 -0
  59. package/lib/publish/index.js +15 -0
  60. package/lib/publish/index.js.map +1 -1
  61. package/lib/publish/publish_plugin.d.ts +1 -1
  62. package/lib/publish/publish_plugin.js.map +1 -1
  63. package/lib/publish/types.d.ts +14 -0
  64. package/lib/{models/pickle_order.js → publish/types.js} +1 -1
  65. package/lib/publish/types.js.map +1 -0
  66. package/lib/runtime/assemble_test_cases.d.ts +2 -2
  67. package/lib/runtime/assemble_test_cases.js.map +1 -1
  68. package/lib/runtime/format_error.js +14 -11
  69. package/lib/runtime/format_error.js.map +1 -1
  70. package/lib/runtime/index.d.ts +2 -2
  71. package/lib/runtime/index.js.map +1 -1
  72. package/lib/runtime/parallel/coordinator.d.ts +2 -2
  73. package/lib/runtime/parallel/coordinator.js.map +1 -1
  74. package/lib/runtime/parallel/worker.js.map +1 -1
  75. package/lib/runtime/test_case_runner.d.ts +2 -2
  76. package/lib/runtime/test_case_runner.js.map +1 -1
  77. package/lib/support_code_library_builder/index.d.ts +2 -2
  78. package/lib/support_code_library_builder/index.js.map +1 -1
  79. package/lib/support_code_library_builder/types.d.ts +1 -1
  80. package/lib/support_code_library_builder/types.js.map +1 -1
  81. package/lib/version.d.ts +1 -1
  82. package/lib/version.js +1 -1
  83. package/lib/version.js.map +1 -1
  84. package/lib/wrapper.mjs +2 -1
  85. package/package.json +13 -8
  86. package/lib/models/pickle_order.d.ts +0 -1
  87. package/lib/models/pickle_order.js.map +0 -1
@@ -1,55 +1,92 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  import { Writable } from 'node:stream';
4
- import { ISupportCodeLibrary } from '../support_code_library_builder/types';
5
- import { FormatOptions, IPublishConfig } from '../formatter';
6
- import { PickleOrder } from '../models/pickle_order';
7
- import { IRuntimeOptions } from '../runtime';
4
+ import { JsonObject } from 'type-fest';
5
+ import { IPublishConfig } from '../publish';
8
6
  import { IConfiguration } from '../configuration';
7
+ import { IPickleOrder } from '../filter';
9
8
  /**
9
+ * Options for {@link loadConfiguration}
10
10
  * @public
11
11
  */
12
12
  export interface ILoadConfigurationOptions {
13
13
  /**
14
- * Path to load configuration file from (defaults to `cucumber.(js|cjs|mjs|json)` if omitted).
14
+ * Path to load configuration file from, or `false` to skip
15
+ * @default `cucumber.(json|yaml|yml|js|cjs|mjs)`
15
16
  */
16
- file?: string;
17
+ file?: string | false;
17
18
  /**
18
- * Zero or more profile names from which to source configuration (if omitted or empty, the `default` profile will be used).
19
+ * Zero or more profile names from which to source configuration in the file
20
+ * @remarks
21
+ * If omitted or empty, the `default` profile will be used.
19
22
  */
20
23
  profiles?: string[];
21
24
  /**
22
- * Ad-hoc configuration options to be applied over the top of whatever is loaded from the configuration file/profiles.
25
+ * Ad-hoc configuration options to be merged over the top of whatever is
26
+ * loaded from the configuration file/profiles
27
+ * @example
28
+ * \{
29
+ * failFast: true,
30
+ * parallel: 2
31
+ * \}
32
+ * @example "--fail-fast --parallel 2"
33
+ * @remarks
34
+ * This can also be provided as a string of argv-style arguments.
23
35
  */
24
- provided?: Partial<IConfiguration>;
36
+ provided?: Partial<IConfiguration> | string;
25
37
  }
26
38
  /**
39
+ * Response from {@link loadConfiguration}
27
40
  * @public
28
41
  */
29
42
  export interface IResolvedConfiguration {
30
43
  /**
31
- * The final flat configuration object resolved from the configuration file/profiles plus any extra provided.
44
+ * The final flat configuration object resolved from the configuration
45
+ * file/profiles plus any extra provided
32
46
  */
33
47
  useConfiguration: IConfiguration;
34
48
  /**
35
- * The format that can be passed into `runCucumber`.
49
+ * The format that can be passed into {@link runCucumber}
36
50
  */
37
51
  runConfiguration: IRunConfiguration;
38
52
  }
39
53
  /**
54
+ * Options relating to sources (i.e. feature files) - where to load them from,
55
+ * how to interpret, filter and order them
40
56
  * @public
41
57
  */
42
58
  export interface ISourcesCoordinates {
59
+ /**
60
+ * Default Gherkin dialect
61
+ * @remarks
62
+ * Used if no dialect is specified in the feature file itself.
63
+ */
43
64
  defaultDialect: string;
65
+ /**
66
+ * Paths and/or glob expressions to feature files
67
+ */
44
68
  paths: string[];
69
+ /**
70
+ * Regular expressions of which scenario names should match one of to be run
71
+ */
45
72
  names: string[];
73
+ /**
74
+ * Tag expression to filter which scenarios should be run
75
+ */
46
76
  tagExpression: string;
47
- order: PickleOrder;
77
+ /**
78
+ * Run in the order defined, or in a random order
79
+ */
80
+ order: IPickleOrder;
48
81
  }
49
82
  /**
83
+ * A pickle that has been successfully compiled from a source
50
84
  * @public
51
85
  */
52
86
  export interface IPlannedPickle {
87
+ /**
88
+ * Name of the pickle (after parameter resolution)
89
+ */
53
90
  name: string;
54
91
  uri: string;
55
92
  location: {
@@ -58,6 +95,7 @@ export interface IPlannedPickle {
58
95
  };
59
96
  }
60
97
  /**
98
+ * An error encountered when parsing a source
61
99
  * @public
62
100
  */
63
101
  export interface ISourcesError {
@@ -66,46 +104,133 @@ export interface ISourcesError {
66
104
  line: number;
67
105
  column?: number;
68
106
  };
107
+ /**
108
+ * Error message explaining what went wrong with the parse
109
+ */
69
110
  message: string;
70
111
  }
71
112
  /**
113
+ * Response from {@link loadSources}
72
114
  * @public
73
115
  */
74
116
  export interface ILoadSourcesResult {
117
+ /**
118
+ * Pickles that have been successfully compiled, in the order they would be
119
+ * run in
120
+ */
75
121
  plan: IPlannedPickle[];
122
+ /**
123
+ * Any errors encountered when parsing sources
124
+ */
76
125
  errors: ISourcesError[];
77
126
  }
78
127
  /**
128
+ * Options relating to user code (aka support code) - where to load it from and
129
+ * how to preprocess it
79
130
  * @public
80
131
  */
81
132
  export interface ISupportCodeCoordinates {
133
+ /**
134
+ * Names of transpilation modules to load, via `require()`
135
+ */
82
136
  requireModules: string[];
137
+ /**
138
+ * Paths and/or glob expressions of user code to load, via `require()`
139
+ */
83
140
  requirePaths: string[];
141
+ /**
142
+ * Paths and/or glob expressions of user code to load, via `import()`
143
+ */
84
144
  importPaths: string[];
85
145
  }
86
146
  /**
147
+ * Options for {@link loadSupport}
87
148
  * @public
149
+ * @remarks
150
+ * A subset of {@link IRunConfiguration}
88
151
  */
89
152
  export interface ILoadSupportOptions {
153
+ /**
154
+ * @remarks
155
+ * This is needed because the default support path locations are derived from
156
+ * feature file locations.
157
+ */
90
158
  sources: ISourcesCoordinates;
91
159
  support: ISupportCodeCoordinates;
92
160
  }
93
161
  /**
162
+ * Options relating to behaviour when actually running tests
94
163
  * @public
95
164
  */
96
- export interface IRunOptionsRuntime extends IRuntimeOptions {
165
+ export interface IRunOptionsRuntime {
166
+ /**
167
+ * Perform a dry run, where a test run is prepared but nothing is executed
168
+ */
169
+ dryRun: boolean;
170
+ /**
171
+ * Stop running tests when a test fails
172
+ */
173
+ failFast: boolean;
174
+ /**
175
+ * Filter out stack frames from Cucumber's code when formatting stack traces
176
+ */
177
+ filterStacktraces: boolean;
178
+ /**
179
+ * Run tests in parallel with the given number of worker processes
180
+ */
97
181
  parallel: number;
182
+ /**
183
+ * Retry failing tests up to the given number of times
184
+ */
185
+ retry: number;
186
+ /**
187
+ * Tag expression to filter which scenarios can be retried
188
+ */
189
+ retryTagFilter: string;
190
+ /**
191
+ * Fail the test run if there are pending steps
192
+ */
193
+ strict: boolean;
194
+ /**
195
+ * Parameters to be passed to the World
196
+ * @remarks
197
+ * The value must be a JSON-serializable object.
198
+ */
199
+ worldParameters: JsonObject;
98
200
  }
99
201
  /**
202
+ * Options relating to formatters - which ones to use, where to write their
203
+ * output, how they should behave
100
204
  * @public
101
205
  */
102
206
  export interface IRunOptionsFormats {
207
+ /**
208
+ * Name/path of the formatter to use for `stdout` output
209
+ */
103
210
  stdout: string;
211
+ /**
212
+ * Zero or more mappings of file output path (key) to name/path of the
213
+ * formatter to use (value)
214
+ * @example
215
+ * \{
216
+ * "./reports/cucumber.html": "html",
217
+ * "./reports/custom.txt": "./custom-formatter.js"
218
+ * \}
219
+ */
104
220
  files: Record<string, string>;
221
+ /**
222
+ * Options for report publication, or `false` to disable publication
223
+ */
105
224
  publish: IPublishConfig | false;
106
- options: FormatOptions;
225
+ /**
226
+ * Options to be provided to formatters
227
+ * @remarks
228
+ * The value must be a JSON-serializable object.
229
+ */
230
+ options: JsonObject;
107
231
  }
108
232
  /**
233
+ * Structured configuration object suitable for passing to {@link runCucumber}
109
234
  * @public
110
235
  */
111
236
  export interface IRunConfiguration {
@@ -115,14 +240,32 @@ export interface IRunConfiguration {
115
240
  formats: IRunOptionsFormats;
116
241
  }
117
242
  /**
243
+ * A collection of user-defined code and setup ("support code") that can be
244
+ * used for a test run
118
245
  * @public
246
+ * @remarks
247
+ * This is mostly a marker interface. The actual instance is a complex object
248
+ * that you shouldn't interact with directly, but some functions return and/or
249
+ * accept it as a means of optimising a test workflow.
119
250
  */
120
- export type ISupportCodeCoordinatesOrLibrary = ISupportCodeCoordinates | ISupportCodeLibrary;
251
+ export interface ISupportCodeLibrary {
252
+ readonly originalCoordinates: ISupportCodeCoordinates;
253
+ }
121
254
  /**
255
+ * Either an actual {@link ISupportCodeLibrary | support code library}, or the
256
+ * {@link ISupportCodeCoordinates | coordinates} required to create and
257
+ * populate one
122
258
  * @public
259
+ * @remarks
260
+ * This alias exists because {@link runCucumber} will accept an existing
261
+ * support code library in its options and thus avoid trying to load it again,
262
+ * improving performance and avoiding cache issues for use cases where multiple
263
+ * test runs happen within the same process. Note this is only useful in serial
264
+ * mode, as parallel workers will each load the support code themselves anyway.
123
265
  */
124
- export type { ISupportCodeLibrary };
266
+ export type ISupportCodeCoordinatesOrLibrary = ISupportCodeCoordinates | ISupportCodeLibrary;
125
267
  /**
268
+ * Options for {@link runCucumber}
126
269
  * @public
127
270
  */
128
271
  export interface IRunOptions {
@@ -132,44 +275,53 @@ export interface IRunOptions {
132
275
  formats: IRunOptionsFormats;
133
276
  }
134
277
  /**
135
- * Contextual data about the project environment.
136
- *
278
+ * Contextual data about the project environment
137
279
  * @public
138
280
  */
139
281
  export interface IRunEnvironment {
140
282
  /**
141
- * Working directory for the project (defaults to `process.cwd()` if omitted).
283
+ * Working directory for the project
284
+ * @default process.cwd()
142
285
  */
143
286
  cwd?: string;
144
287
  /**
145
- * Writable stream where the test run's main output is written (defaults to `process.stdout` if omitted).
288
+ * Writable stream where the test run's main formatter output is written
289
+ * @default process.stdout
146
290
  */
147
291
  stdout?: Writable;
148
292
  /**
149
- * Writable stream where the test run's warning/error output is written (defaults to `process.stderr` if omitted).
293
+ * Writable stream where the test run's warning/error output is written
294
+ * @default process.stderr
150
295
  */
151
296
  stderr?: Writable;
152
297
  /**
153
- * Environment variables (defaults to `process.env` if omitted).
298
+ * Environment variables
299
+ * @default process.env
154
300
  */
155
301
  env?: NodeJS.ProcessEnv;
156
302
  /**
157
- * Whether debug logging is enabled.
303
+ * Whether debug logging should be emitted to {@link IRunEnvironment.stderr}
304
+ * @default false
305
+ * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/debugging.md}
158
306
  */
159
307
  debug?: boolean;
160
308
  }
161
309
  /**
162
- * Result of a Cucumber test run.
163
- *
310
+ * Response from {@link runCucumber}
164
311
  * @public
165
312
  */
166
313
  export interface IRunResult {
167
314
  /**
168
- * Whether the test run was overall successful i.e. no failed scenarios. The exact meaning can vary based on the `strict` configuration option.
315
+ * Whether the test run was overall successful
316
+ * @remarks
317
+ * The exact meaning can vary based on the `strict` configuration option.
169
318
  */
170
319
  success: boolean;
171
320
  /**
172
- * The support code library that was used in the test run; can be reused in subsequent `runCucumber` calls.
321
+ * The support code library that was used in the test run
322
+ * @remarks
323
+ * This can be reused in subsequent {@link runCucumber} calls,
324
+ * see {@link ISupportCodeCoordinatesOrLibrary}
173
325
  */
174
326
  support: ISupportCodeLibrary;
175
327
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Writable } from 'node:stream'\nimport { ISupportCodeLibrary } from '../support_code_library_builder/types'\nimport { FormatOptions, IPublishConfig } from '../formatter'\nimport { PickleOrder } from '../models/pickle_order'\nimport { IRuntimeOptions } from '../runtime'\nimport { IConfiguration } from '../configuration'\n\n/**\n * @public\n */\nexport interface ILoadConfigurationOptions {\n /**\n * Path to load configuration file from (defaults to `cucumber.(js|cjs|mjs|json)` if omitted).\n */\n file?: string\n /**\n * Zero or more profile names from which to source configuration (if omitted or empty, the `default` profile will be used).\n */\n profiles?: string[]\n /**\n * Ad-hoc configuration options to be applied over the top of whatever is loaded from the configuration file/profiles.\n */\n provided?: Partial<IConfiguration>\n}\n\n/**\n * @public\n */\nexport interface IResolvedConfiguration {\n /**\n * The final flat configuration object resolved from the configuration file/profiles plus any extra provided.\n */\n useConfiguration: IConfiguration\n /**\n * The format that can be passed into `runCucumber`.\n */\n runConfiguration: IRunConfiguration\n}\n\n/**\n * @public\n */\nexport interface ISourcesCoordinates {\n defaultDialect: string\n paths: string[]\n names: string[]\n tagExpression: string\n order: PickleOrder\n}\n\n/**\n * @public\n */\nexport interface IPlannedPickle {\n name: string\n uri: string\n location: {\n line: number\n column?: number\n }\n}\n\n/**\n * @public\n */\nexport interface ISourcesError {\n uri: string\n location: {\n line: number\n column?: number\n }\n message: string\n}\n\n/**\n * @public\n */\nexport interface ILoadSourcesResult {\n plan: IPlannedPickle[]\n errors: ISourcesError[]\n}\n\n/**\n * @public\n */\nexport interface ISupportCodeCoordinates {\n requireModules: string[]\n requirePaths: string[]\n importPaths: string[]\n}\n\n/**\n * @public\n */\nexport interface ILoadSupportOptions {\n sources: ISourcesCoordinates\n support: ISupportCodeCoordinates\n}\n\n/**\n * @public\n */\nexport interface IRunOptionsRuntime extends IRuntimeOptions {\n parallel: number\n}\n\n/**\n * @public\n */\nexport interface IRunOptionsFormats {\n stdout: string\n files: Record<string, string>\n publish: IPublishConfig | false\n options: FormatOptions\n}\n\n/**\n * @public\n */\nexport interface IRunConfiguration {\n sources: ISourcesCoordinates\n support: ISupportCodeCoordinates\n runtime: IRunOptionsRuntime\n formats: IRunOptionsFormats\n}\n\n/**\n * @public\n */\nexport type ISupportCodeCoordinatesOrLibrary =\n | ISupportCodeCoordinates\n | ISupportCodeLibrary\n\n/**\n * @public\n */\nexport type { ISupportCodeLibrary }\n\n/**\n * @public\n */\nexport interface IRunOptions {\n sources: ISourcesCoordinates\n support: ISupportCodeCoordinatesOrLibrary\n runtime: IRunOptionsRuntime\n formats: IRunOptionsFormats\n}\n\n/**\n * Contextual data about the project environment.\n *\n * @public\n */\nexport interface IRunEnvironment {\n /**\n * Working directory for the project (defaults to `process.cwd()` if omitted).\n */\n cwd?: string\n /**\n * Writable stream where the test run's main output is written (defaults to `process.stdout` if omitted).\n */\n stdout?: Writable\n /**\n * Writable stream where the test run's warning/error output is written (defaults to `process.stderr` if omitted).\n */\n stderr?: Writable\n /**\n * Environment variables (defaults to `process.env` if omitted).\n */\n env?: NodeJS.ProcessEnv\n /**\n * Whether debug logging is enabled.\n */\n debug?: boolean\n}\n\n/**\n * Result of a Cucumber test run.\n *\n * @public\n */\nexport interface IRunResult {\n /**\n * Whether the test run was overall successful i.e. no failed scenarios. 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; can be reused in subsequent `runCucumber` calls.\n */\n support: ISupportCodeLibrary\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Writable } from 'node:stream'\nimport { 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 * @remarks\n * This can also be provided as a string of argv-style arguments.\n */\n provided?: Partial<IConfiguration> | 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\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\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: 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: 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 | 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 * Contextual data about the project environment\n * @public\n */\nexport interface IRunEnvironment {\n /**\n * Working directory for the project\n * @default process.cwd()\n */\n cwd?: string\n /**\n * Writable stream where the test run's main formatter output is written\n * @default process.stdout\n */\n stdout?: Writable\n /**\n * Writable stream where the test run's warning/error output is written\n * @default process.stderr\n */\n stderr?: Writable\n /**\n * Environment variables\n * @default process.env\n */\n env?: NodeJS.ProcessEnv\n /**\n * Whether debug logging should be emitted to {@link IRunEnvironment.stderr}\n * @default false\n * @see {@link https://github.com/cucumber/cucumber-js/blob/main/docs/debugging.md}\n */\n debug?: boolean\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"]}
@@ -6,9 +6,9 @@ import { Readable } from 'node:stream';
6
6
  import { IdGenerator } from '@cucumber/messages';
7
7
  import { EventDataCollector } from '../formatter/helpers';
8
8
  import PickleFilter from '../pickle_filter';
9
- import { ISupportCodeLibrary } from '../support_code_library_builder/types';
10
- import { PickleOrder } from '../models/pickle_order';
9
+ import { SupportCodeLibrary } from '../support_code_library_builder/types';
11
10
  import { ILogger } from '../logger';
11
+ import { IPickleOrder } from '../filter';
12
12
  interface IParseGherkinMessageStreamRequest {
13
13
  cwd?: string;
14
14
  eventBroadcaster: EventEmitter;
@@ -27,11 +27,11 @@ interface IParseGherkinMessageStreamRequest {
27
27
  * @param pickleFilter
28
28
  */
29
29
  export declare function parseGherkinMessageStream({ eventBroadcaster, eventDataCollector, gherkinMessageStream, order, pickleFilter, }: IParseGherkinMessageStreamRequest): Promise<string[]>;
30
- export declare function orderPickles<T = string>(pickleIds: T[], order: PickleOrder, logger: ILogger): void;
30
+ export declare function orderPickles<T = string>(pickleIds: T[], order: IPickleOrder, logger: ILogger): void;
31
31
  export declare function emitMetaMessage(eventBroadcaster: EventEmitter, env: NodeJS.ProcessEnv): Promise<void>;
32
32
  export declare function emitSupportCodeMessages({ eventBroadcaster, supportCodeLibrary, newId, }: {
33
33
  eventBroadcaster: EventEmitter;
34
- supportCodeLibrary: ISupportCodeLibrary;
34
+ supportCodeLibrary: SupportCodeLibrary;
35
35
  newId: IdGenerator.NewId;
36
36
  }): void;
37
37
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/cli/helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,sDAAwB;AACxB,gFAA0C;AAC1C,6DAA8C;AAE9C,8EAA0D;AAC1D,oDAAgD;AAOhD,wCAAoC;AAapC;;;;;;;;GAQG;AACI,KAAK,UAAU,yBAAyB,CAAC,EAC9C,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,EACL,YAAY,GACsB;IAClC,OAAO,MAAM,IAAI,OAAO,CAAW,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrD,MAAM,MAAM,GAAa,EAAE,CAAA;QAC3B,oBAAoB,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,QAA2B,EAAE,EAAE;YAC9D,gBAAgB,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;YAC3C,IAAI,IAAA,6BAAa,EAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;gBAClC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAA;gBAC9B,MAAM,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAA;gBAC1B,MAAM,eAAe,GAAG,kBAAkB,CAAC,kBAAkB,CAC3D,MAAM,CAAC,GAAG,CACX,CAAA;gBACD,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE,eAAe,EAAE,MAAM,EAAE,CAAC,EAAE;oBACrD,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;iBACtB;aACF;QACH,CAAC,CAAC,CAAA;QACF,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YAClC,YAAY,CAAC,MAAM,EAAE,K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AAC,IAAI;gBACjC,aAAa,EAAE,sBAAsB,CAAC,aAAa;gBACnD,eAAe,EAAE,mBAAmB,CAAC,sBAAsB,CAAC;aAC7D;SACF,CAAA;QACD,gBAAgB,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IAC7C,CAAC,CAAC,CAAA;AACN,CAAC;AAED,SAAS,gBAAgB,CACvB,kBAAuC,EACvC,gBAA8B;IAE9B,CAAC;IAAA,EAAE;SACA,MAAM,CACL,kBAAkB,CAAC,4BAA4B,EAC/C,kBAAkB,CAAC,2BAA2B,CAC/C;SACA,OAAO,CAAC,CAAC,qBAA4C,EAAE,EAAE;QACxD,MAAM,QAAQ,GAAsB;YAClC,IAAI,EAAE;gBACJ,EAAE,EAAE,qBAAqB,CAAC,EAAE;gBAC5B,eAAe,EAAE,mBAAmB,CAAC,qBAAqB,CAAC;aAC5D;SACF,CAAA;QACD,gBAAgB,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IAC7C,CAAC,CAAC,CAAA;AACN,CAAC;AAED,SAAgB,uBAAuB,CAAC,EACtC,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,GAKN;IACC,kBAAkB,CAAC,kBAAkB,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAA;IAC/D,2BAA2B,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAAA;IACjE,mBAAmB,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAAA;IACzD,iBAAiB,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAAA;IACvD,gBAAgB,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAAA;AACxD,CAAC;AAdD,0DAcC","sourcesContent":["import { EventEmitter } from 'node:events'\nimport { Readable } from 'node:stream'\nimport os from 'node:os'\nimport shuffle from 'knuth-shuffle-seeded'\nimport * as messages from '@cucumber/messages'\nimport { IdGenerator } from '@cucumber/messages'\nimport detectCiEnvironment from '@cucumber/ci-environment'\nimport { doesHaveValue } from '../value_checker'\nimport { EventDataCollector } from '../formatter/helpers'\nimport PickleFilter from '../pickle_filter'\nimport { ISupportCodeLibrary } from '../support_code_library_builder/types'\nimport TestCaseHookDefinition from '../models/test_case_hook_definition'\nimport TestRunHookDefinition from '../models/test_run_hook_definition'\nimport { PickleOrder } from '../models/pickle_order'\nimport { version } from '../version'\nimport { ILogger } from '../logger'\nimport { ILineAndUri } from '../types'\n\ninterface IParseGherkinMessageStreamRequest {\n cwd?: string\n eventBroadcaster: EventEmitter\n eventDataCollector: EventDataCollector\n gherkinMessageStream: Readable\n order: string\n pickleFilter: PickleFilter\n}\n\n/**\n * Process a stream of envelopes from Gherkin and resolve to an array of filtered, ordered pickle Ids\n *\n * @param eventBroadcaster\n * @param eventDataCollector\n * @param gherkinMessageStream\n * @param order\n * @param pickleFilter\n */\nexport async function parseGherkinMessageStream({\n eventBroadcaster,\n eventDataCollector,\n gherkinMessageStream,\n order,\n pickleFilter,\n}: IParseGherkinMessageStreamRequest): Promise<string[]> {\n return await new Promise<string[]>((resolve, reject) => {\n const result: string[] = []\n gherkinMessageStream.on('data', (envelope: messages.Envelope) => {\n eventBroadcaster.emit('envelope', envelope)\n if (doesHaveValue(envelope.pickle)) {\n const pickle = envelope.pickle\n const pickleId = pickle.id\n const gherkinDocument = eventDataCollector.getGherkinDocument(\n pickle.uri\n )\n if (pickleFilter.matches({ gherkinDocument, pickle })) {\n result.push(pickleId)\n }\n }\n })\n gherkinMessageStream.on('end', () => {\n orderPickles(result, order, console)\n resolve(result)\n })\n gherkinMessageStream.on('error', reject)\n })\n}\n\n// Orders the pickleIds in place - morphs input\nexport function orderPickles<T = string>(\n pickleIds: T[],\n order: PickleOrder,\n logger: ILogger\n): void {\n const [type, seed] = splitOrder(order)\n switch (type) {\n case 'defined':\n break\n case 'random':\n if (seed === '') {\n const newSeed = Math.floor(Math.random() * 1000 * 1000).toString()\n logger.warn(`Random order using seed: ${newSeed}`)\n shuffle(pickleIds, newSeed)\n } else {\n shuffle(pickleIds, seed)\n }\n break\n default:\n throw new Error(\n 'Unrecgonized order type. Should be `defined` or `random`'\n )\n }\n}\n\nfunction splitOrder(order: string) {\n if (!order.includes(':')) {\n return [order, '']\n }\n return order.split(':')\n}\n\nexport async function emitMetaMessage(\n eventBroadcaster: EventEmitter,\n env: NodeJS.ProcessEnv\n): Promise<void> {\n const meta: messages.Meta = {\n protocolVersion: messages.version,\n implementation: {\n version,\n name: 'cucumber-js',\n },\n cpu: {\n name: os.arch(),\n },\n os: {\n name: os.platform(),\n version: os.release(),\n },\n runtime: {\n name: 'node.js',\n version: process.versions.node,\n },\n ci: detectCiEnvironment(env),\n }\n eventBroadcaster.emit('envelope', {\n meta,\n })\n}\n\nconst makeSourceReference = (source: ILineAndUri) => ({\n uri: source.uri,\n location: {\n line: source.line,\n },\n})\n\nfunction emitParameterTypes(\n supportCodeLibrary: ISupportCodeLibrary,\n eventBroadcaster: EventEmitter,\n newId: IdGenerator.NewId\n): void {\n for (const parameterType of supportCodeLibrary.parameterTypeRegistry\n .parameterTypes) {\n if (parameterType.builtin) {\n continue\n }\n const source =\n supportCodeLibrary.parameterTypeRegistry.lookupSource(parameterType)\n const envelope: messages.Envelope = {\n parameterType: {\n id: newId(),\n name: parameterType.name,\n preferForRegularExpressionMatch: parameterType.preferForRegexpMatch,\n regularExpressions: parameterType.regexpStrings,\n useForSnippets: parameterType.useForSnippets,\n sourceReference: makeSourceReference(source),\n },\n }\n eventBroadcaster.emit('envelope', envelope)\n }\n}\n\nfunction emitUndefinedParameterTypes(\n supportCodeLibrary: ISupportCodeLibrary,\n eventBroadcaster: EventEmitter\n): void {\n for (const undefinedParameterType of supportCodeLibrary.undefinedParameterTypes) {\n const envelope: messages.Envelope = {\n undefinedParameterType,\n }\n eventBroadcaster.emit('envelope', envelope)\n }\n}\n\nfunction emitStepDefinitions(\n supportCodeLibrary: ISupportCodeLibrary,\n eventBroadcaster: EventEmitter\n): void {\n supportCodeLibrary.stepDefinitions.forEach((stepDefinition) => {\n const envelope: messages.Envelope = {\n stepDefinition: {\n id: stepDefinition.id,\n pattern: {\n source: stepDefinition.pattern.toString(),\n type:\n typeof stepDefinition.pattern === 'string'\n ? messages.StepDefinitionPatternType.CUCUMBER_EXPRESSION\n : messages.StepDefinitionPatternType.REGULAR_EXPRESSION,\n },\n sourceReference: makeSourceReference(stepDefinition),\n },\n }\n eventBroadcaster.emit('envelope', envelope)\n })\n}\n\nfunction emitTestCaseHooks(\n supportCodeLibrary: ISupportCodeLibrary,\n eventBroadcaster: EventEmitter\n): void {\n ;[]\n .concat(\n supportCodeLibrary.beforeTestCaseHookDefinitions,\n supportCodeLibrary.afterTestCaseHookDefinitions\n )\n .forEach((testCaseHookDefinition: TestCaseHookDefinition) => {\n const envelope: messages.Envelope = {\n hook: {\n id: testCaseHookDefinition.id,\n name: testCaseHookDefinition.name,\n tagExpression: testCaseHookDefinition.tagExpression,\n sourceReference: makeSourceReference(testCaseHookDefinition),\n },\n }\n eventBroadcaster.emit('envelope', envelope)\n })\n}\n\nfunction emitTestRunHooks(\n supportCodeLibrary: ISupportCodeLibrary,\n eventBroadcaster: EventEmitter\n): void {\n ;[]\n .concat(\n supportCodeLibrary.beforeTestRunHookDefinitions,\n supportCodeLibrary.afterTestRunHookDefinitions\n )\n .forEach((testRunHookDefinition: TestRunHookDefinition) => {\n const envelope: messages.Envelope = {\n hook: {\n id: testRunHookDefinition.id,\n sourceReference: makeSourceReference(testRunHookDefinition),\n },\n }\n eventBroadcaster.emit('envelope', envelope)\n })\n}\n\nexport function emitSupportCodeMessages({\n eventBroadcaster,\n supportCodeLibrary,\n newId,\n}: {\n eventBroadcaster: EventEmitter\n supportCodeLibrary: ISupportCodeLibrary\n newId: IdGenerator.NewId\n}): void {\n emitParameterTypes(supportCodeLibrary, eventBroadcaster, newId)\n emitUndefinedParameterTypes(supportCodeLibrary, eventBroadcaster)\n emitStepDefinitions(supportCodeLibrary, eventBroadcaster)\n emitTestCaseHooks(supportCodeLibrary, eventBroadc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CAAA;QACD,gBAAgB,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IAC7C,CAAC,CAAC,CAAA;AACN,CAAC;AAED,SAAS,gBAAgB,CACvB,kBAAsC,EACtC,gBAA8B;IAE9B,CAAC;IAAA,EAAE;SACA,MAAM,CACL,kBAAkB,CAAC,4BAA4B,EAC/C,kBAAkB,CAAC,2BAA2B,CAC/C;SACA,OAAO,CAAC,CAAC,qBAA4C,EAAE,EAAE;QACxD,MAAM,QAAQ,GAAsB;YAClC,IAAI,EAAE;gBACJ,EAAE,EAAE,qBAAqB,CAAC,EAAE;gBAC5B,eAAe,EAAE,mBAAmB,CAAC,qBAAqB,CAAC;aAC5D;SACF,CAAA;QACD,gBAAgB,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IAC7C,CAAC,CAAC,CAAA;AACN,CAAC;AAED,SAAgB,uBAAuB,CAAC,EACtC,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,GAKN;IACC,kBAAkB,CAAC,kBAAkB,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAA;IAC/D,2BAA2B,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAAA;IACjE,mBAAmB,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAAA;IACzD,iBAAiB,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAAA;IACvD,gBAAgB,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAAA;AACxD,CAAC;AAdD,0DAcC","sourcesContent":["import { EventEmitter } from 'node:events'\nimport { Readable } from 'node:stream'\nimport os from 'node:os'\nimport shuffle from 'knuth-shuffle-seeded'\nimport * as messages from '@cucumber/messages'\nimport { IdGenerator } from '@cucumber/messages'\nimport detectCiEnvironment from '@cucumber/ci-environment'\nimport { doesHaveValue } from '../value_checker'\nimport { EventDataCollector } from '../formatter/helpers'\nimport PickleFilter from '../pickle_filter'\nimport { SupportCodeLibrary } from '../support_code_library_builder/types'\nimport TestCaseHookDefinition from '../models/test_case_hook_definition'\nimport TestRunHookDefinition from '../models/test_run_hook_definition'\nimport { version } from '../version'\nimport { ILogger } from '../logger'\nimport { ILineAndUri } from '../types'\nimport { IPickleOrder } from '../filter'\n\ninterface IParseGherkinMessageStreamRequest {\n cwd?: string\n eventBroadcaster: EventEmitter\n eventDataCollector: EventDataCollector\n gherkinMessageStream: Readable\n order: string\n pickleFilter: PickleFilter\n}\n\n/**\n * Process a stream of envelopes from Gherkin and resolve to an array of filtered, ordered pickle Ids\n *\n * @param eventBroadcaster\n * @param eventDataCollector\n * @param gherkinMessageStream\n * @param order\n * @param pickleFilter\n */\nexport async function parseGherkinMessageStream({\n eventBroadcaster,\n eventDataCollector,\n gherkinMessageStream,\n order,\n pickleFilter,\n}: IParseGherkinMessageStreamRequest): Promise<string[]> {\n return await new Promise<string[]>((resolve, reject) => {\n const result: string[] = []\n gherkinMessageStream.on('data', (envelope: messages.Envelope) => {\n eventBroadcaster.emit('envelope', envelope)\n if (doesHaveValue(envelope.pickle)) {\n const pickle = envelope.pickle\n const pickleId = pickle.id\n const gherkinDocument = eventDataCollector.getGherkinDocument(\n pickle.uri\n )\n if (pickleFilter.matches({ gherkinDocument, pickle })) {\n result.push(pickleId)\n }\n }\n })\n gherkinMessageStream.on('end', () => {\n orderPickles(result, order as IPickleOrder, console)\n resolve(result)\n })\n gherkinMessageStream.on('error', reject)\n })\n}\n\n// Orders the pickleIds in place - morphs input\nexport function orderPickles<T = string>(\n pickleIds: T[],\n order: IPickleOrder,\n logger: ILogger\n): void {\n const [type, seed] = splitOrder(order)\n switch (type) {\n case 'defined':\n break\n case 'random':\n if (seed === '') {\n const newSeed = Math.floor(Math.random() * 1000 * 1000).toString()\n logger.warn(`Random order using seed: ${newSeed}`)\n shuffle(pickleIds, newSeed)\n } else {\n shuffle(pickleIds, seed)\n }\n break\n default:\n throw new Error(\n 'Unrecgonized order type. Should be `defined` or `random`'\n )\n }\n}\n\nfunction splitOrder(order: string) {\n if (!order.includes(':')) {\n return [order, '']\n }\n return order.split(':')\n}\n\nexport async function emitMetaMessage(\n eventBroadcaster: EventEmitter,\n env: NodeJS.ProcessEnv\n): Promise<void> {\n const meta: messages.Meta = {\n protocolVersion: messages.version,\n implementation: {\n version,\n name: 'cucumber-js',\n },\n cpu: {\n name: os.arch(),\n },\n os: {\n name: os.platform(),\n version: os.release(),\n },\n runtime: {\n name: 'node.js',\n version: process.versions.node,\n },\n ci: detectCiEnvironment(env),\n }\n eventBroadcaster.emit('envelope', {\n meta,\n })\n}\n\nconst makeSourceReference = (source: ILineAndUri) => ({\n uri: source.uri,\n location: {\n line: source.line,\n },\n})\n\nfunction emitParameterTypes(\n supportCodeLibrary: SupportCodeLibrary,\n eventBroadcaster: EventEmitter,\n newId: IdGenerator.NewId\n): void {\n for (const parameterType of supportCodeLibrary.parameterTypeRegistry\n .parameterTypes) {\n if (parameterType.builtin) {\n continue\n }\n const source =\n supportCodeLibrary.parameterTypeRegistry.lookupSource(parameterType)\n const envelope: messages.Envelope = {\n parameterType: {\n id: newId(),\n name: parameterType.name,\n preferForRegularExpressionMatch: parameterType.preferForRegexpMatch,\n regularExpressions: parameterType.regexpStrings,\n useForSnippets: parameterType.useForSnippets,\n sourceReference: makeSourceReference(source),\n },\n }\n eventBroadcaster.emit('envelope', envelope)\n }\n}\n\nfunction emitUndefinedParameterTypes(\n supportCodeLibrary: SupportCodeLibrary,\n eventBroadcaster: EventEmitter\n): void {\n for (const undefinedParameterType of supportCodeLibrary.undefinedParameterTypes) {\n const envelope: messages.Envelope = {\n undefinedParameterType,\n }\n eventBroadcaster.emit('envelope', envelope)\n }\n}\n\nfunction emitStepDefinitions(\n supportCodeLibrary: SupportCodeLibrary,\n eventBroadcaster: EventEmitter\n): void {\n supportCodeLibrary.stepDefinitions.forEach((stepDefinition) => {\n const envelope: messages.Envelope = {\n stepDefinition: {\n id: stepDefinition.id,\n pattern: {\n source: stepDefinition.pattern.toString(),\n type:\n typeof stepDefinition.pattern === 'string'\n ? messages.StepDefinitionPatternType.CUCUMBER_EXPRESSION\n : messages.StepDefinitionPatternType.REGULAR_EXPRESSION,\n },\n sourceReference: makeSourceReference(stepDefinition),\n },\n }\n eventBroadcaster.emit('envelope', envelope)\n })\n}\n\nfunction emitTestCaseHooks(\n supportCodeLibrary: SupportCodeLibrary,\n eventBroadcaster: EventEmitter\n): void {\n ;[]\n .concat(\n supportCodeLibrary.beforeTestCaseHookDefinitions,\n supportCodeLibrary.afterTestCaseHookDefinitions\n )\n .forEach((testCaseHookDefinition: TestCaseHookDefinition) => {\n const envelope: messages.Envelope = {\n hook: {\n id: testCaseHookDefinition.id,\n name: testCaseHookDefinition.name,\n tagExpression: testCaseHookDefinition.tagExpression,\n sourceReference: makeSourceReference(testCaseHookDefinition),\n },\n }\n eventBroadcaster.emit('envelope', envelope)\n })\n}\n\nfunction emitTestRunHooks(\n supportCodeLibrary: SupportCodeLibrary,\n eventBroadcaster: EventEmitter\n): void {\n ;[]\n .concat(\n supportCodeLibrary.beforeTestRunHookDefinitions,\n supportCodeLibrary.afterTestRunHookDefinitions\n )\n .forEach((testRunHookDefinition: TestRunHookDefinition) => {\n const envelope: messages.Envelope = {\n hook: {\n id: testRunHookDefinition.id,\n sourceReference: makeSourceReference(testRunHookDefinition),\n },\n }\n eventBroadcaster.emit('envelope', envelope)\n })\n}\n\nexport function emitSupportCodeMessages({\n eventBroadcaster,\n supportCodeLibrary,\n newId,\n}: {\n eventBroadcaster: EventEmitter\n supportCodeLibrary: SupportCodeLibrary\n newId: IdGenerator.NewId\n}): void {\n emitParameterTypes(supportCodeLibrary, eventBroadcaster, newId)\n emitUndefinedParameterTypes(supportCodeLibrary, eventBroadcaster)\n emitStepDefinitions(supportCodeLibrary, eventBroadcaster)\n emitTestCaseHooks(supportCodeLibrary, eventBroadcaster)\n emitTestRunHooks(supportCodeLibrary, eventBroadcaster)\n}\n"]}
@@ -34,13 +34,13 @@ const schema = yup.object().shape({
34
34
  format: yup
35
35
  .array()
36
36
  .of(yup.lazy((val) => Array.isArray(val)
37
- ? yup.array().of(yup.string()).min(2).max(2)
37
+ ? yup.array().of(yup.string()).min(1).max(2)
38
38
  : yup.string())),
39
39
  formatOptions: yup.object(),
40
40
  import: yup.array().of(yup.string()),
41
41
  language: yup.string().oneOf(Object.keys(gherkin_1.dialects)),
42
42
  name: yup.array().of(yup.string()),
43
- order: yup.string().oneOf(['defined', 'random']),
43
+ order: yup.string().matches(/^random:.*|random|defined$/),
44
44
  paths: yup.array().of(yup.string()),
45
45
  parallel: yup.number().integer().min(0),
46
46
  publish: yup.boolean(),
@@ -1 +1 @@
1
- {"version":3,"file":"check_schema.js","sourceRoot":"","sources":["../../src/configuration/check_schema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA0B;AAC1B,+CAA4C;AAG5C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC;IAChC,SAAS,EAAE,GAAG,CAAC,OAAO,EAAE;IACxB,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE;IACrB,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE;IACnB,QAAQ,EAAE,GAAG,CAAC,OAAO,EAAE;IACvB,MAAM,EAAE,GAAG;SACR,KAAK,EAAE;SACP,EAAE,CACD,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CACf,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAChB,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC5C,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,CACjB,CACF;IACH,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE;IAC3B,MAAM,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC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* as yup from 'yup'\nimport { dialects } from '@cucumber/gherkin'\nimport { IConfiguration } from './types'\n\nconst schema = yup.object().shape({\n backtrace: yup.boolean(),\n dryRun: yup.boolean(),\n exit: yup.boolean(),\n failFast: yup.boolean(),\n format: yup\n .array()\n .of(\n yup.lazy((val) =>\n Array.isArray(val)\n ? yup.array().of(yup.string()).min(2).max(2)\n : yup.string()\n )\n ),\n formatOptions: yup.object(),\n import: yup.array().of(yup.string()),\n language: yup.string().oneOf(Object.keys(dialects)),\n name: yup.array().of(yup.string()),\n order: yup.string().oneOf(['defined', 'random']),\n paths: yup.array().of(yup.string()),\n parallel: yup.number().integer().min(0),\n publish: yup.boolean(),\n publishQuiet: yup.boolean(),\n require: yup.array().of(yup.string()),\n requireModule: yup.array().of(yup.string()),\n retry: yup.number().integer().min(0),\n retryTagFilter: yup.string(),\n strict: yup.boolean(),\n tags: yup.string(),\n worldParameters: yup.object(),\n})\n\nexport function checkSchema(configuration: any): Partial<IConfiguration> {\n return schema.validateSync(configuration, {\n abortEarly: false,\n strict: true,\n stripUnknown: true,\n }) as Partial<IConfiguration>\n}\n"]}
1
+ {"version":3,"file":"check_schema.js","sourceRoot":"","sources":["../../src/configuration/check_schema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA0B;AAC1B,+CAA4C;AAG5C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC;IAChC,SAAS,EAAE,GAAG,CAAC,OAAO,EAAE;IACxB,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE;IACrB,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE;IACnB,QAAQ,EAAE,GAAG,CAAC,OAAO,EAAE;IACvB,MAAM,EAAE,GAAG;SACR,KAAK,EAAE;SACP,EAAE,CACD,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CACf,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAChB,CAAC,CAAC,GAAG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,CAAC,MAAM,EAAE;IAClB,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE;CAC9B,CAAC,CAAA;AAEF,SAAgB,WAAW,CAAC,aAAkB;IAC5C,OAAO,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE;QACxC,UAAU,EAAE,KAAK;QACjB,MAAM,EAAE,IAAI;QACZ,YAAY,EAAE,IAAI;KACnB,CAA4B,CAAA;AAC/B,CAAC;AAND,kCAMC","sourcesContent":["import * as yup from 'yup'\nimport { dialects } from '@cucumber/gherkin'\nimport { IConfiguration } from './types'\n\nconst schema = yup.object().shape({\n backtrace: yup.boolean(),\n dryRun: yup.boolean(),\n exit: yup.boolean(),\n failFast: yup.boolean(),\n format: yup\n .array()\n .of(\n yup.lazy((val) =>\n Array.isArray(val)\n ? yup.array().of(yup.string()).min(1).max(2)\n : yup.string()\n )\n ),\n formatOptions: yup.object(),\n import: yup.array().of(yup.string()),\n language: yup.string().oneOf(Object.keys(dialects)),\n name: yup.array().of(yup.string()),\n order: yup.string().matches(/^random:.*|random|defined$/),\n paths: yup.array().of(yup.string()),\n parallel: yup.number().integer().min(0),\n publish: yup.boolean(),\n publishQuiet: yup.boolean(),\n require: yup.array().of(yup.string()),\n requireModule: yup.array().of(yup.string()),\n retry: yup.number().integer().min(0),\n retryTagFilter: yup.string(),\n strict: yup.boolean(),\n tags: yup.string(),\n worldParameters: yup.object(),\n})\n\nexport function checkSchema(configuration: any): Partial<IConfiguration> {\n return schema.validateSync(configuration, {\n abortEarly: false,\n strict: true,\n stripUnknown: true,\n }) as Partial<IConfiguration>\n}\n"]}
@@ -8,12 +8,10 @@ const node_fs_1 = __importDefault(require("node:fs"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  const node_util_1 = require("node:util");
10
10
  const node_url_1 = require("node:url");
11
- const string_argv_1 = __importDefault(require("string-argv"));
12
11
  const yaml_1 = __importDefault(require("yaml"));
13
12
  const read_pkg_up_1 = __importDefault(require("read-pkg-up"));
14
13
  const merge_configurations_1 = require("./merge_configurations");
15
- const argv_parser_1 = __importDefault(require("./argv_parser"));
16
- const check_schema_1 = require("./check_schema");
14
+ const parse_configuration_1 = require("./parse_configuration");
17
15
  async function fromFile(logger, cwd, file, profiles = []) {
18
16
  const definitions = await loadFile(logger, cwd, file);
19
17
  if (!definitions.default) {
@@ -30,7 +28,7 @@ async function fromFile(logger, cwd, file, profiles = []) {
30
28
  throw new Error(`Requested profile "${profileKey}" doesn't exist`);
31
29
  }
32
30
  });
33
- return (0, merge_configurations_1.mergeConfigurations)({}, ...profiles.map((profileKey) => extractConfiguration(logger, profileKey, definitions[profileKey])));
31
+ return (0, merge_configurations_1.mergeConfigurations)({}, ...profiles.map((profileKey) => (0, parse_configuration_1.parseConfiguration)(logger, `Profile "${profileKey}"`, definitions[profileKey])));
34
32
  }
35
33
  exports.fromFile = fromFile;
36
34
  async function loadFile(logger, cwd, file) {
@@ -85,21 +83,4 @@ async function readPackageJson(filePath) {
85
83
  const parentPackage = await (0, read_pkg_up_1.default)({ cwd: node_path_1.default.dirname(filePath) });
86
84
  return parentPackage?.packageJson;
87
85
  }
88
- function extractConfiguration(logger, name, definition) {
89
- if (typeof definition === 'string') {
90
- logger.debug(`Profile "${name}" value is a string; parsing as argv`);
91
- const { configuration } = argv_parser_1.default.parse([
92
- 'node',
93
- 'cucumber-js',
94
- ...(0, string_argv_1.default)(definition),
95
- ]);
96
- return configuration;
97
- }
98
- try {
99
- return (0, check_schema_1.checkSchema)(definition);
100
- }
101
- catch (error) {
102
- throw new Error(`Requested profile "${name}" failed schema validation: ${error.errors.join(' ')}`);
103
- }
104
- }
105
86
  //# sourceMappingURL=from_file.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"from_file.js","sourceRoot":"","sources":["../../src/configuration/from_file.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAwB;AACxB,0DAA4B;AAC5B,yCAAqC;AACrC,uCAAwC;AACxC,8DAAoC;AACpC,gDAAuB;AACvB,8DAAmC;AAGnC,iE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node:fs'\nimport path from 'node:path'\nimport { promisify } from 'node:util'\nimport { pathToFileURL } from 'node:url'\nimport stringArgv from 'string-argv'\nimport YAML from 'yaml'\nimport readPkgUp from 'read-pkg-up'\nimport { ILogger } from '../logger'\nimport { IConfiguration } from './types'\nimport { mergeConfigurations } from './merge_configurations'\nimport ArgvParser from './argv_parser'\nimport { checkSchema } from './check_schema'\n\nexport async function fromFile(\n logger: ILogger,\n cwd: string,\n file: string,\n profiles: string[] = []\n): Promise<Partial<IConfiguration>> {\n const definitions = await loadFile(logger, cwd, file)\n if (!definitions.default) {\n logger.debug('No default profile defined in configuration file')\n definitions.default = {}\n }\n if (profiles.length < 1) {\n logger.debug('No profiles specified; using default profile')\n profiles = ['default']\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 extractConfiguration(logger, profileKey, definitions[profileKey])\n )\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-var-requires\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-var-requires\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-var-requires\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 parentPackage = await readPkgUp({ cwd: path.dirname(filePath) })\n return parentPackage?.packageJson\n}\n\nfunction extractConfiguration(\n logger: ILogger,\n name: string,\n definition: any\n): Partial<IConfiguration> {\n if (typeof definition === 'string') {\n logger.debug(`Profile \"${name}\" value is a string; parsing as argv`)\n const { configuration } = ArgvParser.parse([\n 'node',\n 'cucumber-js',\n ...stringArgv(definition),\n ])\n return configuration\n }\n try {\n return checkSchema(definition)\n } catch (error) {\n throw new Error(\n `Requested profile \"${name}\" failed schema validation: ${error.errors.join(\n ' '\n )}`\n )\n }\n}\n"]}
1
+ {"version":3,"file":"from_file.js","sourceRoot":"","sources":["../../src/configuration/from_file.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAwB;AACxB,0DAA4B;AAC5B,yCAAqC;AACrC,uCAAwC;AACxC,gDAAuB;AACvB,8DAAmC;AAGnC,iEAA4D;AAC5D,+DAA0D;AAEnD,KAAK,UAAU,QAAQ,CAC5B,MAAe,EACf,GAAW,EACX,IAAY,EACZ,WAAqB,EAAE;IAEvB,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;IACrD,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE;QACxB,MAAM,CAAC,KAAK,CAAC,kDAAkD,CAAC,C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AG,CAAC,CAAA;KAC7E;IACD,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;QACnC,MAAM,IAAI,KAAK,CAAC,sBAAsB,QAAQ,4BAA4B,CAAC,CAAA;KAC5E;IACD,OAAO,WAAW,CAAA;AACpB,CAAC;AAED,KAAK,UAAU,eAAe,CAAC,QAAgB;IAC7C,MAAM,aAAa,GAAG,MAAM,IAAA,qBAAS,EAAC,EAAE,GAAG,EAAE,mBAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IACtE,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 readPkgUp from 'read-pkg-up'\nimport { ILogger } from '../logger'\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 const definitions = await loadFile(logger, cwd, file)\n if (!definitions.default) {\n logger.debug('No default profile defined in configuration file')\n definitions.default = {}\n }\n if (profiles.length < 1) {\n logger.debug('No profiles specified; using default profile')\n profiles = ['default']\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 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-var-requires\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-var-requires\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-var-requires\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 parentPackage = await readPkgUp({ cwd: path.dirname(filePath) })\n return parentPackage?.packageJson\n}\n"]}
@@ -3,5 +3,7 @@ export * from './default_configuration';
3
3
  export * from './from_file';
4
4
  export * from './helpers';
5
5
  export * from './merge_configurations';
6
+ export * from './parse_configuration';
6
7
  export * from './split_format_descriptor';
7
8
  export * from './types';
9
+ export * from './validate_configuration';
@@ -24,6 +24,8 @@ __exportStar(require("./default_configuration"), exports);
24
24
  __exportStar(require("./from_file"), exports);
25
25
  __exportStar(require("./helpers"), exports);
26
26
  __exportStar(require("./merge_configurations"), exports);
27
+ __exportStar(require("./parse_configuration"), exports);
27
28
  __exportStar(require("./split_format_descriptor"), exports);
28
29
  __exportStar(require("./types"), exports);
30
+ __exportStar(require("./validate_configuration"), exports);
29
31
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/configuration/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,6CAAqD;AAA5C,0HAAA,OAAO,OAAc;AAC9B,0DAAuC;AACvC,8CAA2B;AAC3B,4CAAyB;AACzB,yDAAsC;AACtC,4DAAyC;AACzC,0CAAuB","sourcesContent":["export { default as ArgvParser } from './argv_parser'\nexport * from './default_configuration'\nexport * from './from_file'\nexport * from './helpers'\nexport * from './merge_configurations'\nexport * from './split_format_descriptor'\nexport * from './types'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/configuration/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,6CAAqD;AAA5C,0HAAA,OAAO,OAAc;AAC9B,0DAAuC;AACvC,8CAA2B;AAC3B,4CAAyB;AACzB,yDAAsC;AACtC,wDAAqC;AACrC,4DAAyC;AACzC,0CAAuB;AACvB,2DAAwC","sourcesContent":["export { default as ArgvParser } from './argv_parser'\nexport * from './default_configuration'\nexport * from './from_file'\nexport * from './helpers'\nexport * from './merge_configurations'\nexport * from './parse_configuration'\nexport * from './split_format_descriptor'\nexport * from './types'\nexport * from './validate_configuration'\n"]}
@@ -0,0 +1,3 @@
1
+ import { ILogger } from '../logger';
2
+ import { IConfiguration } from './types';
3
+ export declare function parseConfiguration(logger: ILogger, source: string, definition: Partial<IConfiguration> | string | undefined): Partial<IConfiguration>;