@wdio/mocha-framework 7.20.3 → 7.20.8-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 +10 -13
- package/build/index.d.ts +6 -15
- package/build/index.d.ts.map +1 -1
- package/build/index.js +62 -128
- package/build/types.d.ts +0 -7
- package/build/types.d.ts.map +1 -1
- package/build/types.js +1 -2
- package/build/utils.d.ts +1 -2
- package/build/utils.d.ts.map +1 -1
- package/build/utils.js +2 -8
- package/package.json +16 -11
|
@@ -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,15 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.MOCHA_TIMEOUT_MESSAGE_REPLACEMENT = exports.MOCHA_TIMEOUT_MESSAGE = exports.NOOP = exports.EVENTS = exports.INTERFACES = void 0;
|
|
4
|
-
exports.INTERFACES = {
|
|
5
|
-
bdd: ['it', 'before', 'beforeEach', 'after', 'afterEach'],
|
|
1
|
+
export const INTERFACES = {
|
|
2
|
+
bdd: ['it', 'specify', 'before', 'beforeEach', 'after', 'afterEach'],
|
|
6
3
|
tdd: ['test', 'suiteSetup', 'setup', 'suiteTeardown', 'teardown'],
|
|
7
4
|
qunit: ['test', 'before', 'beforeEach', 'after', 'afterEach']
|
|
8
5
|
};
|
|
6
|
+
export const TEST_INTERFACES = {
|
|
7
|
+
bdd: ['it', 'specify'],
|
|
8
|
+
tdd: ['test'],
|
|
9
|
+
qunit: ['test']
|
|
10
|
+
};
|
|
9
11
|
/**
|
|
10
12
|
* to map Mocha events to WDIO events
|
|
11
13
|
*/
|
|
12
|
-
|
|
14
|
+
export const EVENTS = {
|
|
13
15
|
'suite': 'suite:start',
|
|
14
16
|
'suite end': 'suite:end',
|
|
15
17
|
'test': 'test:start',
|
|
@@ -21,10 +23,5 @@ exports.EVENTS = {
|
|
|
21
23
|
'retry': 'test:retry',
|
|
22
24
|
'pending': 'test:pending'
|
|
23
25
|
};
|
|
24
|
-
const NOOP = function () { };
|
|
25
|
-
|
|
26
|
-
exports.MOCHA_TIMEOUT_MESSAGE = 'For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.';
|
|
27
|
-
exports.MOCHA_TIMEOUT_MESSAGE_REPLACEMENT = [
|
|
28
|
-
'The execution in the test "%s %s" took too long. Try to reduce the run time or',
|
|
29
|
-
'increase your timeout for test specs (https://webdriver.io/docs/timeouts).'
|
|
30
|
-
].join(' ');
|
|
26
|
+
export const NOOP = /* istanbul ignore next */ function () { };
|
|
27
|
+
export const MOCHA_TIMEOUT_MESSAGE = 'For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.';
|
package/build/index.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="expect-webdriverio/types/standalone" />
|
|
3
|
-
import Mocha from 'mocha';
|
|
4
2
|
import type { Capabilities, Services } from '@wdio/types';
|
|
5
|
-
import type { MochaConfig, MochaOpts as MochaOptsImport, FrameworkMessage,
|
|
6
|
-
import type { EventEmitter } from 'events';
|
|
7
|
-
import type ExpectWebdriverIO from 'expect-webdriverio';
|
|
3
|
+
import type { MochaConfig, MochaOpts as MochaOptsImport, FrameworkMessage, MochaError } from './types';
|
|
4
|
+
import type { EventEmitter } from 'node:events';
|
|
8
5
|
declare type EventTypes = 'hook' | 'test' | 'suite';
|
|
9
6
|
/**
|
|
10
7
|
* Mocha runner
|
|
@@ -30,15 +27,14 @@ declare class MochaAdapter {
|
|
|
30
27
|
_loadFiles(mochaOpts: MochaOptsImport): Promise<void>;
|
|
31
28
|
hasTests(): boolean;
|
|
32
29
|
run(): Promise<unknown>;
|
|
33
|
-
options(options: MochaOptsImport
|
|
34
|
-
preRequire(
|
|
30
|
+
options(options: MochaOptsImport): Promise<any>[];
|
|
31
|
+
preRequire(): Promise<any>[];
|
|
35
32
|
/**
|
|
36
33
|
* Hooks which are added as true Mocha hooks need to call done() to notify async
|
|
37
34
|
*/
|
|
38
35
|
wrapHook(hookName: keyof Services.HookFunctions): () => Promise<void | unknown[]>;
|
|
39
|
-
prepareMessage(hookName: keyof Services.HookFunctions): FormattedMessage;
|
|
40
|
-
|
|
41
|
-
requireExternalModules(modules: string[], context: MochaContext): void;
|
|
36
|
+
prepareMessage(hookName: keyof Services.HookFunctions): import("./types").FormattedMessage;
|
|
37
|
+
requireExternalModules(modules: string[]): Promise<any>[];
|
|
42
38
|
emit(event: string, payload: any, err?: MochaError): void;
|
|
43
39
|
getSyncEventIdStart(type: EventTypes): string;
|
|
44
40
|
getSyncEventIdEnd(type: EventTypes): string;
|
|
@@ -54,10 +50,5 @@ declare global {
|
|
|
54
50
|
interface MochaOpts extends MochaOptsImport {
|
|
55
51
|
}
|
|
56
52
|
}
|
|
57
|
-
namespace NodeJS {
|
|
58
|
-
interface Global {
|
|
59
|
-
expect: ExpectWebdriverIO.Expect;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
53
|
}
|
|
63
54
|
//# sourceMappingURL=index.d.ts.map
|
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,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B,UAAU,SAAU,SAAQ,eAAe;SAAG;KACjD;CACJ"}
|
package/build/index.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const logger_1 = __importDefault(require("@wdio/logger"));
|
|
11
|
-
const utils_1 = require("@wdio/utils");
|
|
12
|
-
const utils_2 = require("./utils");
|
|
13
|
-
const constants_1 = require("./constants");
|
|
14
|
-
const log = (0, logger_1.default)('@wdio/mocha-framework');
|
|
1
|
+
import url from 'node:url';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import Mocha from 'mocha';
|
|
4
|
+
import logger from '@wdio/logger';
|
|
5
|
+
import { runTestInFiberContext, executeHooksWithArgs } from '@wdio/utils';
|
|
6
|
+
import { loadModule } from './utils.js';
|
|
7
|
+
import { formatMessage } from './common/utils.js';
|
|
8
|
+
import { INTERFACES, TEST_INTERFACES, EVENTS, NOOP } from './constants.js';
|
|
9
|
+
const log = logger('@wdio/mocha-framework');
|
|
15
10
|
/**
|
|
16
11
|
* Extracts the mocha UI type following this convention:
|
|
17
12
|
* - If the mochaOpts.ui provided doesn't contain a '-' then the full name
|
|
@@ -23,45 +18,51 @@ const log = (0, logger_1.default)('@wdio/mocha-framework');
|
|
|
23
18
|
*/
|
|
24
19
|
const MOCHA_UI_TYPE_EXTRACTOR = /^(?:.*-)?([^-.]+)(?:.js)?$/;
|
|
25
20
|
const DEFAULT_INTERFACE_TYPE = 'bdd';
|
|
21
|
+
const FILE_PROTOCOL = 'file://';
|
|
26
22
|
/**
|
|
27
23
|
* Mocha runner
|
|
28
24
|
*/
|
|
29
25
|
class MochaAdapter {
|
|
26
|
+
_cid;
|
|
27
|
+
_config;
|
|
28
|
+
_specs;
|
|
29
|
+
_capabilities;
|
|
30
|
+
_reporter;
|
|
31
|
+
_mocha;
|
|
32
|
+
_runner;
|
|
33
|
+
_specLoadError;
|
|
34
|
+
_level = 0;
|
|
35
|
+
_hasTests = true;
|
|
36
|
+
_suiteIds = ['0'];
|
|
37
|
+
_suiteCnt = new Map();
|
|
38
|
+
_hookCnt = new Map();
|
|
39
|
+
_testCnt = new Map();
|
|
40
|
+
_suiteStartDate = Date.now();
|
|
30
41
|
constructor(_cid, _config, _specs, _capabilities, _reporter) {
|
|
31
42
|
this._cid = _cid;
|
|
32
43
|
this._config = _config;
|
|
33
44
|
this._specs = _specs;
|
|
34
45
|
this._capabilities = _capabilities;
|
|
35
46
|
this._reporter = _reporter;
|
|
36
|
-
this._level = 0;
|
|
37
|
-
this._hasTests = true;
|
|
38
|
-
this._suiteIds = ['0'];
|
|
39
|
-
this._suiteCnt = new Map();
|
|
40
|
-
this._hookCnt = new Map();
|
|
41
|
-
this._testCnt = new Map();
|
|
42
|
-
this._suiteStartDate = Date.now();
|
|
43
47
|
this._config = Object.assign({
|
|
44
48
|
mochaOpts: {}
|
|
45
49
|
}, _config);
|
|
46
50
|
}
|
|
47
51
|
async init() {
|
|
48
52
|
const { mochaOpts } = this._config;
|
|
49
|
-
const mocha = this._mocha = new
|
|
53
|
+
const mocha = this._mocha = new Mocha(mochaOpts);
|
|
50
54
|
await mocha.loadFilesAsync();
|
|
51
|
-
mocha.reporter(
|
|
55
|
+
mocha.reporter(NOOP);
|
|
52
56
|
mocha.fullTrace();
|
|
53
|
-
this._specs.forEach((spec) => mocha.addFile(spec));
|
|
54
|
-
mocha.suite.on('pre-require', this.preRequire.bind(this));
|
|
55
|
-
await this._loadFiles(mochaOpts);
|
|
56
57
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
58
|
+
* as Mocha doesn't support file:// formats yet we have to
|
|
59
|
+
* remove it before adding it to Mocha
|
|
59
60
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
this._specs.forEach((spec) => mocha.addFile(spec.startsWith(FILE_PROTOCOL)
|
|
62
|
+
? url.fileURLToPath(spec)
|
|
63
|
+
: spec));
|
|
64
|
+
mocha.suite.on('pre-require', this.preRequire.bind(this));
|
|
65
|
+
await this._loadFiles(mochaOpts);
|
|
65
66
|
return this;
|
|
66
67
|
}
|
|
67
68
|
async _loadFiles(mochaOpts) {
|
|
@@ -70,7 +71,7 @@ class MochaAdapter {
|
|
|
70
71
|
/**
|
|
71
72
|
* grep
|
|
72
73
|
*/
|
|
73
|
-
const mochaRunner = new
|
|
74
|
+
const mochaRunner = new Mocha.Runner(this._mocha.suite, { delay: false });
|
|
74
75
|
if (mochaOpts.grep) {
|
|
75
76
|
mochaRunner.grep(this._mocha.options.grep, mochaOpts.invert);
|
|
76
77
|
}
|
|
@@ -101,11 +102,11 @@ class MochaAdapter {
|
|
|
101
102
|
runtimeError = err;
|
|
102
103
|
return resolve(1);
|
|
103
104
|
}
|
|
104
|
-
Object.keys(
|
|
105
|
+
Object.keys(EVENTS).forEach((e) => this._runner.on(e, this.emit.bind(this, EVENTS[e])));
|
|
105
106
|
this._runner.suite.beforeAll(this.wrapHook('beforeSuite'));
|
|
106
107
|
this._runner.suite.afterAll(this.wrapHook('afterSuite'));
|
|
107
108
|
});
|
|
108
|
-
await
|
|
109
|
+
await executeHooksWithArgs('after', this._config.after, [runtimeError || result, this._capabilities, this._specs]);
|
|
109
110
|
/**
|
|
110
111
|
* in case the spec has a runtime error throw after the wdio hook
|
|
111
112
|
*/
|
|
@@ -114,132 +115,66 @@ class MochaAdapter {
|
|
|
114
115
|
}
|
|
115
116
|
return result;
|
|
116
117
|
}
|
|
117
|
-
options(options
|
|
118
|
+
options(options) {
|
|
118
119
|
let { require = [], compilers = [] } = options;
|
|
119
120
|
if (typeof require === 'string') {
|
|
120
121
|
require = [require];
|
|
121
122
|
}
|
|
122
|
-
this.requireExternalModules([...compilers, ...require]
|
|
123
|
+
return this.requireExternalModules([...compilers, ...require]);
|
|
123
124
|
}
|
|
124
|
-
preRequire(
|
|
125
|
+
preRequire() {
|
|
125
126
|
const options = this._config.mochaOpts;
|
|
126
127
|
const match = MOCHA_UI_TYPE_EXTRACTOR.exec(options.ui);
|
|
127
|
-
const type = (match &&
|
|
128
|
+
const type = (match && INTERFACES[match[1]] && match[1]) || DEFAULT_INTERFACE_TYPE;
|
|
128
129
|
const hookArgsFn = (context) => {
|
|
129
|
-
|
|
130
|
-
return [{ ...context.test, parent: (_b = (_a = context.test) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.title }, context];
|
|
130
|
+
return [{ ...context.test, parent: context.test?.parent?.title }, context];
|
|
131
131
|
};
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
(0, utils_1.runTestInFiberContext)(isTest, isTest ? this._config.beforeTest : this._config.beforeHook,
|
|
132
|
+
INTERFACES[type].forEach((fnName) => {
|
|
133
|
+
const isTest = TEST_INTERFACES[type].flatMap((testCommand) => [testCommand, testCommand + '.only']).includes(fnName);
|
|
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);
|
|
138
137
|
});
|
|
139
|
-
this.options(options
|
|
138
|
+
return this.options(options);
|
|
140
139
|
}
|
|
141
140
|
/**
|
|
142
141
|
* Hooks which are added as true Mocha hooks need to call done() to notify async
|
|
143
142
|
*/
|
|
144
143
|
wrapHook(hookName) {
|
|
145
|
-
return () =>
|
|
144
|
+
return () => executeHooksWithArgs(hookName, this._config[hookName], [this.prepareMessage(hookName)]).catch((e) => {
|
|
146
145
|
log.error(`Error in ${hookName} hook: ${e.stack.slice(7)}`);
|
|
147
146
|
});
|
|
148
147
|
}
|
|
149
148
|
prepareMessage(hookName) {
|
|
150
|
-
var _a, _b, _c;
|
|
151
149
|
const params = { type: hookName };
|
|
152
150
|
switch (hookName) {
|
|
153
151
|
case 'beforeSuite':
|
|
154
152
|
this._suiteStartDate = Date.now();
|
|
155
|
-
params.payload =
|
|
153
|
+
params.payload = this._runner?.suite.suites[0];
|
|
156
154
|
break;
|
|
157
155
|
case 'afterSuite':
|
|
158
|
-
params.payload =
|
|
159
|
-
|
|
156
|
+
params.payload = this._runner?.suite.suites[0];
|
|
157
|
+
if (params.payload) {
|
|
158
|
+
params.payload.duration = params.payload.duration || (Date.now() - this._suiteStartDate);
|
|
159
|
+
}
|
|
160
160
|
break;
|
|
161
161
|
case 'beforeTest':
|
|
162
162
|
case 'afterTest':
|
|
163
|
-
params.payload =
|
|
163
|
+
params.payload = this._runner?.test;
|
|
164
164
|
break;
|
|
165
165
|
}
|
|
166
|
-
return
|
|
167
|
-
}
|
|
168
|
-
formatMessage(params) {
|
|
169
|
-
var _a, _b, _c;
|
|
170
|
-
let message = {
|
|
171
|
-
type: params.type
|
|
172
|
-
};
|
|
173
|
-
const mochaAllHooksIfPresent = (_b = (_a = params.payload) === null || _a === void 0 ? void 0 : _a.title) === null || _b === void 0 ? void 0 : _b.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(constants_1.MOCHA_TIMEOUT_MESSAGE)) {
|
|
179
|
-
const replacement = (0, util_1.format)(constants_1.MOCHA_TIMEOUT_MESSAGE_REPLACEMENT, params.payload.parent.title, params.payload.title);
|
|
180
|
-
params.err.message = params.err.message.replace(constants_1.MOCHA_TIMEOUT_MESSAGE, replacement);
|
|
181
|
-
params.err.stack = params.err.stack.replace(constants_1.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 (((_c = params.payload.parent) === null || _c === void 0 ? void 0 : _c.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
|
-
requireExternalModules(modules
|
|
234
|
-
modules.
|
|
168
|
+
requireExternalModules(modules) {
|
|
169
|
+
return modules.map((module) => {
|
|
235
170
|
if (!module) {
|
|
236
|
-
return;
|
|
171
|
+
return Promise.resolve();
|
|
237
172
|
}
|
|
238
173
|
module = module.replace(/.*:/, '');
|
|
239
174
|
if (module.substr(0, 1) === '.') {
|
|
240
|
-
module =
|
|
175
|
+
module = path.join(process.cwd(), module);
|
|
241
176
|
}
|
|
242
|
-
|
|
177
|
+
return loadModule(module);
|
|
243
178
|
});
|
|
244
179
|
}
|
|
245
180
|
emit(event, payload, err) {
|
|
@@ -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);
|
|
@@ -309,13 +244,12 @@ class MochaAdapter {
|
|
|
309
244
|
throw new Error(`Unknown message type : ${message.type}`);
|
|
310
245
|
}
|
|
311
246
|
}
|
|
312
|
-
exports.MochaAdapter = MochaAdapter;
|
|
313
247
|
const adapterFactory = {};
|
|
314
|
-
exports.adapterFactory = adapterFactory;
|
|
315
248
|
adapterFactory.init = async function (...args) {
|
|
316
249
|
// @ts-ignore just passing through args
|
|
317
250
|
const adapter = new MochaAdapter(...args);
|
|
318
251
|
const instance = await adapter.init();
|
|
319
252
|
return instance;
|
|
320
253
|
};
|
|
321
|
-
|
|
254
|
+
export default adapterFactory;
|
|
255
|
+
export { MochaAdapter, adapterFactory };
|
package/build/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Options } from '@wdio/types';
|
|
2
|
-
import type Mocha from 'mocha';
|
|
3
2
|
export interface MochaOpts {
|
|
4
3
|
/**
|
|
5
4
|
* The `require` option is useful when you want to add or extend some
|
|
@@ -104,10 +103,4 @@ export interface FormattedMessage {
|
|
|
104
103
|
error?: MochaError;
|
|
105
104
|
context?: any;
|
|
106
105
|
}
|
|
107
|
-
export interface MochaContext {
|
|
108
|
-
context: Mocha.MochaGlobals;
|
|
109
|
-
file: string;
|
|
110
|
-
mocha: Mocha;
|
|
111
|
-
options: MochaOpts;
|
|
112
|
-
}
|
|
113
106
|
//# sourceMappingURL=types.d.ts.map
|
package/build/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,MAAM,WAAW,SAAS;IACtB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB;;OAEG;IACH,MAAM,CAAC,E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1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/build/utils.d.ts
CHANGED
package/build/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,wBAAsB,UAAU,CAAE,IAAI,EAAE,MAAM,gBAQ7C"}
|
package/build/utils.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadModule = void 0;
|
|
4
|
-
function loadModule(name, context) {
|
|
1
|
+
export async function loadModule(name) {
|
|
5
2
|
try {
|
|
6
|
-
|
|
7
|
-
module.context = context;
|
|
8
|
-
require(name);
|
|
3
|
+
return await import(name);
|
|
9
4
|
}
|
|
10
5
|
catch (err) {
|
|
11
6
|
throw new Error(`Module ${name} can't get loaded. Are you sure you have installed it?\n` +
|
|
@@ -13,4 +8,3 @@ function loadModule(name, context) {
|
|
|
13
8
|
'these external modules globally too!');
|
|
14
9
|
}
|
|
15
10
|
}
|
|
16
|
-
exports.loadModule = loadModule;
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wdio/mocha-framework",
|
|
3
|
-
"version": "7.20.
|
|
3
|
+
"version": "7.20.8-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",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"main": "./build/index",
|
|
9
8
|
"engines": {
|
|
10
|
-
"node": ">=
|
|
9
|
+
"node": "^16.13 || >=18"
|
|
11
10
|
},
|
|
12
11
|
"repository": {
|
|
13
12
|
"type": "git",
|
|
14
|
-
"url": "git://github.com/webdriverio/webdriverio.git"
|
|
13
|
+
"url": "git://github.com/webdriverio/webdriverio.git",
|
|
14
|
+
"directory": "packages/wdio-mocha-framework"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|
|
17
17
|
"webdriver",
|
|
@@ -21,12 +21,18 @@
|
|
|
21
21
|
"bugs": {
|
|
22
22
|
"url": "https://github.com/webdriverio/webdriverio/issues"
|
|
23
23
|
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"exports": {
|
|
26
|
+
"./common": "./build/common/utils.js",
|
|
27
|
+
".": "./build/index.js"
|
|
28
|
+
},
|
|
29
|
+
"types": "./build/index.d.ts",
|
|
30
|
+
"typeScriptVersion": "3.8.3",
|
|
24
31
|
"dependencies": {
|
|
25
|
-
"@types/mocha": "^
|
|
26
|
-
"@wdio/logger": "7.
|
|
27
|
-
"@wdio/types": "7.20.
|
|
28
|
-
"@wdio/utils": "7.20.
|
|
29
|
-
"expect-webdriverio": "^3.0.0",
|
|
32
|
+
"@types/mocha": "^10.0.0",
|
|
33
|
+
"@wdio/logger": "7.20.8-alpha.504+428a9d729",
|
|
34
|
+
"@wdio/types": "7.20.8-alpha.504+428a9d729",
|
|
35
|
+
"@wdio/utils": "7.20.8-alpha.504+428a9d729",
|
|
30
36
|
"mocha": "^10.0.0"
|
|
31
37
|
},
|
|
32
38
|
"devDependencies": {
|
|
@@ -35,6 +41,5 @@
|
|
|
35
41
|
"publishConfig": {
|
|
36
42
|
"access": "public"
|
|
37
43
|
},
|
|
38
|
-
"
|
|
39
|
-
"gitHead": "df5cbf4f557ddc04f49ebc25b9a74231fdd44f2b"
|
|
44
|
+
"gitHead": "428a9d729ae6231968a60908732fa3f607d195e9"
|
|
40
45
|
}
|