Skip to content

Commit c8e4bcd

Browse files
refactor: Use top-level static imports for real module exports in mocks
Matches the existing teen_process pattern instead of mixing in inline await import() calls right before the corresponding mock.module call. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 57ea0bf commit c8e4bcd

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

test/unit/apk-signing.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import * as appiumSupport from '@appium/support';
66
import {zip} from '@appium/support';
77
import type {ZipEntry} from '@appium/support';
88
import sinon from 'sinon';
9+
import * as teenProcess from 'teen_process';
910

11+
import * as utilsIndex from '../../lib/utils/index.js';
1012
import {FIXTURES_ROOT, MODULE_ROOT} from '../constants.js';
1113

1214
const keystorePath = path.resolve(FIXTURES_ROOT, 'appiumtest.keystore');
@@ -26,17 +28,15 @@ let currentGetResourcePath: (...args: any[]) => any = async () => '';
2628
let currentGetJavaForOs: (...args: any[]) => any = async () => javaDummyPath;
2729
let currentGetJavaHome: (...args: any[]) => any = async () => javaHome;
2830

29-
const realTeenProcess = await import('teen_process');
3031
mock.module('teen_process', {
3132
namedExports: {
32-
...realTeenProcess,
33+
...teenProcess,
3334
exec: (...args: any[]) => currentExec(...args),
3435
},
3536
});
36-
const realUtils = await import('../../lib/utils/index.js');
3737
mock.module('../../lib/utils/index.js', {
3838
namedExports: {
39-
...realUtils,
39+
...utilsIndex,
4040
getResourcePath: (...args: any[]) => currentGetResourcePath(...args),
4141
getJavaForOs: (...args: any[]) => currentGetJavaForOs(...args),
4242
getJavaHome: (...args: any[]) => currentGetJavaHome(...args),

test/unit/system-calls.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import assert from 'node:assert/strict';
22
import {describe, it, beforeEach, afterEach, mock} from 'node:test';
33

4+
import * as asyncbox from 'asyncbox';
45
import sinon from 'sinon';
56
import * as teen_process from 'teen_process';
67

@@ -14,10 +15,9 @@ mock.module('teen_process', {
1415
exec: (...args: any[]) => currentExec(...args),
1516
},
1617
});
17-
const realAsyncbox = await import('asyncbox');
1818
mock.module('asyncbox', {
1919
namedExports: {
20-
...realAsyncbox,
20+
...asyncbox,
2121
sleep: (...args: any[]) => currentSleep(...args),
2222
retryInterval: (...args: any[]) => currentRetryInterval(...args),
2323
},

0 commit comments

Comments
 (0)