@wdio/mocha-framework 8.0.0-alpha.412 → 8.0.0-alpha.504
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/common/utils.d.ts +3 -0
- package/build/common/utils.d.ts.map +1 -0
- package/build/common/utils.js +66 -0
- package/build/constants.d.ts +6 -2
- package/build/constants.d.ts.map +1 -1
- package/build/constants.js +6 -5
- package/build/index.d.ts +2 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +5 -70
- package/package.json +9 -6
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/common/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAElE,wBAAgB,aAAa,CAAE,MAAM,EAAE,gBAAgB,oBA4EtD"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { MOCHA_TIMEOUT_MESSAGE } from '../constants.js';
|
|
2
|
+
export function formatMessage(params) {
|
|
3
|
+
let message = {
|
|
4
|
+
type: params.type
|
|
5
|
+
};
|
|
6
|
+
const mochaAllHooksIfPresent = params.payload?.title?.match(/^"(before|after)( all| each)?" hook/);
|
|
7
|
+
if (params.err) {
|
|
8
|
+
/**
|
|
9
|
+
* replace "Ensure the done() callback is being called in this test." with a more meaningful message
|
|
10
|
+
*/
|
|
11
|
+
if (params.err && params.err.message && params.err.message.includes(MOCHA_TIMEOUT_MESSAGE)) {
|
|
12
|
+
const replacement = (`The execution in the test "${params.payload.parent.title} ${params.payload.title}" took too long. Try to reduce the run time or ` +
|
|
13
|
+
'increase your timeout for test specs (https://webdriver.io/docs/timeouts).');
|
|
14
|
+
params.err.message = params.err.message.replace(MOCHA_TIMEOUT_MESSAGE, replacement);
|
|
15
|
+
params.err.stack = params.err.stack.replace(MOCHA_TIMEOUT_MESSAGE, replacement);
|
|
16
|
+
}
|
|
17
|
+
message.error = {
|
|
18
|
+
name: params.err.name,
|
|
19
|
+
message: params.err.message,
|
|
20
|
+
stack: params.err.stack,
|
|
21
|
+
type: params.err.type || params.err.name,
|
|
22
|
+
expected: params.err.expected,
|
|
23
|
+
actual: params.err.actual
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* hook failures are emitted as "test:fail"
|
|
27
|
+
*/
|
|
28
|
+
if (mochaAllHooksIfPresent) {
|
|
29
|
+
message.type = 'hook:end';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (params.payload) {
|
|
33
|
+
message.title = params.payload.title;
|
|
34
|
+
message.parent = params.payload.parent ? params.payload.parent.title : null;
|
|
35
|
+
let fullTitle = message.title;
|
|
36
|
+
if (params.payload.parent) {
|
|
37
|
+
let parent = params.payload.parent;
|
|
38
|
+
while (parent && parent.title) {
|
|
39
|
+
fullTitle = parent.title + '.' + fullTitle;
|
|
40
|
+
parent = parent.parent;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
message.fullTitle = fullTitle;
|
|
44
|
+
message.pending = params.payload.pending || false;
|
|
45
|
+
message.file = params.payload.file;
|
|
46
|
+
message.duration = params.payload.duration;
|
|
47
|
+
/**
|
|
48
|
+
* Add the current test title to the payload for cases where it helps to
|
|
49
|
+
* identify the test, e.g. when running inside a beforeEach hook
|
|
50
|
+
*/
|
|
51
|
+
if (params.payload.ctx && params.payload.ctx.currentTest) {
|
|
52
|
+
message.currentTest = params.payload.ctx.currentTest.title;
|
|
53
|
+
}
|
|
54
|
+
if (params.type.match(/Test/)) {
|
|
55
|
+
message.passed = (params.payload.state === 'passed');
|
|
56
|
+
}
|
|
57
|
+
if (params.payload.parent?.title && mochaAllHooksIfPresent) {
|
|
58
|
+
const hookName = mochaAllHooksIfPresent[0];
|
|
59
|
+
message.title = `${hookName} for ${params.payload.parent.title}`;
|
|
60
|
+
}
|
|
61
|
+
if (params.payload.context) {
|
|
62
|
+
message.context = params.payload.context;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return message;
|
|
66
|
+
}
|
package/build/constants.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export declare const INTERFACES: {
|
|
2
|
-
readonly bdd: readonly ["it", "before", "beforeEach", "after", "afterEach"];
|
|
2
|
+
readonly bdd: readonly ["it", "specify", "before", "beforeEach", "after", "afterEach"];
|
|
3
3
|
readonly tdd: readonly ["test", "suiteSetup", "setup", "suiteTeardown", "teardown"];
|
|
4
4
|
readonly qunit: readonly ["test", "before", "beforeEach", "after", "afterEach"];
|
|
5
5
|
};
|
|
6
|
+
export declare const TEST_INTERFACES: {
|
|
7
|
+
readonly bdd: readonly ["it", "specify"];
|
|
8
|
+
readonly tdd: readonly ["test"];
|
|
9
|
+
readonly qunit: readonly ["test"];
|
|
10
|
+
};
|
|
6
11
|
/**
|
|
7
12
|
* to map Mocha events to WDIO events
|
|
8
13
|
*/
|
|
@@ -20,5 +25,4 @@ export declare const EVENTS: {
|
|
|
20
25
|
};
|
|
21
26
|
export declare const NOOP: () => void;
|
|
22
27
|
export declare const MOCHA_TIMEOUT_MESSAGE = "For async tests and hooks, ensure \"done()\" is called; if returning a Promise, ensure it resolves.";
|
|
23
|
-
export declare const MOCHA_TIMEOUT_MESSAGE_REPLACEMENT: string;
|
|
24
28
|
//# sourceMappingURL=constants.d.ts.map
|
package/build/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;;;CAIb,CAAA;AAEV;;GAEG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;CAWT,CAAA;AAEV,eAAO,MAAM,IAAI,YAA6C,CAAA;AAC9D,eAAO,MAAM,qBAAqB,wGAAsG,CAAA
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;;;CAIb,CAAA;AAEV,eAAO,MAAM,eAAe;;;;CAIlB,CAAA;AAEV;;GAEG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;CAWT,CAAA;AAEV,eAAO,MAAM,IAAI,YAA6C,CAAA;AAC9D,eAAO,MAAM,qBAAqB,wGAAsG,CAAA"}
|
package/build/constants.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export const INTERFACES = {
|
|
2
|
-
bdd: ['it', 'before', 'beforeEach', 'after', 'afterEach'],
|
|
2
|
+
bdd: ['it', 'specify', 'before', 'beforeEach', 'after', 'afterEach'],
|
|
3
3
|
tdd: ['test', 'suiteSetup', 'setup', 'suiteTeardown', 'teardown'],
|
|
4
4
|
qunit: ['test', 'before', 'beforeEach', 'after', 'afterEach']
|
|
5
5
|
};
|
|
6
|
+
export const TEST_INTERFACES = {
|
|
7
|
+
bdd: ['it', 'specify'],
|
|
8
|
+
tdd: ['test'],
|
|
9
|
+
qunit: ['test']
|
|
10
|
+
};
|
|
6
11
|
/**
|
|
7
12
|
* to map Mocha events to WDIO events
|
|
8
13
|
*/
|
|
@@ -20,7 +25,3 @@ export const EVENTS = {
|
|
|
20
25
|
};
|
|
21
26
|
export const NOOP = /* istanbul ignore next */ function () { };
|
|
22
27
|
export const MOCHA_TIMEOUT_MESSAGE = 'For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.';
|
|
23
|
-
export const MOCHA_TIMEOUT_MESSAGE_REPLACEMENT = [
|
|
24
|
-
'The execution in the test "%s %s" took too long. Try to reduce the run time or',
|
|
25
|
-
'increase your timeout for test specs (https://webdriver.io/docs/timeouts).'
|
|
26
|
-
].join(' ');
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Capabilities, Services } from '@wdio/types';
|
|
3
|
-
import type { MochaConfig, MochaOpts as MochaOptsImport, FrameworkMessage,
|
|
3
|
+
import type { MochaConfig, MochaOpts as MochaOptsImport, FrameworkMessage, MochaError } from './types';
|
|
4
4
|
import type { EventEmitter } from 'node:events';
|
|
5
5
|
declare type EventTypes = 'hook' | 'test' | 'suite';
|
|
6
6
|
/**
|
|
@@ -33,8 +33,7 @@ declare class MochaAdapter {
|
|
|
33
33
|
* Hooks which are added as true Mocha hooks need to call done() to notify async
|
|
34
34
|
*/
|
|
35
35
|
wrapHook(hookName: keyof Services.HookFunctions): () => Promise<void | unknown[]>;
|
|
36
|
-
prepareMessage(hookName: keyof Services.HookFunctions): FormattedMessage;
|
|
37
|
-
formatMessage(params: FrameworkMessage): FormattedMessage;
|
|
36
|
+
prepareMessage(hookName: keyof Services.HookFunctions): import("./types").FormattedMessage;
|
|
38
37
|
requireExternalModules(modules: string[]): Promise<any>[];
|
|
39
38
|
emit(event: string, payload: any, err?: MochaError): void;
|
|
40
39
|
getSyncEventIdStart(type: EventTypes): string;
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAKzD,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,IAAI,eAAe,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACtG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAiB/C,aAAK,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAG3C;;GAEG;AACH,cAAM,YAAY;IAcV,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,SAAS;IAjBrB,OAAO,CAAC,MAAM,CAAC,CAA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/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import url from 'node:url';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { format } from 'node:util';
|
|
4
3
|
import Mocha from 'mocha';
|
|
5
4
|
import logger from '@wdio/logger';
|
|
6
5
|
import { runTestInFiberContext, executeHooksWithArgs } from '@wdio/utils';
|
|
7
6
|
import { loadModule } from './utils.js';
|
|
8
|
-
import {
|
|
7
|
+
import { formatMessage } from './common/utils.js';
|
|
8
|
+
import { INTERFACES, TEST_INTERFACES, EVENTS, NOOP } from './constants.js';
|
|
9
9
|
const log = logger('@wdio/mocha-framework');
|
|
10
10
|
/**
|
|
11
11
|
* Extracts the mocha UI type following this convention:
|
|
@@ -130,8 +130,7 @@ class MochaAdapter {
|
|
|
130
130
|
return [{ ...context.test, parent: context.test?.parent?.title }, context];
|
|
131
131
|
};
|
|
132
132
|
INTERFACES[type].forEach((fnName) => {
|
|
133
|
-
|
|
134
|
-
const isTest = [testCommand, testCommand + '.only'].includes(fnName);
|
|
133
|
+
const isTest = TEST_INTERFACES[type].flatMap((testCommand) => [testCommand, testCommand + '.only']).includes(fnName);
|
|
135
134
|
runTestInFiberContext(isTest, isTest ? this._config.beforeTest : this._config.beforeHook,
|
|
136
135
|
// @ts-ignore
|
|
137
136
|
hookArgsFn, isTest ? this._config.afterTest : this._config.afterHook, hookArgsFn, fnName, this._cid);
|
|
@@ -164,71 +163,7 @@ class MochaAdapter {
|
|
|
164
163
|
params.payload = this._runner?.test;
|
|
165
164
|
break;
|
|
166
165
|
}
|
|
167
|
-
return
|
|
168
|
-
}
|
|
169
|
-
formatMessage(params) {
|
|
170
|
-
let message = {
|
|
171
|
-
type: params.type
|
|
172
|
-
};
|
|
173
|
-
const mochaAllHooksIfPresent = params.payload?.title?.match(/^"(before|after)( all| each)?" hook/);
|
|
174
|
-
if (params.err) {
|
|
175
|
-
/**
|
|
176
|
-
* replace "Ensure the done() callback is being called in this test." with a more meaningful message
|
|
177
|
-
*/
|
|
178
|
-
if (params.err && params.err.message && params.err.message.includes(MOCHA_TIMEOUT_MESSAGE)) {
|
|
179
|
-
const replacement = format(MOCHA_TIMEOUT_MESSAGE_REPLACEMENT, params.payload.parent.title, params.payload.title);
|
|
180
|
-
params.err.message = params.err.message.replace(MOCHA_TIMEOUT_MESSAGE, replacement);
|
|
181
|
-
params.err.stack = params.err.stack.replace(MOCHA_TIMEOUT_MESSAGE, replacement);
|
|
182
|
-
}
|
|
183
|
-
message.error = {
|
|
184
|
-
name: params.err.name,
|
|
185
|
-
message: params.err.message,
|
|
186
|
-
stack: params.err.stack,
|
|
187
|
-
type: params.err.type || params.err.name,
|
|
188
|
-
expected: params.err.expected,
|
|
189
|
-
actual: params.err.actual
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* hook failures are emitted as "test:fail"
|
|
193
|
-
*/
|
|
194
|
-
if (mochaAllHooksIfPresent) {
|
|
195
|
-
message.type = 'hook:end';
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
if (params.payload) {
|
|
199
|
-
message.title = params.payload.title;
|
|
200
|
-
message.parent = params.payload.parent ? params.payload.parent.title : null;
|
|
201
|
-
let fullTitle = message.title;
|
|
202
|
-
if (params.payload.parent) {
|
|
203
|
-
let parent = params.payload.parent;
|
|
204
|
-
while (parent && parent.title) {
|
|
205
|
-
fullTitle = parent.title + '.' + fullTitle;
|
|
206
|
-
parent = parent.parent;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
message.fullTitle = fullTitle;
|
|
210
|
-
message.pending = params.payload.pending || false;
|
|
211
|
-
message.file = params.payload.file;
|
|
212
|
-
message.duration = params.payload.duration;
|
|
213
|
-
/**
|
|
214
|
-
* Add the current test title to the payload for cases where it helps to
|
|
215
|
-
* identify the test, e.g. when running inside a beforeEach hook
|
|
216
|
-
*/
|
|
217
|
-
if (params.payload.ctx && params.payload.ctx.currentTest) {
|
|
218
|
-
message.currentTest = params.payload.ctx.currentTest.title;
|
|
219
|
-
}
|
|
220
|
-
if (params.type.match(/Test/)) {
|
|
221
|
-
message.passed = (params.payload.state === 'passed');
|
|
222
|
-
}
|
|
223
|
-
if (params.payload.parent?.title && mochaAllHooksIfPresent) {
|
|
224
|
-
const hookName = mochaAllHooksIfPresent[0];
|
|
225
|
-
message.title = `${hookName} for ${params.payload.parent.title}`;
|
|
226
|
-
}
|
|
227
|
-
if (params.payload.context) {
|
|
228
|
-
message.context = params.payload.context;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return message;
|
|
166
|
+
return formatMessage(params);
|
|
232
167
|
}
|
|
233
168
|
requireExternalModules(modules) {
|
|
234
169
|
return modules.map((module) => {
|
|
@@ -249,7 +184,7 @@ class MochaAdapter {
|
|
|
249
184
|
*/
|
|
250
185
|
if (payload.root)
|
|
251
186
|
return;
|
|
252
|
-
let message =
|
|
187
|
+
let message = formatMessage({ type: event, payload, err });
|
|
253
188
|
message.cid = this._cid;
|
|
254
189
|
message.specs = this._specs;
|
|
255
190
|
message.uid = this.getUID(message);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wdio/mocha-framework",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.504+428a9d729",
|
|
4
4
|
"description": "A WebdriverIO plugin. Adapter for Mocha testing framework.",
|
|
5
5
|
"author": "Christian Bromann <mail@bromann.dev>",
|
|
6
6
|
"homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-mocha-framework",
|
|
@@ -22,14 +22,17 @@
|
|
|
22
22
|
"url": "https://github.com/webdriverio/webdriverio/issues"
|
|
23
23
|
},
|
|
24
24
|
"type": "module",
|
|
25
|
-
"exports":
|
|
25
|
+
"exports": {
|
|
26
|
+
"./common": "./build/common/utils.js",
|
|
27
|
+
".": "./build/index.js"
|
|
28
|
+
},
|
|
26
29
|
"types": "./build/index.d.ts",
|
|
27
30
|
"typeScriptVersion": "3.8.3",
|
|
28
31
|
"dependencies": {
|
|
29
32
|
"@types/mocha": "^10.0.0",
|
|
30
|
-
"@wdio/logger": "8.0.0-alpha.
|
|
31
|
-
"@wdio/types": "8.0.0-alpha.
|
|
32
|
-
"@wdio/utils": "8.0.0-alpha.
|
|
33
|
+
"@wdio/logger": "8.0.0-alpha.504+428a9d729",
|
|
34
|
+
"@wdio/types": "8.0.0-alpha.504+428a9d729",
|
|
35
|
+
"@wdio/utils": "8.0.0-alpha.504+428a9d729",
|
|
33
36
|
"mocha": "^10.0.0"
|
|
34
37
|
},
|
|
35
38
|
"devDependencies": {
|
|
@@ -38,5 +41,5 @@
|
|
|
38
41
|
"publishConfig": {
|
|
39
42
|
"access": "public"
|
|
40
43
|
},
|
|
41
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "428a9d729ae6231968a60908732fa3f607d195e9"
|
|
42
45
|
}
|