@wdio/cucumber-framework 7.16.12 → 7.17.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.
package/build/index.js DELETED
@@ -1,323 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.World = exports.When = exports.Then = exports.setWorldConstructor = exports.setDefinitionFunctionWrapper = exports.setDefaultTimeout = exports.Given = exports.defineStep = exports.defineParameterType = exports.BeforeStep = exports.BeforeAll = exports.Before = exports.AfterStep = exports.AfterAll = exports.After = exports.adapterFactory = exports.CucumberAdapter = void 0;
26
- const path_1 = __importDefault(require("path"));
27
- const events_1 = require("events");
28
- const mockery_1 = __importDefault(require("mockery"));
29
- const is_glob_1 = __importDefault(require("is-glob"));
30
- const glob_1 = __importDefault(require("glob"));
31
- const Cucumber = __importStar(require("@cucumber/cucumber"));
32
- const cucumber_1 = require("@cucumber/cucumber");
33
- Object.defineProperty(exports, "After", { enumerable: true, get: function () { return cucumber_1.After; } });
34
- Object.defineProperty(exports, "AfterAll", { enumerable: true, get: function () { return cucumber_1.AfterAll; } });
35
- Object.defineProperty(exports, "AfterStep", { enumerable: true, get: function () { return cucumber_1.AfterStep; } });
36
- Object.defineProperty(exports, "Before", { enumerable: true, get: function () { return cucumber_1.Before; } });
37
- Object.defineProperty(exports, "BeforeAll", { enumerable: true, get: function () { return cucumber_1.BeforeAll; } });
38
- Object.defineProperty(exports, "BeforeStep", { enumerable: true, get: function () { return cucumber_1.BeforeStep; } });
39
- Object.defineProperty(exports, "defineParameterType", { enumerable: true, get: function () { return cucumber_1.defineParameterType; } });
40
- Object.defineProperty(exports, "defineStep", { enumerable: true, get: function () { return cucumber_1.defineStep; } });
41
- Object.defineProperty(exports, "Given", { enumerable: true, get: function () { return cucumber_1.Given; } });
42
- Object.defineProperty(exports, "setDefaultTimeout", { enumerable: true, get: function () { return cucumber_1.setDefaultTimeout; } });
43
- Object.defineProperty(exports, "setDefinitionFunctionWrapper", { enumerable: true, get: function () { return cucumber_1.setDefinitionFunctionWrapper; } });
44
- Object.defineProperty(exports, "setWorldConstructor", { enumerable: true, get: function () { return cucumber_1.setWorldConstructor; } });
45
- Object.defineProperty(exports, "World", { enumerable: true, get: function () { return cucumber_1.World; } });
46
- Object.defineProperty(exports, "Then", { enumerable: true, get: function () { return cucumber_1.Then; } });
47
- Object.defineProperty(exports, "When", { enumerable: true, get: function () { return cucumber_1.When; } });
48
- const gherkin_streams_1 = require("@cucumber/gherkin-streams");
49
- const event_data_collector_1 = __importDefault(require("@cucumber/cucumber/lib/formatter/helpers/event_data_collector"));
50
- const messages_1 = require("@cucumber/messages");
51
- const utils_1 = require("@wdio/utils");
52
- const reporter_1 = __importDefault(require("./reporter"));
53
- const constants_1 = require("./constants");
54
- const utils_2 = require("./utils");
55
- const { incrementing } = messages_1.IdGenerator;
56
- function getResultObject(world) {
57
- var _a, _b, _c, _d, _e;
58
- return {
59
- passed: (((_a = world.result) === null || _a === void 0 ? void 0 : _a.status) === Cucumber.Status.PASSED || ((_b = world.result) === null || _b === void 0 ? void 0 : _b.status) === Cucumber.Status.SKIPPED),
60
- error: (_c = world.result) === null || _c === void 0 ? void 0 : _c.message,
61
- duration: ((_e = (_d = world.result) === null || _d === void 0 ? void 0 : _d.duration) === null || _e === void 0 ? void 0 : _e.nanos) / 10e6 // convert into ms
62
- };
63
- }
64
- class CucumberAdapter {
65
- constructor(_cid, _config, _specs, _capabilities, _reporter) {
66
- this._cid = _cid;
67
- this._config = _config;
68
- this._specs = _specs;
69
- this._capabilities = _capabilities;
70
- this._reporter = _reporter;
71
- this._cwd = process.cwd();
72
- this._newId = incrementing();
73
- this._cucumberOpts = Object.assign({}, constants_1.DEFAULT_OPTS, this._config.cucumberOpts);
74
- this._hasTests = true;
75
- this._cucumberFeaturesWithLineNumbers = this._config.cucumberFeaturesWithLineNumbers || [];
76
- this._eventBroadcaster = new events_1.EventEmitter();
77
- this._eventDataCollector = new event_data_collector_1.default(this._eventBroadcaster);
78
- const featurePathsToRun = this._cucumberFeaturesWithLineNumbers.length > 0 ? this._cucumberFeaturesWithLineNumbers : this._specs;
79
- this._pickleFilter = new Cucumber.PickleFilter({
80
- cwd: this._cwd,
81
- featurePaths: featurePathsToRun,
82
- names: this._cucumberOpts.names,
83
- tagExpression: this._cucumberOpts.tagExpression
84
- });
85
- const reporterOptions = {
86
- capabilities: this._capabilities,
87
- ignoreUndefinedDefinitions: Boolean(this._cucumberOpts.ignoreUndefinedDefinitions),
88
- failAmbiguousDefinitions: Boolean(this._cucumberOpts.failAmbiguousDefinitions),
89
- tagsInTitle: Boolean(this._cucumberOpts.tagsInTitle),
90
- scenarioLevelReporter: Boolean(this._cucumberOpts.scenarioLevelReporter)
91
- };
92
- this._cucumberReporter = new reporter_1.default(this._eventBroadcaster, this._pickleFilter, reporterOptions, this._cid, this._specs, this._reporter);
93
- }
94
- async init() {
95
- try {
96
- const gherkinMessageStream = gherkin_streams_1.GherkinStreams.fromPaths(this._specs, {
97
- defaultDialect: this._cucumberOpts.featureDefaultLanguage,
98
- newId: this._newId
99
- });
100
- await Cucumber.parseGherkinMessageStream({
101
- cwd: this._cwd,
102
- eventBroadcaster: this._eventBroadcaster,
103
- gherkinMessageStream,
104
- eventDataCollector: this._eventDataCollector,
105
- order: this._cucumberOpts.order,
106
- pickleFilter: this._pickleFilter
107
- });
108
- this._hasTests = this._cucumberReporter.eventListener.getPickleIds(this._capabilities).length > 0;
109
- }
110
- catch (runtimeError) {
111
- await (0, utils_1.executeHooksWithArgs)('after', this._config.after, [runtimeError, this._capabilities, this._specs]);
112
- throw runtimeError;
113
- }
114
- /**
115
- * import and set options for `expect-webdriverio` assertion lib once
116
- * the framework was initiated so that it can detect the environment
117
- */
118
- const { setOptions } = require('expect-webdriverio');
119
- setOptions({
120
- wait: this._config.waitforTimeout,
121
- interval: this._config.waitforInterval, // interval between attempts
122
- });
123
- return this;
124
- }
125
- hasTests() {
126
- return this._hasTests;
127
- }
128
- async run() {
129
- let runtimeError;
130
- let result;
131
- try {
132
- this.registerRequiredModules();
133
- Cucumber.supportCodeLibraryBuilder.reset(this._cwd, this._newId);
134
- /**
135
- * wdio hooks should be added before spec files are loaded
136
- */
137
- this.addWdioHooks(this._config);
138
- this.loadSpecFiles();
139
- this.wrapSteps(this._config);
140
- /**
141
- * we need to somehow identify is function is step or hook
142
- * so we wrap every user hook function
143
- */
144
- (0, utils_2.setUserHookNames)(Cucumber.supportCodeLibraryBuilder);
145
- Cucumber.setDefaultTimeout(this._cucumberOpts.timeout);
146
- const supportCodeLibrary = Cucumber.supportCodeLibraryBuilder.finalize();
147
- /**
148
- * gets current step data: `{ uri, feature, scenario, step, sourceLocation }`
149
- * or `null` for some hooks.
150
- */
151
- this.getHookParams = this._cucumberReporter
152
- .eventListener
153
- .getHookParams
154
- .bind(this._cucumberReporter.eventListener);
155
- const runtime = new Cucumber.Runtime({
156
- newId: this._newId,
157
- eventBroadcaster: this._eventBroadcaster,
158
- options: this._cucumberOpts,
159
- supportCodeLibrary,
160
- eventDataCollector: this._eventDataCollector,
161
- pickleIds: this._cucumberReporter.eventListener.getPickleIds(this._capabilities)
162
- });
163
- result = await runtime.start() ? 0 : 1;
164
- /**
165
- * if we ignore undefined definitions we trust the reporter
166
- * with the fail count
167
- */
168
- if (this._cucumberOpts.ignoreUndefinedDefinitions && result) {
169
- result = this._cucumberReporter.failedCount;
170
- }
171
- }
172
- catch (err) {
173
- runtimeError = err;
174
- result = 1;
175
- }
176
- await (0, utils_1.executeHooksWithArgs)('after', this._config.after, [runtimeError || result, this._capabilities, this._specs]);
177
- /**
178
- * in case the spec has a runtime error throw after the wdio hook
179
- */
180
- if (runtimeError) {
181
- throw runtimeError;
182
- }
183
- return result;
184
- }
185
- /**
186
- * Transpilation https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md#transpilation
187
- * Usage: `['module']`
188
- * we extend it a bit with ability to init and pass configuration to modules.
189
- * Pass an array with path to module and its configuration instead:
190
- * Usage: `[['module', {}]]`
191
- * Or pass your own function
192
- * Usage: `[() => { require('@babel/register')({ ignore: [] }) }]`
193
- */
194
- registerRequiredModules() {
195
- this._cucumberOpts.requireModule.map(requiredModule => {
196
- if (Array.isArray(requiredModule)) {
197
- require(requiredModule[0])(requiredModule[1]);
198
- }
199
- else if (typeof requiredModule === 'function') {
200
- requiredModule();
201
- }
202
- else {
203
- require(requiredModule);
204
- }
205
- });
206
- }
207
- requiredFiles() {
208
- return this._cucumberOpts.require.reduce((files, requiredFile) => files.concat((0, is_glob_1.default)(requiredFile)
209
- ? glob_1.default.sync(requiredFile)
210
- : [requiredFile]), []);
211
- }
212
- loadSpecFiles() {
213
- // we use mockery to allow people to import 'our' cucumber even though their spec files are in their folders
214
- // because of that we don't have to attach anything to the global object, and the current cucumber spec files
215
- // should just work with no changes with this framework
216
- mockery_1.default.enable({
217
- useCleanCache: false,
218
- warnOnReplace: false,
219
- warnOnUnregistered: false
220
- });
221
- mockery_1.default.registerMock('@cucumber/cucumber', Cucumber);
222
- this.requiredFiles().forEach((codePath) => {
223
- const filepath = path_1.default.isAbsolute(codePath)
224
- ? codePath
225
- : path_1.default.join(process.cwd(), codePath);
226
- // This allows rerunning a stepDefinitions file
227
- delete require.cache[require.resolve(filepath)];
228
- require(filepath);
229
- });
230
- mockery_1.default.disable();
231
- }
232
- /**
233
- * set `beforeFeature`, `afterFeature`, `beforeScenario`, `afterScenario`, 'beforeStep', 'afterStep'
234
- * @param {object} config config
235
- */
236
- addWdioHooks(config) {
237
- var _a;
238
- const eventListener = (_a = this._cucumberReporter) === null || _a === void 0 ? void 0 : _a.eventListener;
239
- Cucumber.BeforeAll(async function wdioHookBeforeFeature() {
240
- const params = eventListener === null || eventListener === void 0 ? void 0 : eventListener.getHookParams();
241
- await (0, utils_1.executeHooksWithArgs)('beforeFeature', config.beforeFeature, [params === null || params === void 0 ? void 0 : params.uri, params === null || params === void 0 ? void 0 : params.feature]);
242
- });
243
- Cucumber.AfterAll(async function wdioHookAfterFeature() {
244
- const params = eventListener === null || eventListener === void 0 ? void 0 : eventListener.getHookParams();
245
- await (0, utils_1.executeHooksWithArgs)('afterFeature', config.afterFeature, [params === null || params === void 0 ? void 0 : params.uri, params === null || params === void 0 ? void 0 : params.feature]);
246
- });
247
- Cucumber.Before(async function wdioHookBeforeScenario(world) {
248
- await (0, utils_1.executeHooksWithArgs)('beforeScenario', config.beforeScenario, [world, this]);
249
- });
250
- Cucumber.After(async function wdioHookAfterScenario(world) {
251
- await (0, utils_1.executeHooksWithArgs)('afterScenario', config.afterScenario, [world, getResultObject(world), this]);
252
- });
253
- Cucumber.BeforeStep(async function wdioHookBeforeStep() {
254
- const params = eventListener === null || eventListener === void 0 ? void 0 : eventListener.getHookParams();
255
- await (0, utils_1.executeHooksWithArgs)('beforeStep', config.beforeStep, [params === null || params === void 0 ? void 0 : params.step, params === null || params === void 0 ? void 0 : params.scenario, this]);
256
- });
257
- Cucumber.AfterStep(async function wdioHookAfterStep(world) {
258
- const params = eventListener === null || eventListener === void 0 ? void 0 : eventListener.getHookParams();
259
- await (0, utils_1.executeHooksWithArgs)('afterStep', config.afterStep, [params === null || params === void 0 ? void 0 : params.step, params === null || params === void 0 ? void 0 : params.scenario, getResultObject(world), this]);
260
- });
261
- }
262
- /**
263
- * wraps step definition code with sync/async runner with a retry option
264
- * @param {object} config
265
- */
266
- wrapSteps(config) {
267
- const wrapStep = this.wrapStep;
268
- const cid = this._cid;
269
- const getHookParams = () => this.getHookParams && this.getHookParams();
270
- Cucumber.setDefinitionFunctionWrapper((fn, options = { retry: 0 }) => {
271
- /**
272
- * hooks defined in wdio.conf are already wrapped
273
- */
274
- if (fn.name.startsWith('wdioHook')) {
275
- return fn;
276
- }
277
- /**
278
- * this flag is used to:
279
- * - avoid hook retry
280
- * - avoid wrap hooks with beforeStep and afterStep
281
- */
282
- const isStep = !fn.name.startsWith('userHook');
283
- return wrapStep(fn, isStep, config, cid, options, getHookParams);
284
- });
285
- }
286
- /**
287
- * wrap step definition to enable retry ability
288
- * @param {Function} code step definition
289
- * @param {boolean} isStep
290
- * @param {object} config
291
- * @param {string} cid cid
292
- * @param {StepDefinitionOptions} options
293
- * @param {Function} getHookParams step definition
294
- * @return {Function} wrapped step definition for sync WebdriverIO code
295
- */
296
- wrapStep(code, isStep, config, cid, options, getHookParams) {
297
- return function (...args) {
298
- const hookParams = getHookParams();
299
- const retryTest = isStep && isFinite(options.retry) ? options.retry : 0;
300
- /**
301
- * wrap user step/hook with wdio before/after hooks
302
- */
303
- const beforeFn = config.beforeHook;
304
- const afterFn = config.afterHook;
305
- return utils_1.testFnWrapper.call(this, isStep ? 'Step' : 'Hook', { specFn: code, specFnArgs: args }, { beforeFn: beforeFn, beforeFnArgs: (context) => [hookParams === null || hookParams === void 0 ? void 0 : hookParams.step, context] }, { afterFn: afterFn, afterFnArgs: (context) => [hookParams === null || hookParams === void 0 ? void 0 : hookParams.step, context] }, cid, retryTest);
306
- };
307
- }
308
- }
309
- exports.CucumberAdapter = CucumberAdapter;
310
- const _CucumberAdapter = CucumberAdapter;
311
- const adapterFactory = {};
312
- exports.adapterFactory = adapterFactory;
313
- /**
314
- * tested by smoke tests
315
- */
316
- /* istanbul ignore next */
317
- adapterFactory.init = async function (...args) {
318
- // @ts-ignore just passing through args
319
- const adapter = new _CucumberAdapter(...args);
320
- const instance = await adapter.init();
321
- return instance;
322
- };
323
- exports.default = adapterFactory;
@@ -1,33 +0,0 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import { PickleFilter } from '@cucumber/cucumber';
4
- import { Feature, Pickle, PickleStep, TestStep, TestStepResult } from '@cucumber/messages';
5
- import CucumberEventListener from './cucumberEventListener';
6
- import type { ReporterOptions } from './types';
7
- import { ReporterScenario } from './constants';
8
- declare class CucumberReporter {
9
- private _options;
10
- private _cid;
11
- private _specs;
12
- private _reporter;
13
- eventListener: CucumberEventListener;
14
- failedCount: number;
15
- private _tagsInTitle;
16
- private _scenarioLevelReport;
17
- private _featureStart?;
18
- private _scenarioStart?;
19
- private _testStart?;
20
- constructor(eventBroadcaster: EventEmitter, pickleFilter: PickleFilter, _options: ReporterOptions, _cid: string, _specs: string[], _reporter: EventEmitter);
21
- handleBeforeFeature(uri: string, feature: Feature): void;
22
- handleBeforeScenario(uri: string, feature: Feature, scenario: ReporterScenario): void;
23
- handleBeforeStep(uri: string, feature: Feature, scenario: Pickle, step: PickleStep | TestStep): void;
24
- handleAfterStep(uri: string, feature: Feature, scenario: Pickle, step: PickleStep | TestStep, result: TestStepResult): void;
25
- afterHook(uri: string, feature: Feature, scenario: Pickle, step: TestStep, result: TestStepResult): void;
26
- afterTest(uri: string, feature: Feature, scenario: Pickle, step: PickleStep, result: TestStepResult): void;
27
- handleAfterScenario(uri: string, feature: Feature, scenario: Pickle, result: TestStepResult): void;
28
- handleAfterFeature(uri: string, feature: Feature): void;
29
- emit(event: string, payload: any): void;
30
- getTitle(featureOrScenario: Feature | Pickle): string;
31
- }
32
- export default CucumberReporter;
33
- //# sourceMappingURL=reporter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reporter.d.ts","sourceRoot":"","sources":["../src/reporter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,EAAU,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAoC,MAAM,oBAAoB,CAAA;AAE5H,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAE3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAE9C,cAAM,gBAAgB;IAad,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,SAAS;IAfd,aAAa,EAAE,qBAAqB,CAAA;IACpC,WAAW,SAAI;IAEtB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,oBAAoB,CAAS;IACrC,OAAO,CAAC,aAAa,CAAC,CAAM;IAC5B,OAAO,CAAC,cAAc,CAAC,CAAM;IAC7B,OAAO,CAAC,UAAU,CAAC,CAAM;gBAGrB,gBAAgB,EAAE,YAAY,EAC9B,YAAY,EAAE,YAAY,EAClB,QAAQ,EAAE,eAAe,EACzB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EAAE,EAChB,SAAS,EAAE,YAAY;IAkBnC,mBAAmB,CAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAclD,oBAAoB,CAChB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,gBAAgB;IAgB9B,gBAAgB,CACZ,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,UAAU,GAAG,QAAQ;IAS/B,eAAe,CACX,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,UAAU,GAAG,QAAQ,EAC3B,MAAM,EAAE,cAAc;IAS1B,SAAS,CACL,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,cAAc;IAkB1B,SAAS,CACL,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,cAAc;IA+F1B,mBAAmB,CACf,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,cAAc;IAiB1B,kBAAkB,CAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAWjD,IAAI,CAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG;IAUjC,QAAQ,CAAE,iBAAiB,EAAE,OAAO,GAAG,MAAM;CAMhD;AAED,eAAe,gBAAgB,CAAA"}
package/build/reporter.js DELETED
@@ -1,211 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const cucumber_1 = require("@cucumber/cucumber");
7
- const cucumberEventListener_1 = __importDefault(require("./cucumberEventListener"));
8
- const utils_1 = require("./utils");
9
- class CucumberReporter {
10
- constructor(eventBroadcaster, pickleFilter, _options, _cid, _specs, _reporter) {
11
- this._options = _options;
12
- this._cid = _cid;
13
- this._specs = _specs;
14
- this._reporter = _reporter;
15
- this.failedCount = 0;
16
- this._tagsInTitle = this._options.tagsInTitle || false;
17
- this._scenarioLevelReport = this._options.scenarioLevelReporter;
18
- this.eventListener = new cucumberEventListener_1.default(eventBroadcaster, pickleFilter)
19
- .on('before-feature', this.handleBeforeFeature.bind(this))
20
- .on('before-scenario', this.handleBeforeScenario.bind(this))
21
- .on('after-scenario', this.handleAfterScenario.bind(this))
22
- .on('after-feature', this.handleAfterFeature.bind(this));
23
- if (!this._scenarioLevelReport) {
24
- this.eventListener
25
- .on('before-step', this.handleBeforeStep.bind(this))
26
- .on('after-step', this.handleAfterStep.bind(this));
27
- }
28
- }
29
- handleBeforeFeature(uri, feature) {
30
- this._featureStart = new Date();
31
- this.emit('suite:start', {
32
- uid: (0, utils_1.getFeatureId)(uri, feature),
33
- title: this.getTitle(feature),
34
- type: 'feature',
35
- file: uri,
36
- tags: feature.tags,
37
- description: feature.description,
38
- keyword: feature.keyword
39
- });
40
- }
41
- handleBeforeScenario(uri, feature, scenario) {
42
- this._scenarioStart = new Date();
43
- this._testStart = new Date();
44
- this.emit(this._scenarioLevelReport ? 'test:start' : 'suite:start', {
45
- uid: scenario.id,
46
- title: this.getTitle(scenario),
47
- parent: (0, utils_1.getFeatureId)(uri, feature),
48
- type: 'scenario',
49
- file: uri,
50
- tags: scenario.tags,
51
- rule: scenario.rule
52
- });
53
- }
54
- handleBeforeStep(uri, feature, scenario, step) {
55
- this._testStart = new Date();
56
- const type = (0, utils_1.getStepType)(step);
57
- const payload = (0, utils_1.buildStepPayload)(uri, feature, scenario, step, { type });
58
- this.emit(`${type}:start`, payload);
59
- }
60
- handleAfterStep(uri, feature, scenario, step, result) {
61
- const type = (0, utils_1.getStepType)(step);
62
- if (type === 'hook') {
63
- return this.afterHook(uri, feature, scenario, step, result);
64
- }
65
- return this.afterTest(uri, feature, scenario, step, result);
66
- }
67
- afterHook(uri, feature, scenario, step, result) {
68
- var _a;
69
- let error;
70
- if (result.message) {
71
- error = new Error(result.message.split('\n')[0]);
72
- error.stack = result.message;
73
- }
74
- const payload = (0, utils_1.buildStepPayload)(uri, feature, scenario, step, {
75
- type: 'hook',
76
- state: result.status,
77
- error,
78
- duration: Date.now() - ((_a = this._testStart) === null || _a === void 0 ? void 0 : _a.getTime())
79
- });
80
- this.emit('hook:end', payload);
81
- }
82
- afterTest(uri, feature, scenario, step, result) {
83
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
84
- let state = 'undefined';
85
- switch (result.status) {
86
- case cucumber_1.Status.FAILED:
87
- case cucumber_1.Status.UNDEFINED:
88
- state = 'fail';
89
- break;
90
- case cucumber_1.Status.PASSED:
91
- state = 'pass';
92
- break;
93
- case cucumber_1.Status.PENDING:
94
- state = 'pending';
95
- break;
96
- case cucumber_1.Status.SKIPPED:
97
- state = 'skip';
98
- break;
99
- case cucumber_1.Status.AMBIGUOUS:
100
- state = 'pending';
101
- break;
102
- }
103
- let error = result.message ? new Error(result.message) : undefined;
104
- let title = step
105
- ? step === null || step === void 0 ? void 0 : step.text
106
- : this.getTitle(scenario);
107
- if (result.status === cucumber_1.Status.UNDEFINED) {
108
- if (this._options.ignoreUndefinedDefinitions) {
109
- /**
110
- * mark test as pending
111
- */
112
- state = 'pending';
113
- title += ' (undefined step)';
114
- }
115
- else {
116
- /**
117
- * mark test as failed
118
- */
119
- this.failedCount++;
120
- const err = new Error((step ? `Step "${title}" is not defined. ` : `Scenario ${title} has undefined steps. `) +
121
- 'You can ignore this error by setting cucumberOpts.ignoreUndefinedDefinitions as true.');
122
- err.stack = `${err.message}\n\tat Feature(${uri}):1:1\n`;
123
- const featChildren = (_a = feature.children) === null || _a === void 0 ? void 0 : _a.find(c => { var _a; return scenario.astNodeIds && ((_a = c.scenario) === null || _a === void 0 ? void 0 : _a.id) === scenario.astNodeIds[0]; });
124
- if (featChildren) {
125
- err.stack += `\tat Scenario(${(_b = featChildren.scenario) === null || _b === void 0 ? void 0 : _b.name}):${(_d = (_c = featChildren.scenario) === null || _c === void 0 ? void 0 : _c.location) === null || _d === void 0 ? void 0 : _d.line}:${(_f = (_e = featChildren.scenario) === null || _e === void 0 ? void 0 : _e.location) === null || _f === void 0 ? void 0 : _f.column}\n`;
126
- const featStep = (_h = (_g = featChildren.scenario) === null || _g === void 0 ? void 0 : _g.steps) === null || _h === void 0 ? void 0 : _h.find(s => step.astNodeIds && s.id === step.astNodeIds[0]);
127
- if (featStep) {
128
- err.stack += `\tat Step(${featStep.text}):${(_j = featStep.location) === null || _j === void 0 ? void 0 : _j.line}:${(_k = featStep.location) === null || _k === void 0 ? void 0 : _k.column}\n`;
129
- }
130
- }
131
- error = err;
132
- }
133
- }
134
- else if (result.status === cucumber_1.Status.FAILED && !result.willBeRetried) {
135
- error = new Error((_l = result.message) === null || _l === void 0 ? void 0 : _l.split('\n')[0]);
136
- error.stack = result.message;
137
- this.failedCount++;
138
- }
139
- else if (result.status === cucumber_1.Status.AMBIGUOUS && this._options.failAmbiguousDefinitions) {
140
- state = 'fail';
141
- this.failedCount++;
142
- error = new Error((_m = result.message) === null || _m === void 0 ? void 0 : _m.split('\n')[0]);
143
- error.stack = result.message;
144
- }
145
- else if (result.willBeRetried) {
146
- state = 'retry';
147
- }
148
- const common = {
149
- title: title,
150
- state,
151
- error,
152
- duration: Date.now() - ((_o = this._testStart) === null || _o === void 0 ? void 0 : _o.getTime()),
153
- passed: ['pass', 'skip'].includes(state),
154
- file: uri
155
- };
156
- const payload = step
157
- ? (0, utils_1.buildStepPayload)(uri, feature, scenario, step, {
158
- type: 'step',
159
- ...common
160
- })
161
- : {
162
- type: 'scenario',
163
- uid: scenario.id,
164
- parent: (0, utils_1.getFeatureId)(uri, feature),
165
- tags: scenario.tags,
166
- ...common
167
- };
168
- this.emit('test:' + state, payload);
169
- }
170
- handleAfterScenario(uri, feature, scenario, result) {
171
- var _a;
172
- if (this._scenarioLevelReport) {
173
- return this.afterTest(uri, feature, scenario, { id: scenario.id }, result);
174
- }
175
- this.emit('suite:end', {
176
- uid: scenario.id,
177
- title: this.getTitle(scenario),
178
- parent: (0, utils_1.getFeatureId)(uri, feature),
179
- type: 'scenario',
180
- file: uri,
181
- duration: Date.now() - ((_a = this._scenarioStart) === null || _a === void 0 ? void 0 : _a.getTime()),
182
- tags: scenario.tags
183
- });
184
- }
185
- handleAfterFeature(uri, feature) {
186
- var _a;
187
- this.emit('suite:end', {
188
- uid: (0, utils_1.getFeatureId)(uri, feature),
189
- title: this.getTitle(feature),
190
- type: 'feature',
191
- file: uri,
192
- duration: Date.now() - ((_a = this._featureStart) === null || _a === void 0 ? void 0 : _a.getTime()),
193
- tags: feature.tags
194
- });
195
- }
196
- emit(event, payload) {
197
- let message = (0, utils_1.formatMessage)({ payload });
198
- message.cid = this._cid;
199
- message.specs = this._specs;
200
- message.uid = payload.uid;
201
- this._reporter.emit(event, message);
202
- }
203
- getTitle(featureOrScenario) {
204
- const name = featureOrScenario.name;
205
- const tags = featureOrScenario.tags;
206
- if (!this._tagsInTitle || !tags || !tags.length)
207
- return name;
208
- return `${tags.map((tag) => tag.name).join(', ')}: ${name}`;
209
- }
210
- }
211
- exports.default = CucumberReporter;