@wdio/browser-runner 9.0.0-alpha.78 → 9.0.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/browser/driver.js +249 -234
- package/build/browser/expect.js +107 -148
- package/build/browser/frameworks/mocha.d.ts.map +1 -1
- package/build/browser/integrations/stencil.js +370 -407
- package/build/browser/mock.d.ts +3 -2
- package/build/browser/mock.d.ts.map +1 -1
- package/build/browser/mock.js +78 -34
- package/build/browser/setup.js +313 -37
- package/build/browser/spy.d.ts.map +1 -1
- package/build/browser/spy.js +29 -40
- package/build/browser/utils.d.ts +7 -0
- package/build/browser/utils.d.ts.map +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1465 -171
- package/build/types.d.ts +19 -2
- package/build/types.d.ts.map +1 -1
- package/build/utils.d.ts +3 -3
- package/build/utils.d.ts.map +1 -1
- package/build/vite/constants.d.ts +3 -0
- package/build/vite/constants.d.ts.map +1 -1
- package/build/vite/plugins/esbuild.d.ts.map +1 -1
- package/build/vite/plugins/testrunner.d.ts.map +1 -1
- package/build/vite/server.d.ts +0 -1
- package/build/vite/server.d.ts.map +1 -1
- package/build/vite/utils.d.ts.map +1 -1
- package/package.json +57 -26
- package/build/browser/commands/debug.js +0 -6
- package/build/browser/frameworks/mocha.js +0 -320
- package/build/browser/utils.js +0 -61
- package/build/communicator.js +0 -82
- package/build/constants.js +0 -89
- package/build/types.js +0 -1
- package/build/utils.js +0 -86
- package/build/vite/constants.js +0 -55
- package/build/vite/frameworks/index.js +0 -19
- package/build/vite/frameworks/nuxt.js +0 -61
- package/build/vite/frameworks/stencil.js +0 -165
- package/build/vite/frameworks/tailwindcss.js +0 -28
- package/build/vite/mock.js +0 -50
- package/build/vite/plugins/esbuild.js +0 -25
- package/build/vite/plugins/mockHoisting.js +0 -312
- package/build/vite/plugins/testrunner.js +0 -152
- package/build/vite/plugins/worker.js +0 -12
- package/build/vite/server.js +0 -104
- package/build/vite/types.js +0 -1
- package/build/vite/utils.js +0 -223
- /package/{LICENSE-MIT → LICENSE} +0 -0
package/build/vite/utils.js
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
/* eslint-disable quotes */
|
|
2
|
-
import fs from 'node:fs/promises';
|
|
3
|
-
import url from 'node:url';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import logger from '@wdio/logger';
|
|
6
|
-
import { resolve } from 'import-meta-resolve';
|
|
7
|
-
import { WDIO_EVENT_NAME } from '../constants.js';
|
|
8
|
-
import { MOCHA_VARIABELS } from '../constants.js';
|
|
9
|
-
const log = logger('@wdio/browser-runner');
|
|
10
|
-
export async function getTemplate(options, env, spec, p = process) {
|
|
11
|
-
const root = options.rootDir || process.cwd();
|
|
12
|
-
const rootFileUrl = url.pathToFileURL(root).href;
|
|
13
|
-
const isHeadless = options.headless || Boolean(process.env.CI);
|
|
14
|
-
const alias = options.viteConfig?.resolve?.alias || {};
|
|
15
|
-
const usesTailwindCSS = await hasFileByExtensions(path.join(root, 'tailwind.config'));
|
|
16
|
-
/**
|
|
17
|
-
* clean up some values that might cause serialization issues
|
|
18
|
-
*/
|
|
19
|
-
if ('runner' in env.config) {
|
|
20
|
-
delete env.config.runner;
|
|
21
|
-
}
|
|
22
|
-
let vueDeps = '';
|
|
23
|
-
if (options.preset === 'vue') {
|
|
24
|
-
try {
|
|
25
|
-
const vueDir = path.dirname(url.fileURLToPath(await resolve('vue', `${rootFileUrl}/node_modules`)));
|
|
26
|
-
const vueScript = (await fs.readFile(path.join(vueDir, 'dist', 'vue.global.prod.js'), 'utf-8')).toString();
|
|
27
|
-
vueDeps += /*html*/ `
|
|
28
|
-
<script type="module">
|
|
29
|
-
${vueScript}
|
|
30
|
-
window.Vue = Vue
|
|
31
|
-
</script>`;
|
|
32
|
-
const vueCompilerDir = path.dirname(url.fileURLToPath(await resolve('@vue/compiler-dom', `${rootFileUrl}/node_modules`)));
|
|
33
|
-
const vueCompilerScript = (await fs.readFile(path.join(vueCompilerDir, 'dist', 'compiler-dom.global.prod.js'))).toString();
|
|
34
|
-
vueDeps += /*html*/ `
|
|
35
|
-
<script type="module">
|
|
36
|
-
${vueCompilerScript}
|
|
37
|
-
window.VueCompilerDOM = VueCompilerDOM
|
|
38
|
-
</script>`;
|
|
39
|
-
}
|
|
40
|
-
catch (err) {
|
|
41
|
-
throw new Error(`Fail to set-up Vue environment: ${err.message}\n\n` +
|
|
42
|
-
'Make sure you have "vue" and "@vue/compiler-dom" installed as dependencies!\n' +
|
|
43
|
-
`Error: ${err.stack}`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
let sourceMapScript = '';
|
|
47
|
-
let sourceMapSetupCommand = '';
|
|
48
|
-
try {
|
|
49
|
-
const sourceMapSupportDir = await resolve('source-map-support', import.meta.url);
|
|
50
|
-
sourceMapScript = /*html*/ `<script src="/@fs/${url.fileURLToPath(path.dirname(sourceMapSupportDir))}/browser-source-map-support.js"></script>`;
|
|
51
|
-
sourceMapSetupCommand = 'sourceMapSupport.install()';
|
|
52
|
-
}
|
|
53
|
-
catch (err) {
|
|
54
|
-
log.error(`Failed to setup source-map-support: ${err.message}`);
|
|
55
|
-
}
|
|
56
|
-
const mochaPath = await resolve('mocha', `${rootFileUrl}/node_modules`);
|
|
57
|
-
const mochaCSSHref = path.join(url.fileURLToPath(path.dirname(mochaPath)), 'mocha.css');
|
|
58
|
-
const mochaJSSrc = path.join(url.fileURLToPath(path.dirname(mochaPath)), 'mocha.js');
|
|
59
|
-
return /* html */ `
|
|
60
|
-
<!doctype html>
|
|
61
|
-
<html>
|
|
62
|
-
<head>
|
|
63
|
-
<title>WebdriverIO Browser Test</title>
|
|
64
|
-
<link rel="icon" type="image/x-icon" href="https://webdriver.io/img/favicon.png">
|
|
65
|
-
${usesTailwindCSS ? /*html*/ `<link rel="stylesheet" href="/node_modules/tailwindcss/tailwind.css">` : ''}
|
|
66
|
-
<script type="module">
|
|
67
|
-
const alias = ${JSON.stringify(alias)}
|
|
68
|
-
window.__wdioMockCache__ = new Map()
|
|
69
|
-
window.WDIO_EVENT_NAME = '${WDIO_EVENT_NAME}'
|
|
70
|
-
window.wdioImport = function (modName, mod) {
|
|
71
|
-
/**
|
|
72
|
-
* attempt to resolve direct import
|
|
73
|
-
*/
|
|
74
|
-
if (window.__wdioMockCache__.get(modName)) {
|
|
75
|
-
return window.__wdioMockCache__.get(modName)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* if above fails, check if we have an alias for it
|
|
80
|
-
*/
|
|
81
|
-
for (const [aliasName, aliasPath] of Object.entries(alias)) {
|
|
82
|
-
if (modName.slice(0, aliasName.length) === aliasName) {
|
|
83
|
-
modName = modName.replace(aliasName, aliasPath)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (window.__wdioMockCache__.get(modName)) {
|
|
87
|
-
return window.__wdioMockCache__.get(modName)
|
|
88
|
-
}
|
|
89
|
-
return mod
|
|
90
|
-
}
|
|
91
|
-
</script>
|
|
92
|
-
<link rel="stylesheet" href="/@fs/${mochaCSSHref}">
|
|
93
|
-
<script type="module" src="/@fs/${mochaJSSrc}"></script>
|
|
94
|
-
${sourceMapScript}
|
|
95
|
-
<script type="module">
|
|
96
|
-
${sourceMapSetupCommand}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Inject environment variables
|
|
100
|
-
*/
|
|
101
|
-
window.__wdioEnv__ = ${JSON.stringify(env)}
|
|
102
|
-
window.__wdioSpec__ = '${spec}'
|
|
103
|
-
window.__wdioEvents__ = []
|
|
104
|
-
/**
|
|
105
|
-
* listen to window errors during bootstrap phase
|
|
106
|
-
*/
|
|
107
|
-
window.__wdioErrors__ = []
|
|
108
|
-
addEventListener('error', (ev) => window.__wdioErrors__.push({
|
|
109
|
-
filename: ev.filename,
|
|
110
|
-
message: ev.message,
|
|
111
|
-
error: ev.error.stack
|
|
112
|
-
}))
|
|
113
|
-
/**
|
|
114
|
-
* mock process
|
|
115
|
-
*/
|
|
116
|
-
window.process = window.process || {
|
|
117
|
-
platform: 'browser',
|
|
118
|
-
env: ${JSON.stringify(p.env)},
|
|
119
|
-
stdout: {},
|
|
120
|
-
stderr: {},
|
|
121
|
-
cwd: () => ${JSON.stringify(p.cwd())},
|
|
122
|
-
}
|
|
123
|
-
</script>
|
|
124
|
-
<script type="module" src="@wdio/browser-runner/setup"></script>
|
|
125
|
-
<style>
|
|
126
|
-
${MOCHA_VARIABELS}
|
|
127
|
-
|
|
128
|
-
body {
|
|
129
|
-
width: calc(100% - 500px);
|
|
130
|
-
padding: 0;
|
|
131
|
-
margin: 0;
|
|
132
|
-
}
|
|
133
|
-
</style>
|
|
134
|
-
${vueDeps}
|
|
135
|
-
</head>
|
|
136
|
-
<body>
|
|
137
|
-
<mocha-framework spec="${spec}" ${isHeadless ? 'style="display: none"' : ''}></mocha-framework>
|
|
138
|
-
</body>
|
|
139
|
-
</html>`;
|
|
140
|
-
}
|
|
141
|
-
export async function userfriendlyImport(preset, pkg) {
|
|
142
|
-
if (!pkg) {
|
|
143
|
-
return {};
|
|
144
|
-
}
|
|
145
|
-
try {
|
|
146
|
-
return await import(pkg);
|
|
147
|
-
}
|
|
148
|
-
catch (err) {
|
|
149
|
-
throw new Error(`Couldn't load preset "${preset}" given important dependency ("${pkg}") is not installed.\n` +
|
|
150
|
-
`Please run:\n\n\tnpm install ${pkg}\n\tor\n\tyarn add --dev ${pkg}`);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
export function normalizeId(id, base) {
|
|
154
|
-
if (base && id.startsWith(base)) {
|
|
155
|
-
id = `/${id.slice(base.length)}`;
|
|
156
|
-
}
|
|
157
|
-
return id
|
|
158
|
-
.replace(/^\/@id\/__x00__/, '\0') // virtual modules start with `\0`
|
|
159
|
-
.replace(/^\/@id\//, '')
|
|
160
|
-
.replace(/^__vite-browser-external:/, '')
|
|
161
|
-
.replace(/^node:/, '')
|
|
162
|
-
.replace(/[?&]v=\w+/, '?') // remove ?v= query
|
|
163
|
-
.replace(/\?$/, ''); // remove end query mark
|
|
164
|
-
}
|
|
165
|
-
export async function getFilesFromDirectory(dir) {
|
|
166
|
-
/**
|
|
167
|
-
* check if dir exists
|
|
168
|
-
*/
|
|
169
|
-
const isExisting = await fs.access(dir).then(() => true, () => false);
|
|
170
|
-
if (!isExisting) {
|
|
171
|
-
return [];
|
|
172
|
-
}
|
|
173
|
-
let files = await fs.readdir(dir);
|
|
174
|
-
files = (await Promise.all(files.map(async (file) => {
|
|
175
|
-
const filePath = path.join(dir, file);
|
|
176
|
-
const stats = await fs.stat(filePath);
|
|
177
|
-
if (stats.isDirectory()) {
|
|
178
|
-
return getFilesFromDirectory(filePath);
|
|
179
|
-
}
|
|
180
|
-
else if (stats.isFile()) {
|
|
181
|
-
return filePath;
|
|
182
|
-
}
|
|
183
|
-
}))).filter(Boolean);
|
|
184
|
-
return files.reduce((all, folderContents) => all.concat(folderContents), []);
|
|
185
|
-
}
|
|
186
|
-
let mockedModulesList;
|
|
187
|
-
export async function getManualMocks(automockDir) {
|
|
188
|
-
/**
|
|
189
|
-
* read available mocks only one time
|
|
190
|
-
*/
|
|
191
|
-
if (!mockedModulesList) {
|
|
192
|
-
mockedModulesList = (await getFilesFromDirectory(automockDir))
|
|
193
|
-
/**
|
|
194
|
-
* seperate to module name and actual path
|
|
195
|
-
*/
|
|
196
|
-
.map((filePath) => [
|
|
197
|
-
filePath,
|
|
198
|
-
filePath.slice(automockDir.length + 1).slice(0, -path.extname(filePath).length)
|
|
199
|
-
]);
|
|
200
|
-
}
|
|
201
|
-
return mockedModulesList;
|
|
202
|
-
}
|
|
203
|
-
const EXTENSION = ['.js', '.ts', '.mjs', '.cjs', '.mts'];
|
|
204
|
-
export async function hasFileByExtensions(p, extensions = EXTENSION) {
|
|
205
|
-
return (await Promise.all([
|
|
206
|
-
fs.access(p).then(() => p, () => undefined),
|
|
207
|
-
...extensions.map((ext) => fs.access(p + ext).then(() => p + ext, () => undefined))
|
|
208
|
-
])).filter(Boolean)[0];
|
|
209
|
-
}
|
|
210
|
-
export function hasDir(p) {
|
|
211
|
-
return fs.stat(p).then((s) => s.isDirectory(), () => false);
|
|
212
|
-
}
|
|
213
|
-
export function getErrorTemplate(filename, error) {
|
|
214
|
-
return /*html*/ `
|
|
215
|
-
<pre>${error.stack}</pre>
|
|
216
|
-
<script type="module">
|
|
217
|
-
window.__wdioErrors__ = [{
|
|
218
|
-
filename: "${filename}",
|
|
219
|
-
message: \`${error.message}\`
|
|
220
|
-
}]
|
|
221
|
-
</script>
|
|
222
|
-
`;
|
|
223
|
-
}
|
/package/{LICENSE-MIT → LICENSE}
RENAMED
|
File without changes
|