@wdio/mocha-framework 8.0.0-alpha.558 → 8.0.0-alpha.565
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.d.ts +13 -0
- package/build/common.d.ts.map +1 -0
- package/build/{common/utils.js → common.js} +58 -1
- package/build/index.d.ts +0 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +5 -51
- package/package.json +9 -6
- package/build/common/utils.d.ts +0 -3
- package/build/common/utils.d.ts.map +0 -1
- package/build/utils.d.ts +0 -2
- package/build/utils.d.ts.map +0 -1
- package/build/utils.js +0 -10
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FormattedMessage, FrameworkMessage, MochaOpts } from './types';
|
|
2
|
+
export declare function formatMessage(params: FrameworkMessage): FormattedMessage;
|
|
3
|
+
/**
|
|
4
|
+
* require external modules
|
|
5
|
+
* @param modules list of modules to load before the test starts
|
|
6
|
+
* @param loader function to import the module, optional and for testing purposes only
|
|
7
|
+
*/
|
|
8
|
+
export declare function requireExternalModules(modules: string[], loader?: typeof loadModule): Promise<any>[];
|
|
9
|
+
type Hook = Function | Function[];
|
|
10
|
+
export declare function setupEnv(cid: string, options: MochaOpts, beforeTest: Hook, beforeHook: Hook, afterTest: Hook, afterHook: Hook): Promise<any>[];
|
|
11
|
+
export declare function loadModule(name: string): Promise<any>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAc5E,wBAAgB,aAAa,CAAE,MAAM,EAAE,gBAAgB,oBA4EtD;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAE,OAAO,EAAE,MAAM,EAAE,EAAE,MAAM,oBAAa,kBAc7E;AAED,KAAK,IAAI,GAAG,QAAQ,GAAG,QAAQ,EAAE,CAAA;AACjC,wBAAgB,QAAQ,CAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,kBA6B9H;AAED,wBAAsB,UAAU,CAAE,IAAI,EAAE,MAAM,gBAQ7C"}
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { wrapGlobalTestMethod } from '@wdio/utils';
|
|
2
|
+
import { INTERFACES, TEST_INTERFACES, MOCHA_TIMEOUT_MESSAGE } from './constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* Extracts the mocha UI type following this convention:
|
|
5
|
+
* - If the mochaOpts.ui provided doesn't contain a '-' then the full name
|
|
6
|
+
* is taken as ui type (i.e. 'bdd','tdd','qunit')
|
|
7
|
+
* - If it contains a '-' then it asumes we are providing a custom ui for
|
|
8
|
+
* mocha. Then it extracts the text after the last '-' (ignoring .js if
|
|
9
|
+
* provided) as the interface type. (i.e. strong-bdd in
|
|
10
|
+
* https://github.com/strongloop/strong-mocha-interfaces)
|
|
11
|
+
*/
|
|
12
|
+
const MOCHA_UI_TYPE_EXTRACTOR = /^(?:.*-)?([^-.]+)(?:.js)?$/;
|
|
13
|
+
const DEFAULT_INTERFACE_TYPE = 'bdd';
|
|
2
14
|
export function formatMessage(params) {
|
|
3
15
|
let message = {
|
|
4
16
|
type: params.type
|
|
@@ -64,3 +76,48 @@ export function formatMessage(params) {
|
|
|
64
76
|
}
|
|
65
77
|
return message;
|
|
66
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* require external modules
|
|
81
|
+
* @param modules list of modules to load before the test starts
|
|
82
|
+
* @param loader function to import the module, optional and for testing purposes only
|
|
83
|
+
*/
|
|
84
|
+
export function requireExternalModules(modules, loader = loadModule) {
|
|
85
|
+
return modules.map((module) => {
|
|
86
|
+
if (!module) {
|
|
87
|
+
return Promise.resolve();
|
|
88
|
+
}
|
|
89
|
+
module = module.replace(/.*:/, '');
|
|
90
|
+
if (module.startsWith('./') && globalThis.process) {
|
|
91
|
+
module = `${globalThis.process.cwd()}/${module.slice(2)}`;
|
|
92
|
+
}
|
|
93
|
+
return loader(module);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
export function setupEnv(cid, options, beforeTest, beforeHook, afterTest, afterHook) {
|
|
97
|
+
const match = MOCHA_UI_TYPE_EXTRACTOR.exec(options.ui);
|
|
98
|
+
const type = (match && INTERFACES[match[1]] && match[1]) || DEFAULT_INTERFACE_TYPE;
|
|
99
|
+
const hookArgsFn = (context) => {
|
|
100
|
+
return [{ ...context.test, parent: context.test?.parent?.title }, context];
|
|
101
|
+
};
|
|
102
|
+
INTERFACES[type].forEach((fnName) => {
|
|
103
|
+
const isTest = TEST_INTERFACES[type].flatMap((testCommand) => [testCommand, testCommand + '.only']).includes(fnName);
|
|
104
|
+
wrapGlobalTestMethod(isTest, isTest ? beforeTest : beforeHook,
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
hookArgsFn, isTest ? afterTest : afterHook, hookArgsFn, fnName, cid);
|
|
107
|
+
});
|
|
108
|
+
let { require = [], compilers = [] } = options;
|
|
109
|
+
if (typeof require === 'string') {
|
|
110
|
+
require = [require];
|
|
111
|
+
}
|
|
112
|
+
return requireExternalModules([...compilers, ...require]);
|
|
113
|
+
}
|
|
114
|
+
export async function loadModule(name) {
|
|
115
|
+
try {
|
|
116
|
+
return await import(name);
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
throw new Error(`Module ${name} can't get loaded. Are you sure you have installed it?\n` +
|
|
120
|
+
'Note: if you\'ve installed WebdriverIO globally you need to install ' +
|
|
121
|
+
'these external modules globally too!');
|
|
122
|
+
}
|
|
123
|
+
}
|
package/build/index.d.ts
CHANGED
|
@@ -27,14 +27,11 @@ declare class MochaAdapter {
|
|
|
27
27
|
_loadFiles(mochaOpts: MochaOptsImport): Promise<void>;
|
|
28
28
|
hasTests(): boolean;
|
|
29
29
|
run(): Promise<unknown>;
|
|
30
|
-
options(options: MochaOptsImport): Promise<any>[];
|
|
31
|
-
preRequire(): Promise<any>[];
|
|
32
30
|
/**
|
|
33
31
|
* Hooks which are added as true Mocha hooks need to call done() to notify async
|
|
34
32
|
*/
|
|
35
33
|
wrapHook(hookName: keyof Services.HookFunctions): () => Promise<void | unknown[]>;
|
|
36
34
|
prepareMessage(hookName: keyof Services.HookFunctions): import("./types").FormattedMessage;
|
|
37
|
-
requireExternalModules(modules: string[]): Promise<any>[];
|
|
38
35
|
emit(event: string, payload: any, err?: MochaError): void;
|
|
39
36
|
getSyncEventIdStart(type: EventTypes): string;
|
|
40
37
|
getSyncEventIdEnd(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":";AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAIzD,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;AAK/C,KAAK,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,CAAO;IACtB,OAAO,CAAC,OAAO,CAAC,CAAQ;IACxB,OA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
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { INTERFACES, TEST_INTERFACES, EVENTS, NOOP } from './constants.js';
|
|
4
|
+
import { executeHooksWithArgs } from '@wdio/utils';
|
|
5
|
+
import { formatMessage, setupEnv } from './common.js';
|
|
6
|
+
import { EVENTS, NOOP } from './constants.js';
|
|
9
7
|
const log = logger('@wdio/mocha-framework');
|
|
10
|
-
/**
|
|
11
|
-
* Extracts the mocha UI type following this convention:
|
|
12
|
-
* - If the mochaOpts.ui provided doesn't contain a '-' then the full name
|
|
13
|
-
* is taken as ui type (i.e. 'bdd','tdd','qunit')
|
|
14
|
-
* - If it contains a '-' then it asumes we are providing a custom ui for
|
|
15
|
-
* mocha. Then it extracts the text after the last '-' (ignoring .js if
|
|
16
|
-
* provided) as the interface type. (i.e. strong-bdd in
|
|
17
|
-
* https://github.com/strongloop/strong-mocha-interfaces)
|
|
18
|
-
*/
|
|
19
|
-
const MOCHA_UI_TYPE_EXTRACTOR = /^(?:.*-)?([^-.]+)(?:.js)?$/;
|
|
20
|
-
const DEFAULT_INTERFACE_TYPE = 'bdd';
|
|
21
8
|
const FILE_PROTOCOL = 'file://';
|
|
22
9
|
/**
|
|
23
10
|
* Mocha runner
|
|
@@ -61,7 +48,8 @@ class MochaAdapter {
|
|
|
61
48
|
this._specs.forEach((spec) => mocha.addFile(spec.startsWith(FILE_PROTOCOL)
|
|
62
49
|
? url.fileURLToPath(spec)
|
|
63
50
|
: spec));
|
|
64
|
-
|
|
51
|
+
const { beforeTest, beforeHook, afterTest, afterHook } = this._config;
|
|
52
|
+
mocha.suite.on('pre-require', (context) => setupEnv(this._cid, context, beforeTest, beforeHook, afterTest, afterHook));
|
|
65
53
|
await this._loadFiles(mochaOpts);
|
|
66
54
|
return this;
|
|
67
55
|
}
|
|
@@ -115,28 +103,6 @@ class MochaAdapter {
|
|
|
115
103
|
}
|
|
116
104
|
return result;
|
|
117
105
|
}
|
|
118
|
-
options(options) {
|
|
119
|
-
let { require = [], compilers = [] } = options;
|
|
120
|
-
if (typeof require === 'string') {
|
|
121
|
-
require = [require];
|
|
122
|
-
}
|
|
123
|
-
return this.requireExternalModules([...compilers, ...require]);
|
|
124
|
-
}
|
|
125
|
-
preRequire() {
|
|
126
|
-
const options = this._config.mochaOpts;
|
|
127
|
-
const match = MOCHA_UI_TYPE_EXTRACTOR.exec(options.ui);
|
|
128
|
-
const type = (match && INTERFACES[match[1]] && match[1]) || DEFAULT_INTERFACE_TYPE;
|
|
129
|
-
const hookArgsFn = (context) => {
|
|
130
|
-
return [{ ...context.test, parent: context.test?.parent?.title }, context];
|
|
131
|
-
};
|
|
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,
|
|
135
|
-
// @ts-ignore
|
|
136
|
-
hookArgsFn, isTest ? this._config.afterTest : this._config.afterHook, hookArgsFn, fnName, this._cid);
|
|
137
|
-
});
|
|
138
|
-
return this.options(options);
|
|
139
|
-
}
|
|
140
106
|
/**
|
|
141
107
|
* Hooks which are added as true Mocha hooks need to call done() to notify async
|
|
142
108
|
*/
|
|
@@ -165,18 +131,6 @@ class MochaAdapter {
|
|
|
165
131
|
}
|
|
166
132
|
return formatMessage(params);
|
|
167
133
|
}
|
|
168
|
-
requireExternalModules(modules) {
|
|
169
|
-
return modules.map((module) => {
|
|
170
|
-
if (!module) {
|
|
171
|
-
return Promise.resolve();
|
|
172
|
-
}
|
|
173
|
-
module = module.replace(/.*:/, '');
|
|
174
|
-
if (module.substr(0, 1) === '.') {
|
|
175
|
-
module = path.join(process.cwd(), module);
|
|
176
|
-
}
|
|
177
|
-
return loadModule(module);
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
134
|
emit(event, payload, err) {
|
|
181
135
|
/**
|
|
182
136
|
* For some reason, Mocha fires a second 'suite:end' event for the root suite,
|
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.565+9959d0e91",
|
|
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",
|
|
@@ -23,16 +23,19 @@
|
|
|
23
23
|
},
|
|
24
24
|
"type": "module",
|
|
25
25
|
"exports": {
|
|
26
|
-
"./common":
|
|
26
|
+
"./common": {
|
|
27
|
+
"import": "./build/common.js",
|
|
28
|
+
"types": "./build/common.d.ts"
|
|
29
|
+
},
|
|
27
30
|
".": "./build/index.js"
|
|
28
31
|
},
|
|
29
32
|
"types": "./build/index.d.ts",
|
|
30
33
|
"typeScriptVersion": "3.8.3",
|
|
31
34
|
"dependencies": {
|
|
32
35
|
"@types/mocha": "^10.0.0",
|
|
33
|
-
"@wdio/logger": "8.0.0-alpha.
|
|
34
|
-
"@wdio/types": "8.0.0-alpha.
|
|
35
|
-
"@wdio/utils": "8.0.0-alpha.
|
|
36
|
+
"@wdio/logger": "8.0.0-alpha.565+9959d0e91",
|
|
37
|
+
"@wdio/types": "8.0.0-alpha.565+9959d0e91",
|
|
38
|
+
"@wdio/utils": "8.0.0-alpha.565+9959d0e91",
|
|
36
39
|
"mocha": "^10.0.0"
|
|
37
40
|
},
|
|
38
41
|
"devDependencies": {
|
|
@@ -41,5 +44,5 @@
|
|
|
41
44
|
"publishConfig": {
|
|
42
45
|
"access": "public"
|
|
43
46
|
},
|
|
44
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "9959d0e91c0f7d2991a5a0c1eb34d288894dae74"
|
|
45
48
|
}
|
package/build/common/utils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/build/utils.d.ts
DELETED
package/build/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export async function loadModule(name) {
|
|
2
|
-
try {
|
|
3
|
-
return await import(name);
|
|
4
|
-
}
|
|
5
|
-
catch (err) {
|
|
6
|
-
throw new Error(`Module ${name} can't get loaded. Are you sure you have installed it?\n` +
|
|
7
|
-
'Note: if you\'ve installed WebdriverIO globally you need to install ' +
|
|
8
|
-
'these external modules globally too!');
|
|
9
|
-
}
|
|
10
|
-
}
|