Skip to content

Commit c825e64

Browse files
chore: Drop mocha (#887)
1 parent 5f1a539 commit c825e64

28 files changed

Lines changed: 211 additions & 201 deletions

.mocharc.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"rebuild": "npm run clean && npm run build",
1414
"format": "prettier -w ./lib ./test",
1515
"format:check": "prettier --check ./lib ./test",
16-
"test": "mocha --exit --timeout 1m \"./test/unit/**/*-specs.ts\"",
17-
"e2e-test": "mocha --exit --timeout 5m \"./test/functional/**/*-specs.ts\""
16+
"test": "node --test --test-force-exit --test-timeout=60000 \"./build/test/unit/**/*.spec.js\"",
17+
"e2e-test": "node --test --test-force-exit --test-concurrency=1 --test-timeout=300000 \"./build/test/functional/**/*.spec.js\""
1818
},
1919
"repository": {
2020
"type": "git",
@@ -64,18 +64,15 @@
6464
"@types/chai": "^5.2.3",
6565
"@types/chai-as-promised": "^8.0.2",
6666
"@types/ini": "^4.1.0",
67-
"@types/mocha": "^10.0.1",
6867
"@types/node": "^26.0.0",
6968
"@types/semver": "^7.5.0",
7069
"@types/sinon": "^22.0.0",
7170
"chai": "^6.0.0",
7271
"chai-as-promised": "^8.0.0",
7372
"conventional-changelog-conventionalcommits": "^9.3.1",
74-
"mocha": "^11.0.1",
7573
"prettier": "^3.0.0",
7674
"semantic-release": "^25.0.2",
7775
"sinon": "^22.0.0",
78-
"ts-node": "^10.9.1",
7976
"typescript": "^6.0.2"
8077
},
8178
"types": "./build/lib/index.d.ts"

test/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import path from 'node:path';
2+
import {node} from '@appium/support';
3+
14
/**
25
* ApiDemos test app constants
36
* These constants are used by both unit and functional test suites
47
*/
58
export const APIDEMOS_PKG = 'io.appium.android.apis';
69
export const APIDEMOS_ACTIVITY = 'io.appium.android.apis.ApiDemos';
710
export const APIDEMOS_ACTIVITY_SHORT = '.ApiDemos';
11+
12+
export const MODULE_ROOT = node.getModuleRootSync('appium-adb', __filename)!;
13+
export const FIXTURES_ROOT = path.join(MODULE_ROOT, 'test', 'fixtures');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {fs} from '@appium/support';
33
import path from 'node:path';
44
import chai, {expect} from 'chai';
55
import chaiAsPromised from 'chai-as-promised';
6+
import {describe, it} from 'node:test';
67

78
chai.use(chaiAsPromised);
89

test/functional/android-manifest-e2e-specs.ts renamed to test/functional/android-manifest-e2e.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {getAndroidPlatformAndPath} from '../../lib/tools/android-manifest';
66
import chai, {expect} from 'chai';
77
import chaiAsPromised from 'chai-as-promised';
88
import {readPackageManifest, requireSdkRoot} from '../../lib/utils';
9+
import {describe, it, before, type TestContext} from 'node:test';
910

1011
chai.use(chaiAsPromised);
1112

@@ -26,12 +27,12 @@ describe('Android-manifest', function () {
2627
it('hasInternetPermissionFromManifest should be true', async function () {
2728
expect(await adb.hasInternetPermissionFromManifest(apiDemosPath)).to.be.true;
2829
});
29-
it('hasInternetPermissionFromManifest should be false', async function () {
30+
it('hasInternetPermissionFromManifest should be false', async function (ctx: TestContext) {
3031
// Note: ApiDemos has internet permission, so we need a different test
3132
// For now, we'll skip this test or use a different APK
3233
// Since ApiDemos has internet permission, this test would fail
3334
// We'll comment it out or modify the test logic
34-
this.skip();
35+
ctx.skip();
3536
});
3637

3738
it('should compile and insert manifest', async function () {
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import path from 'node:path';
33
import {fs, tempDir} from '@appium/support';
44
import {unsignApk} from '../../lib/tools/apk-signing';
55
import {getApiDemosPath} from './setup';
6+
import {FIXTURES_ROOT} from '../constants';
67
import chai, {expect} from 'chai';
78
import chaiAsPromised from 'chai-as-promised';
9+
import {describe, it, before, beforeEach, afterEach} from 'node:test';
810

911
chai.use(chaiAsPromised);
1012

11-
const fixturesRoot = path.resolve(__dirname, '..', 'fixtures');
12-
const keystorePath = path.resolve(fixturesRoot, 'appiumtest.keystore');
13+
const keystorePath = path.resolve(FIXTURES_ROOT, 'appiumtest.keystore');
1314
const keyAlias = 'appiumtest';
1415

1516
describe('Apk-signing', function () {
Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@ import {retryInterval} from 'asyncbox';
33
import chai, {expect} from 'chai';
44
import chaiAsPromised from 'chai-as-promised';
55
import {
6-
MOCHA_TIMEOUT,
7-
MOCHA_LONG_TIMEOUT,
6+
E2E_TIMEOUT,
7+
E2E_LONG_TIMEOUT,
88
APIDEMOS_PKG,
99
APIDEMOS_ACTIVITY,
1010
APIDEMOS_ACTIVITY_SHORT,
1111
getApiDemosPath,
1212
} from './setup';
13+
import {describe, it, before, type TestContext} from 'node:test';
1314

1415
chai.use(chaiAsPromised);
1516

1617
const START_APP_WAIT_DURATION = 60000;
1718
const START_APP_WAIT_DURATION_FAIL = process.env.CI ? 20000 : 10000;
1819

19-
describe('apk utils', function () {
20-
this.timeout(MOCHA_TIMEOUT);
21-
20+
describe('apk utils', {timeout: E2E_TIMEOUT}, function () {
2221
let adb: any;
2322
let apiDemosPath: string;
2423
const deviceTempPath = '/data/local/tmp/';
@@ -56,10 +55,10 @@ describe('apk utils', function () {
5655
await adb.grantAllPermissions(APIDEMOS_PKG);
5756
});
5857
describe('startUri', function () {
59-
it('should be able to start a uri', async function () {
58+
it('should be able to start a uri', async function (ctx: TestContext) {
6059
const apiLevel = await adb.getApiLevel();
6160
if (apiLevel < 23 || apiLevel > 28) {
62-
return this.skip();
61+
return ctx.skip();
6362
}
6463
await adb.goToHome();
6564
let res = await adb.getFocusedPackageAndActivity();
@@ -96,45 +95,51 @@ describe('apk utils', function () {
9695
await assertPackageAndActivity();
9796
});
9897
});
99-
it('should be able to start with an intent and no activity', async function () {
100-
if ((await adb.getApiLevel()) < 28 && process.env.CI) {
101-
return this.skip();
102-
}
98+
it(
99+
'should be able to start with an intent and no activity',
100+
{timeout: E2E_LONG_TIMEOUT},
101+
async function (ctx: TestContext) {
102+
if ((await adb.getApiLevel()) < 28 && process.env.CI) {
103+
return ctx.skip();
104+
}
103105

104-
this.timeout(MOCHA_LONG_TIMEOUT);
105-
await adb.install(apiDemosPath, {
106-
grantPermissions: true,
107-
});
108-
await adb.startApp({
109-
action: 'android.intent.action.WEB_SEARCH',
110-
pkg: 'com.google.android.googlequicksearchbox',
111-
optionalIntentArguments: '-e query foo',
112-
waitDuration: START_APP_WAIT_DURATION,
113-
stopApp: false,
114-
});
115-
const {appPackage} = await adb.getFocusedPackageAndActivity();
116-
const expectedPkgPossibilities = [
117-
'com.android.browser',
118-
'org.chromium.webview_shell',
119-
'com.google.android.googlequicksearchbox',
120-
];
121-
expect(expectedPkgPossibilities).to.include(appPackage);
122-
});
123-
it('should throw an error for unknown activity for intent', async function () {
124-
this.timeout(MOCHA_LONG_TIMEOUT);
125-
await adb.install(apiDemosPath, {
126-
grantPermissions: true,
127-
});
128-
await expect(
129-
adb.startApp({
130-
action: 'android.intent.action.DEFAULT',
131-
pkg: 'com.google.android.telephony',
132-
optionalIntentArguments: '-d tel:555-5555',
106+
await adb.install(apiDemosPath, {
107+
grantPermissions: true,
108+
});
109+
await adb.startApp({
110+
action: 'android.intent.action.WEB_SEARCH',
111+
pkg: 'com.google.android.googlequicksearchbox',
112+
optionalIntentArguments: '-e query foo',
133113
waitDuration: START_APP_WAIT_DURATION,
134114
stopApp: false,
135-
}),
136-
).to.eventually.be.rejectedWith(/Cannot start the .* application/);
137-
});
115+
});
116+
const {appPackage} = await adb.getFocusedPackageAndActivity();
117+
const expectedPkgPossibilities = [
118+
'com.android.browser',
119+
'org.chromium.webview_shell',
120+
'com.google.android.googlequicksearchbox',
121+
];
122+
expect(expectedPkgPossibilities).to.include(appPackage);
123+
},
124+
);
125+
it(
126+
'should throw an error for unknown activity for intent',
127+
{timeout: E2E_LONG_TIMEOUT},
128+
async function () {
129+
await adb.install(apiDemosPath, {
130+
grantPermissions: true,
131+
});
132+
await expect(
133+
adb.startApp({
134+
action: 'android.intent.action.DEFAULT',
135+
pkg: 'com.google.android.telephony',
136+
optionalIntentArguments: '-d tel:555-5555',
137+
waitDuration: START_APP_WAIT_DURATION,
138+
stopApp: false,
139+
}),
140+
).to.eventually.be.rejectedWith(/Cannot start the .* application/);
141+
},
142+
);
138143
it('should throw error for wrong activity', async function () {
139144
await adb.install(apiDemosPath, {
140145
grantPermissions: true,
@@ -297,10 +302,6 @@ describe('apk utils', function () {
297302
});
298303
describe('activateApp', function () {
299304
it('should be able to activate with normal package and activity', async function () {
300-
if ((await adb.getApiLevel()) < 23) {
301-
return this.skip();
302-
}
303-
304305
await adb.install(apiDemosPath, {
305306
grantPermissions: true,
306307
});
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import {ADB} from '../../lib/adb';
2-
import {MOCHA_TIMEOUT, APIDEMOS_PKG, APIDEMOS_ACTIVITY, getApiDemosPath} from './setup';
2+
import {E2E_TIMEOUT, APIDEMOS_PKG, APIDEMOS_ACTIVITY, getApiDemosPath} from './setup';
33
import {waitForCondition} from 'asyncbox';
44
import chai, {expect} from 'chai';
55
import chaiAsPromised from 'chai-as-promised';
6+
import {describe, it, before, type TestContext} from 'node:test';
67

78
chai.use(chaiAsPromised);
89

9-
describe('app commands', function () {
10-
this.timeout(MOCHA_TIMEOUT);
11-
10+
describe('app commands', {timeout: E2E_TIMEOUT}, function () {
1211
let adb: ADB;
1312
let apiDemosPath: string;
1413
const androidInstallTimeout = 90000;
@@ -88,9 +87,9 @@ describe('app commands', function () {
8887
expect(packageInfo.isInstalled).to.be.true;
8988
});
9089

91-
it('should get focused package and activity', async function () {
90+
it('should get focused package and activity', async function (ctx: TestContext) {
9291
if ((await adb.getApiLevel()) > 30) {
93-
return this.skip();
92+
return ctx.skip();
9493
}
9594
await adb.install(apiDemosPath, {
9695
timeout: androidInstallTimeout,
@@ -109,9 +108,9 @@ describe('app commands', function () {
109108
});
110109

111110
describe('activity waiting', function () {
112-
it('should wait for activity', async function () {
111+
it('should wait for activity', async function (ctx: TestContext) {
113112
if ((await adb.getApiLevel()) > 30) {
114-
return this.skip();
113+
return ctx.skip();
115114
}
116115
await adb.install(apiDemosPath, {
117116
timeout: androidInstallTimeout,

test/functional/emulator-commands-e2e-specs.ts renamed to test/functional/emulator-commands-e2e.spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import {ADB} from '../../lib/adb';
22
import chai, {expect} from 'chai';
33
import chaiAsPromised from 'chai-as-promised';
4+
import {describe, it, before, type TestContext} from 'node:test';
45

56
chai.use(chaiAsPromised);
67

78
describe('emulator commands', function () {
89
let adb: ADB;
910

1011
before(async function () {
11-
if (process.env.REAL_DEVICE) {
12-
return this.skip();
13-
}
14-
1512
adb = await ADB.createADB();
1613
const devices = await adb.getConnectedEmulators();
1714
adb.setDevice(devices[0]);
@@ -38,9 +35,9 @@ describe('emulator commands', function () {
3835
});
3936

4037
describe('getEmuImageProperties', function () {
41-
it('should get emulator image properties', async function () {
38+
it('should get emulator image properties', async function (ctx: TestContext) {
4239
if (process.env.CI) {
43-
return this.skip();
40+
return ctx.skip();
4441
}
4542

4643
const name = await adb.execEmuConsoleCommand(['avd', 'name']);

test/functional/general-commands-e2e-specs.ts renamed to test/functional/general-commands-e2e.spec.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ import path from 'node:path';
33
import {randomUUID} from 'node:crypto';
44
import chai, {expect} from 'chai';
55
import chaiAsPromised from 'chai-as-promised';
6-
import {MOCHA_TIMEOUT, APIDEMOS_PKG, getApiDemosPath} from './setup';
6+
import {E2E_TIMEOUT, APIDEMOS_PKG, getApiDemosPath} from './setup';
77
import {fs, tempDir} from '@appium/support';
88
import {waitForCondition} from 'asyncbox';
9+
import {describe, it, before, after, afterEach, beforeEach, type TestContext} from 'node:test';
910

1011
chai.use(chaiAsPromised);
1112

12-
describe('general commands', function () {
13-
this.timeout(MOCHA_TIMEOUT);
14-
13+
describe('general commands', {timeout: E2E_TIMEOUT}, function () {
1514
let adb: ADB;
1615
let apiDemosPath: string;
1716
const androidInstallTimeout = 90000;
@@ -38,10 +37,10 @@ describe('general commands', function () {
3837
expect(defaultIME).to.be.a('string');
3938
expect(defaultIME?.length ?? 0).to.be.above(0);
4039
});
41-
it('enableIME and disableIME should enable and disable IME', async function () {
40+
it('enableIME and disableIME should enable and disable IME', async function (ctx: TestContext) {
4241
const imes = await adb.availableIMEs();
4342
if (imes.length < 2) {
44-
return this.skip();
43+
return ctx.skip();
4544
}
4645

4746
// Get the default IME to avoid trying to disable it (which may not be allowed)
@@ -51,7 +50,7 @@ describe('general commands', function () {
5150

5251
// Skip if we can't find a non-default IME or if the only IME is the default
5352
if (!ime || ime === defaultIme) {
54-
this.skip();
53+
ctx.skip();
5554
return;
5655
}
5756

@@ -248,15 +247,19 @@ describe('general commands', function () {
248247
});
249248

250249
describe('bugreport', function () {
251-
it('should return the report as a raw string', async function () {
252-
if (process.env.CI) {
253-
// skip the test on CI, since it takes a lot of time
254-
return this.skip;
255-
}
256-
const BUG_REPORT_TIMEOUT = 2 * 60 * 1000; // 2 minutes
257-
this.timeout(BUG_REPORT_TIMEOUT);
258-
expect(await adb.bugreport()).to.be.a('string');
259-
});
250+
const BUG_REPORT_TIMEOUT = 2 * 60 * 1000; // 2 minutes
251+
252+
it(
253+
'should return the report as a raw string',
254+
{timeout: BUG_REPORT_TIMEOUT},
255+
async function (ctx: TestContext) {
256+
if (process.env.CI) {
257+
// skip the test on CI, since it takes a lot of time
258+
return ctx.skip();
259+
}
260+
expect(await adb.bugreport()).to.be.a('string');
261+
},
262+
);
260263
});
261264

262265
describe('features', function () {

0 commit comments

Comments
 (0)