@wdio/browser-runner 8.5.1 → 8.5.3

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.
@@ -21,12 +21,12 @@ export async function mock(path, factory) {
21
21
  if (!factory) {
22
22
  return;
23
23
  }
24
- const mockLocalFile = path.startsWith('/') || path.startsWith('./');
24
+ const mockLocalFile = path.startsWith('/') || path.startsWith('./') || path.startsWith('../');
25
25
  const mockPath = mockLocalFile
26
26
  ? (new URL(resolveUrl(window.__wdioSpec__.split('/').slice(0, -1).join('/') + '/' + path))).pathname
27
27
  : path;
28
28
  try {
29
- const resolvedMock = await factory(() => (import(mockLocalFile ? `/@mock${mockPath}` : `/node_modules/.vite/deps/${mockPath}.js`)));
29
+ const resolvedMock = await factory(() => (import(mockLocalFile ? `/@mock${mockPath}` : `/node_modules/.vite/deps/${mockPath.replace('/', '_')}.js`)));
30
30
  socket.send(JSON.stringify({
31
31
  type: MESSAGE_TYPES.mockRequest,
32
32
  value: { path: mockPath, origin, namedExports: Object.keys(resolvedMock) }
@@ -1 +1 @@
1
- {"version":3,"file":"mockHoisting.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/mockHoisting.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAM7C,wBAAgB,YAAY,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,EAAE,CA2M/D"}
1
+ {"version":3,"file":"mockHoisting.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/mockHoisting.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAM7C,wBAAgB,YAAY,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,EAAE,CAmN/D"}
@@ -25,6 +25,7 @@ export function mockHoisting(mockHandler) {
25
25
  return '';
26
26
  }
27
27
  }
28
+ const mocks = [...mockHandler.mocks.values()];
28
29
  const preBundledDepName = path.basename(id).split('?')[0];
29
30
  const mockedMod = (
30
31
  // mocked file
@@ -32,7 +33,14 @@ export function mockHoisting(mockHandler) {
32
33
  // mocked dependency
33
34
  mockHandler.mocks.get(path.basename(id, path.extname(id))) ||
34
35
  // pre-bundled deps e.g. /node_modules/.vite/deps/algoliasearch_lite.js?v=e31c24e
35
- [...mockHandler.mocks.values()].find((mock) => `${mock.path.replace('/', '_')}.js` === preBundledDepName));
36
+ mocks.find((mock) => `${mock.path.replace('/', '_')}.js` === preBundledDepName) ||
37
+ // relative file imports ignoring file extension, e.g. `mock('../../constants.ts', () => { ... })`
38
+ mocks.find((mock) => {
39
+ const mockFileExtLength = path.extname(mock.path).length;
40
+ const toCompare = mockFileExtLength > 0 ? mock.path.slice(0, -mockFileExtLength) : mock.path;
41
+ // compare without file extension as we don't know if users use them or not
42
+ return toCompare === id.slice(0, -path.extname(id).length);
43
+ }));
36
44
  if (mockedMod) {
37
45
  const newCode = mockedMod.namedExports.map((ne) => {
38
46
  if (ne === 'default') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdio/browser-runner",
3
- "version": "8.5.1",
3
+ "version": "8.5.3",
4
4
  "description": "A WebdriverIO runner to run unit tests tests in the browser.",
5
5
  "author": "Christian Bromann <mail@bromann.dev>",
6
6
  "homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-browser-runner",
@@ -70,5 +70,5 @@
70
70
  "@types/ws": "^8.5.4",
71
71
  "@wdio/runner": "8.5.1"
72
72
  },
73
- "gitHead": "3a0fcc3875d01630da633c71560963aa5c425cef"
73
+ "gitHead": "445f1c901e9bd08b2d17d35592ad7c3258937917"
74
74
  }