diff --git a/package.json b/package.json index 389455aa2..602ebe556 100644 --- a/package.json +++ b/package.json @@ -143,19 +143,14 @@ "@semantic-release/changelog": "^6.0.3", "@semantic-release/git": "^10.0.1", "@types/bluebird": "^3.5.38", - "@types/chai": "^4.3.5", - "@types/chai-as-promised": "^7.1.5", "@types/lodash": "^4.14.196", "@types/mocha": "^10.0.1", "@types/node": "^20.4.7", "@types/portscanner": "^2.1.1", - "@types/sinon": "^17.0.0", - "@types/sinon-chai": "^3.2.9", "@types/teen_process": "^2.0.1", "axios": "^1.4.0", - "chai": "^4.3.7", - "chai-as-promised": "^7.1.1", - "chai-subset": "^1.6.0", + "chai": "^5.1.1", + "chai-as-promised": "^8.0.0", "conventional-changelog-conventionalcommits": "^8.0.0", "mocha": "^10.2.0", "mocha-junit-reporter": "^2.2.1", @@ -166,7 +161,6 @@ "semantic-release": "^24.0.0", "sharp": "^0.x", "sinon": "^18.0.0", - "sinon-chai": "^3.7.0", "ts-node": "^10.9.1", "type-fest": "^4.1.0", "typescript": "^5.4.2", diff --git a/test/functional/basic/alert-e2e-specs.js b/test/functional/basic/alert-e2e-specs.js index d7aa8d5d7..a1b25f99a 100644 --- a/test/functional/basic/alert-e2e-specs.js +++ b/test/functional/basic/alert-e2e-specs.js @@ -1,18 +1,22 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import B from 'bluebird'; import {retryInterval} from 'asyncbox'; import {amendCapabilities, UICATALOG_CAPS} from '../desired'; import {initSession, deleteSession, hasDefaultPrebuiltWDA, MOCHA_TIMEOUT} from '../helpers/session'; -chai.should(); -chai.use(chaiAsPromised); describe('XCUITestDriver - alerts -', function () { this.timeout(MOCHA_TIMEOUT); let driver; + let chai; + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + const caps = amendCapabilities(UICATALOG_CAPS, { 'appium:usePrebuiltWDA': hasDefaultPrebuiltWDA(), }); diff --git a/test/functional/basic/basic-e2e-specs.js b/test/functional/basic/basic-e2e-specs.js index cf6911604..8570dedef 100644 --- a/test/functional/basic/basic-e2e-specs.js +++ b/test/functional/basic/basic-e2e-specs.js @@ -1,6 +1,3 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; -import chaiSubset from 'chai-subset'; import B from 'bluebird'; import util from 'util'; import {retryInterval} from 'asyncbox'; @@ -9,15 +6,20 @@ import {initSession, deleteSession, hasDefaultPrebuiltWDA, MOCHA_TIMEOUT} from ' import {GUINEA_PIG_PAGE} from '../web/helpers'; import sharp from 'sharp'; -chai.should(); -chai.use(chaiAsPromised); -chai.use(chaiSubset); describe('XCUITestDriver - basics -', function () { this.timeout(MOCHA_TIMEOUT); let driver; + let chai; + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + const caps = amendCapabilities(UICATALOG_CAPS, { 'appium:usePrebuiltWDA': hasDefaultPrebuiltWDA(), }); @@ -144,7 +146,9 @@ describe('XCUITestDriver - basics -', function () { it('should get the list of available logs', async function () { const expectedTypes = ['syslog', 'crashlog', 'performance', 'server', 'safariConsole']; const actualTypes = await driver.getLogTypes(); - actualTypes.should.containSubset(expectedTypes); + for (const actualType of actualTypes) { + expectedTypes.includes(actualType).should.be.true; + } }); }); diff --git a/test/functional/basic/element-e2e-specs.js b/test/functional/basic/element-e2e-specs.js index 894dfef88..fe1b3c852 100644 --- a/test/functional/basic/element-e2e-specs.js +++ b/test/functional/basic/element-e2e-specs.js @@ -1,5 +1,3 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import _ from 'lodash'; import B from 'bluebird'; import {retryInterval} from 'asyncbox'; @@ -7,14 +5,20 @@ import {extractCapabilityValue, amendCapabilities, UICATALOG_CAPS} from '../desi import {initSession, deleteSession, hasDefaultPrebuiltWDA, MOCHA_TIMEOUT} from '../helpers/session'; import {util} from 'appium/support'; -chai.should(); -chai.use(chaiAsPromised); describe('XCUITestDriver - elements -', function () { this.timeout(MOCHA_TIMEOUT); let driver; + let chai; + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + const caps = amendCapabilities(UICATALOG_CAPS, { 'appium:usePrebuiltWDA': hasDefaultPrebuiltWDA(), }); diff --git a/test/functional/basic/face-id-e2e-specs.js b/test/functional/basic/face-id-e2e-specs.js index eb563f0b1..85d60690d 100644 --- a/test/functional/basic/face-id-e2e-specs.js +++ b/test/functional/basic/face-id-e2e-specs.js @@ -1,5 +1,3 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import {amendCapabilities, FACEIDAPP_CAPS} from '../desired'; import {initSession, deleteSession, hasDefaultPrebuiltWDA, MOCHA_TIMEOUT} from '../helpers/session'; import B from 'bluebird'; @@ -7,9 +5,6 @@ import {killAllSimulators} from '../helpers/simulator'; import {CLASS_CHAIN_SEARCH} from '../helpers/element'; import {waitForCondition} from 'asyncbox'; -chai.should(); -chai.use(chaiAsPromised); -const expect = chai.expect; const DEFAULT_IMPLICIT_TIMEOUT_MS = 1000; const FACE_ID_SELECTOR = '**/XCUIElementTypeStaticText[`label == "Face ID"`]'; @@ -26,6 +21,17 @@ if (!process.env.CI) { this.timeout(MOCHA_TIMEOUT * 2); this.retries(MOCHA_RETRIES); let driver; + let chai; + let expect; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + expect = chai.expect; + }); beforeEach(async function () { await killAllSimulators(); diff --git a/test/functional/basic/find-e2e-specs.js b/test/functional/basic/find-e2e-specs.js index 644318dea..3b0e19d76 100644 --- a/test/functional/basic/find-e2e-specs.js +++ b/test/functional/basic/find-e2e-specs.js @@ -1,5 +1,3 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import B from 'bluebird'; import _ from 'lodash'; import {retryInterval} from 'asyncbox'; @@ -13,8 +11,6 @@ import {PREDICATE_SEARCH, CLASS_CHAIN_SEARCH} from '../helpers/element'; import {initSession, deleteSession, hasDefaultPrebuiltWDA, MOCHA_TIMEOUT} from '../helpers/session'; import {util} from 'appium/support'; -chai.should(); -chai.use(chaiAsPromised); const TEST_PAUSE_DURATION = 500; @@ -28,7 +24,16 @@ describe('XCUITestDriver - find -', function () { this.timeout(MOCHA_TIMEOUT); let driver; + let chai; + before(async function () { + + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + const caps = amendCapabilities(UICATALOG_CAPS, { 'appium:usePrebuiltWDA': hasDefaultPrebuiltWDA(), }); diff --git a/test/functional/basic/gesture-e2e-specs.js b/test/functional/basic/gesture-e2e-specs.js index ec60740b3..6a568b3bd 100644 --- a/test/functional/basic/gesture-e2e-specs.js +++ b/test/functional/basic/gesture-e2e-specs.js @@ -1,5 +1,3 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import B from 'bluebird'; import {retryInterval} from 'asyncbox'; import {UICATALOG_CAPS, amendCapabilities} from '../desired'; @@ -7,8 +5,6 @@ import {PREDICATE_SEARCH} from '../helpers/element'; import {initSession, deleteSession, hasDefaultPrebuiltWDA, MOCHA_TIMEOUT} from '../helpers/session'; import {APPIUM_IMAGE} from '../web/helpers'; -chai.should(); -chai.use(chaiAsPromised); const BTN_OK_CNCL = 'Okay / Cancel'; @@ -16,6 +12,15 @@ describe('XCUITestDriver - gestures', function () { this.timeout(MOCHA_TIMEOUT); let driver; + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); describe('dynamic gestures', function () { before(async function () { diff --git a/test/functional/basic/touch-id-e2e-specs.js b/test/functional/basic/touch-id-e2e-specs.js index c18b89699..66e00f213 100644 --- a/test/functional/basic/touch-id-e2e-specs.js +++ b/test/functional/basic/touch-id-e2e-specs.js @@ -1,5 +1,3 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import {amendCapabilities, TOUCHIDAPP_CAPS} from '../desired'; import {initSession, deleteSession, hasDefaultPrebuiltWDA, MOCHA_TIMEOUT} from '../helpers/session'; import B from 'bluebird'; @@ -7,9 +5,6 @@ import {killAllSimulators} from '../helpers/simulator'; import {CLASS_CHAIN_SEARCH} from '../helpers/element'; import {waitForCondition} from 'asyncbox'; -chai.should(); -chai.use(chaiAsPromised); -const expect = chai.expect; const DEFAULT_IMPLICIT_TIMEOUT_MS = 1000; const TOUCH_ID_SELECTOR = '**/XCUIElementTypeStaticText[`label == "Touch ID for β€œbiometric”"`]'; @@ -23,6 +18,18 @@ if (!process.env.CI) { this.timeout(MOCHA_TIMEOUT * 2); this.retries(MOCHA_RETRIES); let driver; + let chai; + let expect; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + + expect = chai.expect; + }); beforeEach(async function () { await killAllSimulators(); diff --git a/test/functional/device/accessibility-e2e-specs.js b/test/functional/device/accessibility-e2e-specs.js index eafe9ba4a..141fd0f30 100644 --- a/test/functional/device/accessibility-e2e-specs.js +++ b/test/functional/device/accessibility-e2e-specs.js @@ -1,17 +1,23 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import {PREDICATE_SEARCH} from '../helpers/element'; import {MOCHA_TIMEOUT, initSession, deleteSession, hasDefaultPrebuiltWDA} from '../helpers/session'; import {SETTINGS_CAPS, amendCapabilities} from '../desired'; -chai.should(); -chai.use(chaiAsPromised); describe('Accessibility', function () { this.timeout(MOCHA_TIMEOUT); let driver, caps; + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); + beforeEach(function () { caps = amendCapabilities(SETTINGS_CAPS, { 'appium:usePrebuiltWDA': hasDefaultPrebuiltWDA(), diff --git a/test/functional/device/file-movement-e2e-specs.js b/test/functional/device/file-movement-e2e-specs.js index 83fb7fb47..190f282fc 100644 --- a/test/functional/device/file-movement-e2e-specs.js +++ b/test/functional/device/file-movement-e2e-specs.js @@ -1,12 +1,8 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import {amendCapabilities, UICATALOG_CAPS} from '../desired'; import {initSession, deleteSession, hasDefaultPrebuiltWDA, MOCHA_TIMEOUT} from '../helpers/session'; import {fs, tempDir, zip} from 'appium/support'; import path from 'path'; -chai.should(); -chai.use(chaiAsPromised); const UICAT_CONTAINER = `@com.example.apple-samplecode.UICatalog`; @@ -19,7 +15,15 @@ describe('XCUITestDriver - file movement', function () { this.timeout(MOCHA_TIMEOUT); let driver; + let chai; + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + const caps = amendCapabilities(UICATALOG_CAPS, { 'appium:usePrebuiltWDA': hasDefaultPrebuiltWDA(), }); diff --git a/test/functional/device/otherApps-e2e-specs.js b/test/functional/device/otherApps-e2e-specs.js index f87497820..c151a02a4 100644 --- a/test/functional/device/otherApps-e2e-specs.js +++ b/test/functional/device/otherApps-e2e-specs.js @@ -1,10 +1,6 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import {MOCHA_TIMEOUT, initSession, deleteSession, hasDefaultPrebuiltWDA} from '../helpers/session'; import {MULTIPLE_APPS, amendCapabilities} from '../desired'; -chai.should(); -chai.use(chaiAsPromised); describe('OtherApps', function () { this.timeout(MOCHA_TIMEOUT); @@ -12,7 +8,15 @@ describe('OtherApps', function () { let caps; let driver; - before(function () { + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + caps = amendCapabilities(MULTIPLE_APPS, { 'appium:usePrebuiltWDA': hasDefaultPrebuiltWDA(), 'appium:wdaStartupRetries': 0, diff --git a/test/functional/device/passwords-e2e-specs.js b/test/functional/device/passwords-e2e-specs.js index 9c0eb9a24..bd7b07e9d 100644 --- a/test/functional/device/passwords-e2e-specs.js +++ b/test/functional/device/passwords-e2e-specs.js @@ -1,17 +1,23 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import {MOCHA_TIMEOUT, initSession, deleteSession, hasDefaultPrebuiltWDA} from '../helpers/session'; import {UICATALOG_CAPS, amendCapabilities, extractCapabilityValue} from '../desired'; import {util} from 'appium/support'; -chai.should(); -chai.use(chaiAsPromised); describe('Passwords', function () { this.timeout(MOCHA_TIMEOUT); let driver, caps; + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); + beforeEach(function () { caps = amendCapabilities(UICATALOG_CAPS, { 'appium:usePrebuiltWDA': hasDefaultPrebuiltWDA(), diff --git a/test/functional/device/performance-e2e-specs.js b/test/functional/device/performance-e2e-specs.js index ff427ec05..77c0a8118 100644 --- a/test/functional/device/performance-e2e-specs.js +++ b/test/functional/device/performance-e2e-specs.js @@ -1,17 +1,22 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import B from 'bluebird'; import {amendCapabilities, UICATALOG_CAPS} from '../desired'; import {initSession, deleteSession, hasDefaultPrebuiltWDA, MOCHA_TIMEOUT} from '../helpers/session'; -chai.should(); -chai.use(chaiAsPromised); describe('XCUITestDriver - performance', function () { this.timeout(MOCHA_TIMEOUT); const profileName = 'Time Profiler'; let driver; + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); describe('record performance metrics', function () { before(async function () { diff --git a/test/functional/device/xctest-e2e-specs.js b/test/functional/device/xctest-e2e-specs.js index 3d1237fd2..79140ec5e 100644 --- a/test/functional/device/xctest-e2e-specs.js +++ b/test/functional/device/xctest-e2e-specs.js @@ -1,6 +1,4 @@ -import chai from 'chai'; import path from 'path'; -import chaiAsPromised from 'chai-as-promised'; import {MOCHA_TIMEOUT, initSession, deleteSession, hasDefaultPrebuiltWDA} from '../helpers/session'; import {GENERIC_CAPS, amendCapabilities} from '../desired'; import xcode from 'appium-xcode'; @@ -15,15 +13,21 @@ const TEST_BUNDLE_PATH = path.resolve( ); const XCTEST_BUNDLE_PATH = path.join(TEST_BUNDLE_PATH, 'PlugIns', 'XCTesterAppUITests.xctest'); -chai.should(); -chai.use(chaiAsPromised); if (process.env.LAUNCH_WITH_IDB) { describe('XCTest', function () { this.timeout(MOCHA_TIMEOUT); let driver; + let chai; + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + // idb_companion doesn't work with xcode 13 or lower due to concurrency lib issue. if ( /** @type {import('appium-xcode').XcodeVersion} */ (await xcode.getVersion(true)).major < 14 diff --git a/test/functional/driver/driver-e2e-specs.js b/test/functional/driver/driver-e2e-specs.js index 9f5dad08d..90e28ce8b 100644 --- a/test/functional/driver/driver-e2e-specs.js +++ b/test/functional/driver/driver-e2e-specs.js @@ -1,5 +1,3 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import {retryInterval} from 'asyncbox'; import {getSimulator} from 'appium-ios-simulator'; import {killAllSimulators, deleteDeviceWithRetry, cleanupSimulator} from '../helpers/simulator'; @@ -18,9 +16,6 @@ import axios from 'axios'; const SIM_DEVICE_NAME = 'xcuitestDriverTest'; -chai.should(); -chai.use(chaiAsPromised); - const simctl = new Simctl(); async function createDevice() { @@ -41,8 +36,15 @@ describe('XCUITestDriver', function () { let baseCaps; let caps; let driver; + let chai; before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + const udid = await createDevice(); baseCaps = amendCapabilities(UICATALOG_SIM_CAPS, {'appium:udid': udid}); caps = amendCapabilities(baseCaps, { diff --git a/test/functional/long/typing-stress-e2e-specs.js b/test/functional/long/typing-stress-e2e-specs.js index 5d148e758..220dc3e08 100644 --- a/test/functional/long/typing-stress-e2e-specs.js +++ b/test/functional/long/typing-stress-e2e-specs.js @@ -1,14 +1,8 @@ -// @ts-check - -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import {UICATALOG_CAPS, amendCapabilities} from '../desired'; import {PREDICATE_SEARCH} from '../helpers/element'; import {initSession, deleteSession} from '../helpers/session'; import {retryInterval} from 'asyncbox'; -chai.should(); -chai.use(chaiAsPromised); // leave the long test to Travis const TYPING_TRIES = process.env.CI ? 100 : 10; @@ -17,7 +11,15 @@ describe('XCUITestDriver - long tests', function () { this.timeout(0); let driver; + let chai; + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + const caps = amendCapabilities(UICATALOG_CAPS, {'appium:maxTypingFrequency': 20}); driver = await initSession(caps); }); diff --git a/test/functional/tv/tvos-e2e-specs.js b/test/functional/tv/tvos-e2e-specs.js index 340ca19a4..2ae850c00 100644 --- a/test/functional/tv/tvos-e2e-specs.js +++ b/test/functional/tv/tvos-e2e-specs.js @@ -1,5 +1,3 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import {getSimulator} from 'appium-ios-simulator'; import {cleanupSimulator} from '../helpers/simulator'; import Simctl from 'node-simctl'; @@ -8,8 +6,6 @@ import {TVOS_CAPS} from '../desired'; const SIM_DEVICE_NAME = 'xcuitestDriverTest'; -chai.should(); -chai.use(chaiAsPromised); const simctl = new Simctl(); @@ -18,7 +14,15 @@ describe('tvOS', function () { let baseCaps; let udid; + let chai; + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + udid = await simctl.createDevice( SIM_DEVICE_NAME, TVOS_CAPS.deviceName, diff --git a/test/functional/web/safari-alerts-e2e-specs.js b/test/functional/web/safari-alerts-e2e-specs.js index ca3b9fd47..892be4205 100644 --- a/test/functional/web/safari-alerts-e2e-specs.js +++ b/test/functional/web/safari-alerts-e2e-specs.js @@ -1,18 +1,22 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import {retryInterval} from 'asyncbox'; import {SAFARI_CAPS, amendCapabilities} from '../desired'; import {initSession, deleteSession, hasDefaultPrebuiltWDA, MOCHA_TIMEOUT} from '../helpers/session'; import {GUINEA_PIG_PAGE} from './helpers'; -chai.should(); -chai.use(chaiAsPromised); describe('safari - alerts', function () { this.timeout(MOCHA_TIMEOUT); let driver; + let chai; + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + const caps = amendCapabilities(SAFARI_CAPS, { 'appium:safariInitialUrl': GUINEA_PIG_PAGE, 'appium:safariAllowPopups': true, diff --git a/test/functional/web/safari-basic-e2e-specs.js b/test/functional/web/safari-basic-e2e-specs.js index 251dda70a..04e81fcb7 100644 --- a/test/functional/web/safari-basic-e2e-specs.js +++ b/test/functional/web/safari-basic-e2e-specs.js @@ -1,5 +1,3 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import B from 'bluebird'; import {MOCHA_TIMEOUT, initSession, deleteSession, hasDefaultPrebuiltWDA} from '../helpers/session'; import {SAFARI_CAPS, amendCapabilities} from '../desired'; @@ -22,9 +20,6 @@ import { import {util} from 'appium/support'; import {retryInterval} from 'asyncbox'; -chai.should(); -chai.use(chaiAsPromised); -const expect = chai.expect; const DEFAULT_CAPS = amendCapabilities(SAFARI_CAPS, { 'appium:safariInitialUrl': GUINEA_PIG_PAGE, @@ -37,6 +32,18 @@ describe('Safari - basics -', function () { this.timeout(MOCHA_TIMEOUT); let driver; + let chai; + let expect; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + + expect = chai.expect; + }); describe('init', function () { afterEach(async function () { diff --git a/test/functional/web/safari-execute-e2e-specs.js b/test/functional/web/safari-execute-e2e-specs.js index 872659b2a..bc4715e5b 100644 --- a/test/functional/web/safari-execute-e2e-specs.js +++ b/test/functional/web/safari-execute-e2e-specs.js @@ -1,15 +1,7 @@ -// import _ from 'lodash'; -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; -// import http from 'http'; import {SAFARI_CAPS, amendCapabilities} from '../desired'; import {initSession, deleteSession, hasDefaultPrebuiltWDA, MOCHA_TIMEOUT} from '../helpers/session'; import {openPage, GUINEA_PIG_PAGE} from './helpers'; -chai.should(); -chai.use(chaiAsPromised); -const expect = chai.expect; - const SCROLL_INTO_VIEW = `return arguments[0].scrollIntoView(true);`; const GET_RIGHT_INNERHTML = `return document.body.innerHTML.indexOf('I am some page content') > 0`; const GET_WRONG_INNERHTML = `return document.body.innerHTML.indexOf('I am not some page content') > 0`; @@ -19,7 +11,17 @@ describe('safari - execute -', function () { this.timeout(MOCHA_TIMEOUT); let driver; + let chai; + let expect; + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + expect = chai.expect; + const caps = amendCapabilities(SAFARI_CAPS, { 'appium:safariInitialUrl': GUINEA_PIG_PAGE, 'appium:showSafariConsoleLog': true, diff --git a/test/functional/web/safari-nativewebtap-e2e-specs.js b/test/functional/web/safari-nativewebtap-e2e-specs.js index ce6bd4991..ce8c36e71 100644 --- a/test/functional/web/safari-nativewebtap-e2e-specs.js +++ b/test/functional/web/safari-nativewebtap-e2e-specs.js @@ -1,5 +1,3 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import _ from 'lodash'; import {util} from 'appium/support'; import {initSession, deleteSession, hasDefaultPrebuiltWDA, MOCHA_TIMEOUT} from '../helpers/session'; @@ -23,8 +21,6 @@ import {retryInterval} from 'asyncbox'; import B from 'bluebird'; import {CLASS_CHAIN_SEARCH} from '../helpers/element'; -chai.should(); -chai.use(chaiAsPromised); const caps = amendCapabilities(SAFARI_CAPS, { 'appium:safariInitialUrl': GUINEA_PIG_PAGE, @@ -42,7 +38,16 @@ describe('Safari - coordinate conversion -', function () { this.timeout(MOCHA_TIMEOUT * 2); const devices = [DEVICE_NAME, DEVICE_NAME_FOR_SAFARI_IPAD]; - before(function () { + + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + if (process.env.CI) { return this.skip(); } diff --git a/test/functional/web/safari-ssl-e2e-specs.js b/test/functional/web/safari-ssl-e2e-specs.js index 34b90ea57..08e73b334 100644 --- a/test/functional/web/safari-ssl-e2e-specs.js +++ b/test/functional/web/safari-ssl-e2e-specs.js @@ -1,6 +1,4 @@ import B from 'bluebird'; -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import https from 'https'; import {getFreePort} from '../helpers/ports'; import os from 'os'; @@ -11,8 +9,6 @@ import {doesIncludeCookie, doesNotIncludeCookie, newCookie, oldCookie1} from './ const pem = B.promisifyAll(_pem); -chai.should(); -chai.use(chaiAsPromised); let caps; let pemCertificate; @@ -25,7 +21,15 @@ describe('Safari SSL', function () { let driver; /** @type {string} */ let localHttpsUrl; + let chai; + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + // Create a random pem certificate const privateKey = await pem.createPrivateKeyAsync(); const keys = await pem.createCertificateAsync({ diff --git a/test/functional/web/safari-window-e2e-specs.js b/test/functional/web/safari-window-e2e-specs.js index 645361bae..817a69e10 100644 --- a/test/functional/web/safari-window-e2e-specs.js +++ b/test/functional/web/safari-window-e2e-specs.js @@ -1,6 +1,4 @@ -import chai from 'chai'; import _ from 'lodash'; -import chaiAsPromised from 'chai-as-promised'; import {SAFARI_CAPS, amendCapabilities} from '../desired'; import {initSession, deleteSession, hasDefaultPrebuiltWDA, MOCHA_TIMEOUT} from '../helpers/session'; import { @@ -12,8 +10,6 @@ import { } from './helpers'; import {waitForCondition} from 'asyncbox'; -chai.should(); -chai.use(chaiAsPromised); const GET_ELEM_SYNC = `return document.getElementsByTagName('h1')[0].innerHTML;`; const GET_ELEM_ASYNC = `arguments[arguments.length - 1](document.getElementsByTagName('h1')[0].innerHTML);`; @@ -26,6 +22,16 @@ const SUB_FRAME_3_TITLE = 'Sub frame 3'; const DEFAULT_IMPLICIT_TIMEOUT_MS = 1000; describe('safari - windows and frames', function () { + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); + describe('without safariAllowPopups', function () { this.timeout(MOCHA_TIMEOUT); diff --git a/test/unit/app-infos-cache-specs.js b/test/unit/app-infos-cache-specs.js index efc306f6f..a7eb57908 100644 --- a/test/unit/app-infos-cache-specs.js +++ b/test/unit/app-infos-cache-specs.js @@ -1,19 +1,24 @@ import { AppInfosCache, } from '../../lib/app-infos-cache'; -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import { fs, tempDir, zip } from 'appium/support'; import path from 'node:path'; import log from '../../lib/logger.js'; -chai.should(); -chai.use(chaiAsPromised); - const BIOMETRIC_BUNDLE_ID = 'com.mwakizaka.biometric'; describe('AppInfosCache', function () { + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); + describe('retrives info from different types of apps', function () { let ipaPath; const appPath = path.resolve(__dirname, '..', 'assets', 'biometric.app'); diff --git a/test/unit/app-utils-specs.js b/test/unit/app-utils-specs.js index fbbe49338..ddd5cc504 100644 --- a/test/unit/app-utils-specs.js +++ b/test/unit/app-utils-specs.js @@ -2,15 +2,21 @@ import { unzipStream, unzipFile, } from '../../lib/app-utils'; -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import { fs, tempDir, zip } from 'appium/support'; import path from 'node:path'; -chai.should(); -chai.use(chaiAsPromised); describe('app-utils', function () { + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); + describe('unzipStream', function () { it('should unzip from stream', async function () { try { diff --git a/test/unit/commands/activeAppInfo-specs.js b/test/unit/commands/activeAppInfo-specs.js index ededab475..18e978428 100644 --- a/test/unit/commands/activeAppInfo-specs.js +++ b/test/unit/commands/activeAppInfo-specs.js @@ -1,19 +1,22 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import sinon from 'sinon'; import XCUITestDriver from '../../../lib/driver'; -chai.should(); -chai.use(chaiAsPromised); describe('get activeapp commands', function () { const driver = new XCUITestDriver(); - // @ts-ignore give the driver a spy-able proxy object driver.wda = {jwproxy: {command: () => {}}}; let proxyStub; - this.beforeEach(function () { - // @ts-ignore ok for tests + let chai; + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); + + beforeEach(function () { proxyStub = sinon.stub(driver.wda.jwproxy, 'command'); }); diff --git a/test/unit/commands/alert-specs.js b/test/unit/commands/alert-specs.js index d3801c68f..7aa2b1d19 100644 --- a/test/unit/commands/alert-specs.js +++ b/test/unit/commands/alert-specs.js @@ -1,14 +1,19 @@ import sinon from 'sinon'; import XCUITestDriver from '../../../lib/driver'; -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; -chai.should(); -chai.use(chaiAsPromised); describe('alert commands', function () { let driver = new XCUITestDriver(); let proxySpy = sinon.stub(driver, 'proxyCommand'); + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); afterEach(function () { proxySpy.reset(); @@ -25,7 +30,7 @@ describe('alert commands', function () { describe('setAlertText', function () { it('should send translated POST request to WDA', async function () { await driver.setAlertText('some text'); - proxySpy.should.have.been.calledOnceWith('/alert/text', 'POST', {value: 'some text'}); + proxySpy.calledOnceWith('/alert/text', 'POST', {value: 'some text'}).should.be.true; }); }); describe('postAcceptAlert', function () { @@ -57,7 +62,7 @@ describe('alert commands', function () { it('should send accept alert request to WDA with encoded button label', async function () { const buttonLabel = 'some label'; await driver.execute(`mobile: ${commandName}`, {action: 'accept', buttonLabel}); - proxySpy.should.have.been.calledOnceWith('/alert/accept', 'POST', {name: buttonLabel}); + proxySpy.calledOnceWith('/alert/accept', 'POST', {name: buttonLabel}).should.be.true; }); it('should send dimsiss alert request to WDA if button label is not provided', async function () { diff --git a/test/unit/commands/context-specs.js b/test/unit/commands/context-specs.js index f22e0f691..64b3e245c 100644 --- a/test/unit/commands/context-specs.js +++ b/test/unit/commands/context-specs.js @@ -1,12 +1,19 @@ import XCUITestDriver from '../../../lib/driver'; -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; -chai.should(); -chai.use(chaiAsPromised); -const expect = chai.expect; describe('context', function () { + let chai; + let expect; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + expect = chai.expect; + }); + describe('onPageChange', function () { const pageChangeNotification = { appIdKey: '5191', diff --git a/test/unit/commands/deviceinfo-specs.js b/test/unit/commands/deviceinfo-specs.js index 4d06ae6b5..fe393acc5 100644 --- a/test/unit/commands/deviceinfo-specs.js +++ b/test/unit/commands/deviceinfo-specs.js @@ -1,19 +1,23 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import sinon from 'sinon'; import XCUITestDriver from '../../../lib/driver'; -chai.should(); -chai.use(chaiAsPromised); describe('get deviceinfo commands', function () { const driver = new XCUITestDriver(); - // @ts-ignore give the driver a spy-able proxy object driver.wda = {jwproxy: {command: () => {}}}; let proxyStub; - this.beforeEach(function () { - // @ts-ignore ok for tests + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); + + beforeEach(function () { proxyStub = sinon.stub(driver.wda.jwproxy, 'command'); }); @@ -27,7 +31,6 @@ describe('get deviceinfo commands', function () { currentLocale: 'ja_EN', }; proxyStub.returns(opts); - await driver.mobileGetDeviceInfo().should.eventually.eql(opts); }); diff --git a/test/unit/commands/element-specs.js b/test/unit/commands/element-specs.js index 2b8115160..5399752d7 100644 --- a/test/unit/commands/element-specs.js +++ b/test/unit/commands/element-specs.js @@ -1,25 +1,26 @@ -// @ts-check - -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; -import {createSandbox} from 'sinon'; -import sinonChai from 'sinon-chai'; +// eslint-disable-next-line +import sinon, {createSandbox} from 'sinon'; import XCUITestDriver from '../../../lib/driver'; -chai.should(); -chai.use(chaiAsPromised).use(sinonChai); describe('element commands', function () { - /** @type {sinon.SinonSandbox} */ let sandbox; /** @type {XCUITestDriver} */ let driver; + let chai; + /** @type {sinon.SinonStubbedMember} */ let proxyStub; - before(function () { + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + driver = new XCUITestDriver(); }); @@ -39,8 +40,8 @@ describe('element commands', function () { it('should call setValue', async function () { await driver.setValueImmediate('hello', '2'); - driver.setValue.should.have.been.calledOnceWithExactly('hello', '2'); - driver.setValue.should.have.returned(undefined); + driver.setValue.calledOnceWithExactly('hello', '2').should.be.true; + driver.setValue.returned(undefined).should.be.true; }); }); @@ -49,7 +50,7 @@ describe('element commands', function () { const attribute = 'enabled'; afterEach(function () { - proxyStub.should.have.been.calledOnce; + proxyStub.calledOnce.should.be.true; }); it('should properly parse boolean true attribute presented as integer', async function () { @@ -88,7 +89,7 @@ describe('element commands', function () { const property = 'enabled'; afterEach(function () { - proxyStub.should.have.been.calledOnce; + proxyStub.calledOnce.should.be.true; }); it('should properly parse boolean true attribute presented as integer', async function () { @@ -127,8 +128,8 @@ describe('element commands', function () { const getContentSizeStub = sandbox.stub(driver, 'getContentSize'); getContentSizeStub.resolves('foo'); (await driver.getAttribute('contentSize', 2)).should.eql('foo'); - proxyStub.should.not.have.been.called; - getContentSizeStub.should.have.been.calledOnce; + proxyStub.called.should.be.false; + getContentSizeStub.calledOnce.should.be.true; }); }); @@ -167,7 +168,7 @@ describe('element commands', function () { driver.curContext = oldContext; }); it('should throw when in a web context', async function () { - await driver.getContentSize(el).should.be.rejectedWith(/not yet implemented/); + await driver.getContentSize(el).should.be.rejectedWith(/not yet implemented/); }); }); @@ -190,7 +191,7 @@ describe('element commands', function () { left: 0, scrollableOffset: 100, }); - getRectStub.should.have.been.calledOnce; + getRectStub.calledOnce.should.be.true; }); it('should get simple difference in element positions of a table', async function () { @@ -210,7 +211,7 @@ describe('element commands', function () { left: 0, scrollableOffset: 170, }); - getRectStub.should.have.been.calledTwice; + getRectStub.calledTwice.should.be.true; }); it('should be sensitive to row items in the case of a collection view', async function () { @@ -239,7 +240,7 @@ describe('element commands', function () { left: 0, scrollableOffset, }); - getRectStub.should.have.been.calledThrice; + getRectStub.calledThrice.should.be.true; }); }); @@ -252,33 +253,33 @@ describe('element commands', function () { describe('success', function () { it('should proxy string as array of characters', async function () { await driver.setValue('hello\uE006', elementId); - proxyStub.should.have.been.calledOnceWith(expectedEndpoint, expectedMethod, { + proxyStub.calledOnceWith(expectedEndpoint, expectedMethod, { value: ['h', 'e', 'l', 'l', 'o', '\n'], - }); + }).should.be.true; }); it('should proxy string with smileys as array of characters', async function () { await driver.setValue('helloπŸ˜€πŸ˜Ž', elementId); - proxyStub.should.have.been.calledOnceWith(expectedEndpoint, expectedMethod, { + proxyStub.calledOnceWith(expectedEndpoint, expectedMethod, { value: ['h', 'e', 'l', 'l', 'o', 'πŸ˜€', '😎'], - }); + }).should.be.true; }); it('should proxy number as array of characters', async function () { await driver.setValue(1234.56, elementId); - proxyStub.should.have.been.calledOnceWith(expectedEndpoint, expectedMethod, { + proxyStub.calledOnceWith(expectedEndpoint, expectedMethod, { value: ['1', '2', '3', '4', '.', '5', '6'], - }); + }).should.be.true; }); it('should proxy string array as array of characters', async function () { await driver.setValue(['hel', 'lo'], elementId); - proxyStub.should.have.been.calledOnceWith(expectedEndpoint, expectedMethod, { + proxyStub.calledOnceWith(expectedEndpoint, expectedMethod, { value: ['h', 'e', 'l', 'l', 'o'], - }); + }).should.be.true; }); it('should proxy integer array as array of characters', async function () { await driver.setValue([1234], elementId); - proxyStub.should.have.been.calledOnceWith(expectedEndpoint, expectedMethod, { + proxyStub.calledOnceWith(expectedEndpoint, expectedMethod, { value: ['1', '2', '3', '4'], - }); + }).should.be.true; }); }); @@ -318,19 +319,19 @@ describe('element commands', function () { it('with default', async function () { driver.opts.sendKeyStrategy = undefined; await driver.setValue('hello\uE006πŸ˜€', elementId); - atomElement.should.have.been.calledOnce; - executeAtom.should.have.been.calledOnce; - setValueWithWebAtom.should.have.been.calledOnceWith( + atomElement.calledOnce.should.be.true; + executeAtom.calledOnce.should.be.true; + setValueWithWebAtom.calledOnceWith( webEl, 'hello\uE006πŸ˜€' - ); + ).should.be.true; }); it('with oneByOne', async function () { driver.opts.sendKeyStrategy = 'oneByOne'; await driver.setValue('hello\uE006πŸ˜€', elementId); - atomElement.should.have.been.calledOnce; - executeAtom.should.have.been.calledOnce; + atomElement.calledOnce.should.be.true; + executeAtom.calledOnce.should.be.true; setValueWithWebAtom.getCall(0).args.should.eql([webEl, 'h']); setValueWithWebAtom.getCall(1).args.should.eql([webEl, 'e']); setValueWithWebAtom.getCall(2).args.should.eql([webEl, 'l']); diff --git a/test/unit/commands/file-movement-specs.js b/test/unit/commands/file-movement-specs.js index 5d2e840ee..3bd48d3f1 100644 --- a/test/unit/commands/file-movement-specs.js +++ b/test/unit/commands/file-movement-specs.js @@ -1,12 +1,20 @@ import {parseContainerPath} from '../../../lib/commands/file-movement'; -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import {tempDir} from 'appium/support'; -const should = chai.should(); -chai.use(chaiAsPromised); describe('file-movement', function () { + let chai; + let expect; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + expect = chai.expect; + }); + describe('parseContainerPath', function () { it('should parse with container', async function () { const mntRoot = await tempDir.openDir(); @@ -17,7 +25,7 @@ describe('file-movement', function () { bundleId.should.eql('io.appium.example'); pathInContainer.should.eql(`${mntRoot}/Documents/file.txt`); - /** @type {string} */ (containerType).should.eql('app'); + containerType.should.eql('app'); }); it('should parse with container root', async function () { const mntRoot = await tempDir.openDir(); @@ -28,7 +36,7 @@ describe('file-movement', function () { bundleId.should.eql('io.appium.example'); pathInContainer.should.eql(mntRoot); - /** @type {string} */ (containerType).should.eql('documents'); + containerType.should.eql('documents'); }); it('should parse without container', async function () { const mntRoot = await tempDir.openDir(); @@ -39,7 +47,7 @@ describe('file-movement', function () { bundleId.should.eql('io.appium.example'); pathInContainer.should.eql(`${mntRoot}/Documents/file.txt`); - should.equal(containerType, null); + expect(containerType).equal(null); }); it('should raise an error if no container path', async function () { const mntRoot = await tempDir.openDir(); diff --git a/test/unit/commands/find-specs.js b/test/unit/commands/find-specs.js index bf0c8597e..25b8a8453 100644 --- a/test/unit/commands/find-specs.js +++ b/test/unit/commands/find-specs.js @@ -5,6 +5,12 @@ describe('general commands', function () { const driver = new XCUITestDriver(); const proxySpy = sinon.stub(driver, 'proxyCommand'); + let chai; + + before(async function () { + chai = await import('chai'); + chai.should(); + }); afterEach(function () { proxySpy.reset(); }); @@ -22,10 +28,10 @@ describe('general commands', function () { try { await driver.findNativeElementOrElements(strategy, selector, mult); } catch (ign) {} - proxySpy.should.have.been.calledOnceWith(`/element${mult ? 's' : ''}`, 'POST', { + proxySpy.calledOnceWith(`/element${mult ? 's' : ''}`, 'POST', { using: modStrategy || strategy, value: modSelector, - }); + }).should.be.true; proxySpy.reset(); } @@ -100,16 +106,16 @@ describe('general commands', function () { let el = await driver.findNativeElementOrElements('xpath', variant, false, { ELEMENT: 'ctx', }); - proxySpy.should.have.been.calledTwice; - proxySpy.should.have.been.calledWith('/element/ctx/element', 'POST', { + proxySpy.calledTwice.should.be.true; + proxySpy.calledWith('/element/ctx/element', 'POST', { using: 'class chain', value: '*[1]', - }); - proxySpy.should.have.been.calledWith('/element/ctx/element', 'POST', { + }).should.be.true; + proxySpy.calledWith('/element/ctx/element', 'POST', { using: 'class chain', value: '*[2]', - }); - attribSpy.should.have.been.calledTwice; + }).should.be.true; + attribSpy.calledTwice.should.be.true; el.should.eql({ELEMENT: 2}); proxySpy.reset(); attribSpy.reset(); diff --git a/test/unit/commands/general-specs.js b/test/unit/commands/general-specs.js index 0dae3bf9b..7740ed782 100644 --- a/test/unit/commands/general-specs.js +++ b/test/unit/commands/general-specs.js @@ -1,39 +1,41 @@ import sinon from 'sinon'; import _ from 'lodash'; import XCUITestDriver from '../../../lib/driver'; -import chai from 'chai'; -import sinonChai from 'sinon-chai'; -chai.use(sinonChai); describe('general commands', function () { const driver = new XCUITestDriver(); - const proxyStub = sinon.stub(driver, 'proxyCommand'); + + let chai; + let mockDriver; + + before(async function () { + chai = await import('chai'); + chai.should(); + }); + + beforeEach(function () { + mockDriver = sinon.mock(driver); + }); afterEach(function () { - proxyStub.reset(); + mockDriver.verify(); }); describe('background', function () { it('should deactivate app for the given time if seconds is zero or greater', async function () { + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/deactivateApp', 'POST', { duration: 0.5 }, true); await driver.background(0.5); - proxyStub.calledOnce.should.be.true; - proxyStub.firstCall.args[0].should.eql('/wda/deactivateApp'); - proxyStub.firstCall.args[1].should.eql('POST'); }); it('should switch to home screen if seconds less than zero', async function () { + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/homescreen', 'POST', {}, false); await driver.background(-1); - proxyStub.calledOnce.should.be.true; - proxyStub.firstCall.args[0].should.eql('/wda/homescreen'); - proxyStub.firstCall.args[1].should.eql('POST'); }); it('should switch to home screen if seconds is null', async function () { + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/homescreen', 'POST', {}, false); await driver.background(); - proxyStub.calledOnce.should.be.true; - proxyStub.firstCall.args[0].should.eql('/wda/homescreen'); - proxyStub.firstCall.args[1].should.eql('POST'); }); }); @@ -50,7 +52,6 @@ describe('general commands', function () { simctl: true, sendBiometricMatch: sandbox.stub(), }; - // @ts-ignore driver._device = device; }); @@ -60,20 +61,20 @@ describe('general commands', function () { it('should send default request to Simulator', async function () { await driver.touchId(); - device.sendBiometricMatch.should.have.been.calledOnceWith(true, 'touchId'); + device.sendBiometricMatch.calledOnceWith(true, 'touchId').should.be.true; }); it('should send request to Simulator with false', async function () { await driver.touchId(false); - device.sendBiometricMatch.should.have.been.calledOnceWith(false, 'touchId'); + device.sendBiometricMatch.calledOnceWith(false, 'touchId').should.be.true; }); it('should not be called on a real device', async function () { delete device.simctl; device.devicectl = true; await driver.touchId().should.be.rejected; - device.sendBiometricMatch.should.not.have.been.called; - // sendBiometricMatchSpy.notCalled.should.be.true; + + device.sendBiometricMatch.called.should.be.false; }); }); @@ -90,7 +91,6 @@ describe('general commands', function () { simctl: true, enrollBiometric: sandbox.stub(), }; - // @ts-ignore driver._device = device; }); @@ -102,7 +102,7 @@ describe('general commands', function () { // @ts-expect-error random stuff on opts again driver.opts.allowTouchIdEnroll = true; await driver.toggleEnrollTouchId(); - device.enrollBiometric.should.have.been.calledOnce; + device.enrollBiometric.calledOnce.should.be.true; }); it('should not be called on a real device', async function () { @@ -111,18 +111,14 @@ describe('general commands', function () { // @ts-expect-error random stuff on opts again driver.opts.allowTouchIdEnroll = true; await driver.toggleEnrollTouchId().should.be.rejected; - device.enrollBiometric.should.not.have.been.called; + device.enrollBiometric.called.should.be.false; }); }); describe('window size', function () { it('should be able to get the current window size with Rect', async function () { - proxyStub.withArgs('/window/size', 'GET').resolves({width: 100, height: 20}); - + mockDriver.expects('proxyCommand').once().withExactArgs('/window/size', 'GET').returns({width: 100, height: 20}); await driver.getWindowRect(); - proxyStub.calledOnce.should.be.true; - proxyStub.firstCall.args[0].should.eql('/window/size'); - proxyStub.firstCall.args[1].should.eql('GET'); }); }); @@ -178,8 +174,8 @@ describe('general commands', function () { }); describe('getDevicePixelRatio and getStatusBarHeight', function () { - beforeEach(function () { - proxyStub.withArgs('/wda/screen', 'GET').resolves({ + before(function () { + mockDriver.expects('proxyCommand').withExactArgs('/wda/screen', 'GET').returns({ statusBarSize: { width: 100, height: 20, diff --git a/test/unit/commands/gesture-specs.js b/test/unit/commands/gesture-specs.js index 1340b8a7e..7dc24d48d 100644 --- a/test/unit/commands/gesture-specs.js +++ b/test/unit/commands/gesture-specs.js @@ -1,18 +1,25 @@ import sinon from 'sinon'; import XCUITestDriver from '../../../lib/driver'; import {gesturesChainToString} from '../../../lib/commands/gesture'; -import _ from 'lodash'; -import sinonChai from 'sinon-chai'; -import chai from 'chai'; -chai.use(sinonChai); describe('gesture commands', function () { const driver = new XCUITestDriver(); - const proxySpy = sinon.stub(driver, 'proxyCommand'); + + let chai; + let mockDriver; + + before(async function () { + chai = await import('chai'); + chai.should(); + }); + + beforeEach(function () { + mockDriver = sinon.mock(driver); + }); afterEach(function () { - proxySpy.reset(); + mockDriver.verify(); }); describe('gesturesChainToString', function () { @@ -55,42 +62,32 @@ describe('gesture commands', function () { .should.be.rejectedWith(/Mobile scroll supports the following strategies/); }); it('should pass through bare element', async function () { + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/element/4/scroll', 'POST', { direction: 'down' }); await driver.execute('mobile: scroll', {element: 4, direction: 'down'}); - proxySpy.calledOnce.should.be.true; - proxySpy.firstCall.args[0].should.eql('/wda/element/4/scroll'); - proxySpy.firstCall.args[1].should.eql('POST'); }); it('should unpack element object', async function () { + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/element/4/scroll', 'POST', { direction: 'down' }); await driver.execute('mobile: scroll', {element: {ELEMENT: 4}, direction: 'down'}); - proxySpy.calledOnce.should.be.true; - proxySpy.firstCall.args[0].should.eql('/wda/element/4/scroll'); - proxySpy.firstCall.args[1].should.eql('POST'); }); it('should pass name strategy exclusively', async function () { + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/element/4/scroll', 'POST', { name: 'something' }); await driver.execute('mobile: scroll', {element: 4, direction: 'down', name: 'something'}); - proxySpy.should.have.been.calledOnceWith('/wda/element/4/scroll', 'POST', { - name: 'something', - }); }); it('should pass direction strategy exclusively', async function () { + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/element/4/scroll', 'POST', { direction: 'down' }); await driver.execute('mobile: scroll', { element: 4, direction: 'down', predicateString: 'something', }); - proxySpy.should.have.been.calledOnceWith('/wda/element/4/scroll', 'POST', { - direction: 'down', - }); }); it('should pass predicateString strategy exclusively', async function () { + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/element/4/scroll', 'POST', { predicateString: 'something' }); await driver.execute('mobile: scroll', { element: 4, toVisible: true, predicateString: 'something', }); - proxySpy.should.have.been.calledOnceWith('/wda/element/4/scroll', 'POST', { - predicateString: 'something', - }); }); }); @@ -107,8 +104,8 @@ describe('gesture commands', function () { }); it('should proxy a swipe up request through to WDA', async function () { + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/element/4/swipe', 'POST', { direction: 'up' }); await driver.execute(`mobile: ${commandName}`, {element: 4, direction: 'up'}); - proxySpy.should.have.been.calledOnceWith('/wda/element/4/swipe', 'POST', {direction: 'up'}); }); }); @@ -132,11 +129,12 @@ describe('gesture commands', function () { it('should proxy a pinch request through to WDA', async function () { const opts = {element: 4, scale: 1, velocity: '1'}; - await driver.execute(`mobile: ${commandName}`, opts); - proxySpy.should.have.been.calledOnceWith('/wda/element/4/pinch', 'POST', { + + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/element/4/pinch', 'POST', { scale: opts.scale, velocity: parseInt(opts.velocity, 10), }); + await driver.execute(`mobile: ${commandName}`, opts); }); }); @@ -144,23 +142,19 @@ describe('gesture commands', function () { const commandName = 'doubleTap'; it('should proxy a doubleTap request without element through to WDA', async function () { + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/doubleTap', 'POST', { x: undefined, y: undefined }); await driver.execute(`mobile: ${commandName}`); - proxySpy.calledOnce.should.be.true; - proxySpy.firstCall.args[0].should.eql('/wda/doubleTap'); - proxySpy.firstCall.args[1].should.eql('POST'); }); it('should proxy a doubleTap request for an element through to WDA', async function () { + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/element/4/doubleTap', 'POST', { x: undefined, y: undefined }); await driver.execute(`mobile: ${commandName}`, {element: 4}); - proxySpy.calledOnce.should.be.true; - proxySpy.firstCall.args[0].should.eql('/wda/element/4/doubleTap'); - proxySpy.firstCall.args[1].should.eql('POST'); }); it('should proxy a doubleTap request for a coordinate point through to WDA', async function () { const opts = {x: 100, y: 100}; + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/doubleTap', 'POST', opts); await driver.execute(`mobile: ${commandName}`, opts); - proxySpy.should.have.been.calledOnceWith('/wda/doubleTap', 'POST', opts); }); }); @@ -168,10 +162,8 @@ describe('gesture commands', function () { const commandName = 'twoFingerTap'; it('should proxy a twoFingerTap request for an element through to WDA', async function () { + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/element/4/twoFingerTap', 'POST'); await driver.execute(`mobile: ${commandName}`, {element: 4}); - proxySpy.calledOnce.should.be.true; - proxySpy.firstCall.args[0].should.eql('/wda/element/4/twoFingerTap'); - proxySpy.firstCall.args[1].should.eql('POST'); }); }); @@ -190,36 +182,26 @@ describe('gesture commands', function () { it('should proxy a touchAndHold request without element through to WDA', async function () { const opts = {duration: 100}; + + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/touchAndHold', 'POST', { + ...opts, + x: undefined, + y: undefined, + }); + await driver.execute(`mobile: ${commandName}`, opts); - proxySpy.should.have.been.calledOnceWith( - '/wda/touchAndHold', - 'POST', - { - ...opts, - x: undefined, - y: undefined, - }, - ); }); it('should proxy a touchAndHold request for an element through to WDA', async function () { const opts = {elementId: 4, duration: 100}; + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/element/4/touchAndHold', 'POST', { duration: 100, x: undefined, y: undefined }); await driver.execute(`mobile: ${commandName}`, opts); - proxySpy.should.have.been.calledOnceWith( - '/wda/element/4/touchAndHold', - 'POST', - { - ..._.omit(opts, 'elementId'), - x: undefined, - y: undefined, - } - ); }); it('should proxy a touchAndHold request for a coordinate point through to WDA', async function () { const opts = {duration: 100, x: 100, y: 100}; + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/touchAndHold', 'POST', opts); await driver.execute('mobile: touchAndHold', opts); - proxySpy.should.have.been.calledOnceWith('/wda/touchAndHold', 'POST', opts); }); }); @@ -228,14 +210,14 @@ describe('gesture commands', function () { it('should proxy a tap request for an element through to WDA', async function () { const opts = {elementId: 4, x: 100, y: 100}; + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/element/4/tap', 'POST', { x: 100, y: 100 }); await driver.execute(`mobile: ${commandName}`, opts); - proxySpy.should.have.been.calledOnceWith('/wda/element/4/tap', 'POST', _.omit(opts, 'elementId')); }); it('should proxy a tap request for a coordinate point through to WDA', async function () { const opts = {x: 100, y: 100}; + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/tap', 'POST', { x: 100, y: 100 }); await driver.execute(`mobile: ${commandName}`, opts); - proxySpy.should.have.been.calledOnceWith('/wda/tap', 'POST', opts); }); }); @@ -262,12 +244,8 @@ describe('gesture commands', function () { it('should proxy a selectPickerWheel request for an element through to WDA', async function () { const opts = {elementId: 4, order: 'next', offset: 0.3}; + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/pickerwheel/4/select', 'POST', { order: 'next', offset: 0.3 }); await driver.execute(`mobile: ${commandName}`, opts); - proxySpy.should.have.been.calledOnceWith( - '/wda/pickerwheel/4/select', - 'POST', - _.omit(opts, 'elementId'), - ); }); }); @@ -347,28 +325,28 @@ describe('gesture commands', function () { it('should proxy a dragFromToForDuration request for an element through to WDA', async function () { const opts = {element: 4, duration: 100, fromX: 1, fromY: 1, toX: 100, toY: 100}; - await driver.execute(`mobile: ${commandName}`, { - element: 4, + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/element/4/dragfromtoforduration', 'POST', { duration: 100, fromX: 1, fromY: 1, toX: 100, toY: 100, }); - proxySpy.should.have.been.calledOnceWith( - '/wda/element/4/dragfromtoforduration', - 'POST', - _.omit(opts, 'element'), - ); + await driver.execute(`mobile: ${commandName}`, opts); }); it('should proxy a dragFromToForDuration request for a coordinate point through to WDA', async function () { const opts = {duration: 100, fromX: 1, fromY: 1, toX: 100, toY: 100}; + mockDriver.expects('proxyCommand').once().withExactArgs('/wda/dragfromtoforduration', 'POST', { + duration: 100, + fromX: 1, + fromY: 1, + toX: 100, + toY: 100, + }); await driver.execute(`mobile: ${commandName}`, opts); - proxySpy.should.have.been.calledOnceWith('/wda/dragfromtoforduration', 'POST', opts); }); }); - }); }); diff --git a/test/unit/commands/pasteboard-specs.js b/test/unit/commands/pasteboard-specs.js index 44d7716a9..3092d7a46 100644 --- a/test/unit/commands/pasteboard-specs.js +++ b/test/unit/commands/pasteboard-specs.js @@ -6,11 +6,17 @@ describe('pasteboard commands', function () { const driver = new XCUITestDriver(); let isSimulatorStub, setPasteboardStub, getPasteboardStub; + let chai; + + before(async function () { + chai = await import('chai'); + chai.should(); + }); + beforeEach(function () { const simctl = new Simctl(); setPasteboardStub = sinon.stub(simctl, 'setPasteboard'); getPasteboardStub = sinon.stub(simctl, 'getPasteboard'); - // @ts-ignore driver._device = { simctl }; isSimulatorStub = sinon.stub(driver, 'isSimulator'); }); diff --git a/test/unit/commands/proxy-helper-specs.js b/test/unit/commands/proxy-helper-specs.js index 34aff6edc..c3d3fc340 100644 --- a/test/unit/commands/proxy-helper-specs.js +++ b/test/unit/commands/proxy-helper-specs.js @@ -1,52 +1,55 @@ import {errors} from 'appium/driver'; import sinon from 'sinon'; -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import XCUITestDriver from '../../../lib/driver'; -chai.should(); -chai.use(chaiAsPromised); describe('proxy commands', function () { let driver = new XCUITestDriver(); - // @ts-ignore give the driver a spy-able proxy object driver.wda = {jwproxy: {command: () => {}}}; - // @ts-ignore ok for tests - const proxyStub = sinon.stub(driver.wda.jwproxy, 'command'); + + let chai; + let mockJwproxy; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); + + beforeEach(function () { + mockJwproxy = sinon.mock(driver.wda.jwproxy); + }); afterEach(function () { - if (proxyStub) { - proxyStub.reset(); - } + mockJwproxy.verify(); }); describe('proxyCommand', function () { it('should send command through WDA', async function () { - proxyStub.returns({status: 0}); - + mockJwproxy.expects('command').once().withExactArgs( + '/some/endpoint', + 'POST', + { some: 'stuff' } + ); await driver.proxyCommand('/some/endpoint', 'POST', {some: 'stuff'}); - proxyStub.calledOnce.should.be.true; - // @ts-ignore - proxyStub.firstCall.args[0].should.eql('/some/endpoint'); - // @ts-ignore - proxyStub.firstCall.args[1].should.eql('POST'); - // @ts-ignore - proxyStub.firstCall.args[2].some.should.eql('stuff'); }); + it('should throw an error if no endpoint is given', async function () { + mockJwproxy.expects('command').never().called; // @ts-expect-error incorrect usage await driver.proxyCommand(null, 'POST', {some: 'stuff'}).should.be.rejectedWith(/endpoint/); - proxyStub.callCount.should.eql(0); }); it('should throw an error if no method is given', async function () { + mockJwproxy.expects('command').never().called; await driver // @ts-expect-error incorrect usage .proxyCommand('/some/endpoint', null, {some: 'stuff'}) .should.be.rejectedWith(/GET, POST/); - proxyStub.callCount.should.eql(0); }); it('should throw an error if wda returns an error (even if http status is 200)', async function () { - proxyStub.returns({status: 13, value: 'WDA error occurred'}); + mockJwproxy.expects('command').once().returns({status: 13, value: 'WDA error occurred'}); try { await driver.proxyCommand('/some/endpoint', 'POST', {some: 'stuff'}); } catch (err) { @@ -54,12 +57,10 @@ describe('proxy commands', function () { err.message.should.include('WDA error occurred'); err.should.be.an.instanceof(errors.UnknownError); } - proxyStub.calledOnce.should.be.true; }); it('should not throw an error if no status is returned', async function () { - proxyStub.returns({value: 'WDA error occurred'}); + mockJwproxy.expects('command').once().returns({value: 'WDA error occurred'}); await driver.proxyCommand('/some/endpoint', 'POST', {some: 'stuff'}); - proxyStub.calledOnce.should.be.true; }); }); }); diff --git a/test/unit/commands/screenshots-specs.js b/test/unit/commands/screenshots-specs.js index 2c95962ef..8b414d557 100644 --- a/test/unit/commands/screenshots-specs.js +++ b/test/unit/commands/screenshots-specs.js @@ -13,7 +13,6 @@ describe('screenshots commands', function () { beforeEach(function () { driver = new XCUITestDriver(); simctl = new Simctl(); - // @ts-ignore driver._device = { simctl }; proxyStub = sinon.stub(driver, 'proxyCommand'); }); diff --git a/test/unit/commands/session-specs.js b/test/unit/commands/session-specs.js index 7b9ceea56..3e6edd75c 100644 --- a/test/unit/commands/session-specs.js +++ b/test/unit/commands/session-specs.js @@ -1,11 +1,25 @@ import sinon from 'sinon'; import XCUITestDriver from '../../../lib/driver'; -import chai from 'chai'; - -chai.should(); describe('session commands', function () { let driver = new XCUITestDriver(); + + let chai; + let mockDriver; + + before(async function () { + chai = await import('chai'); + chai.should(); + }); + + beforeEach(function () { + mockDriver = sinon.mock(driver); + }); + + afterEach(function () { + mockDriver.verify(); + }); + driver.opts.udid = 'cecinestpasuneudid'; let proxySpy = sinon.stub(driver, 'proxyCommand').callsFake(async (endpoint, method) => { if (endpoint === '/' && method === 'GET') { diff --git a/test/unit/commands/ssl-certificate-specs.js b/test/unit/commands/ssl-certificate-specs.js index 6e397e3da..37a51e441 100644 --- a/test/unit/commands/ssl-certificate-specs.js +++ b/test/unit/commands/ssl-certificate-specs.js @@ -1,7 +1,5 @@ -import chai from 'chai'; import {parseCommonName} from '../../../lib/commands/certificate'; -chai.should(); describe('ssl certificate parser command', function () { const sslOutputLibreSSL = 'subject= /C=US/ST=California/L=San Francisco/O=BadSSL/CN=*.badssl.com'; @@ -9,6 +7,13 @@ describe('ssl certificate parser command', function () { 'subject=C = US, ST = California, L = San Francisco, O = BadSSL, CN = *.badssl.com'; const expectedString = '*.badssl.com'; + let chai; + + before(async function () { + chai = await import('chai'); + chai.should(); + }); + it('try to parse LibreSSL command output', function () { parseCommonName(sslOutputLibreSSL).should.eql(expectedString); }); diff --git a/test/unit/commands/xctest-specs.js b/test/unit/commands/xctest-specs.js index 3e7609d75..d347a64a2 100644 --- a/test/unit/commands/xctest-specs.js +++ b/test/unit/commands/xctest-specs.js @@ -1,12 +1,10 @@ -import chai from 'chai'; import {parseXCTestStdout} from '../../../lib/commands/xctest'; -chai.should(); describe('session commands', function () { const xctestLogs1Success = `XCTesterAppUITests - XCTesterAppUITests.XCTesterAppUITests/testExample | Passed: True | Crashed: False | Duration: 1.485 | Failure message: | Location :0 - XCTesterAppUITests - XCTesterAppUITests.XCTesterAppUITests/testLaunchPerformance | Passed: True | Crashed: False | Duration: 14.297 | Failure message: | Location :0 + XCTesterAppUITests - XCTesterAppUITests.XCTesterAppUITests/testLaunchPerformance | Passed: True | Crashed: False | Duration: 14.297 | Failure message: | Location :0 `.trim(); const xctestLogs2Success = ` XCTesterAppUITests - XCTesterAppUITests.XCTesterAppUITests/testExample | Status: passed | Duration: 2.2897069454193115 @@ -17,6 +15,16 @@ describe('session commands', function () { XCTesterAppUITests - XCTesterAppUITests.XCTesterAppUITests/testLaunchPerformance | Status: failed | Duration: 0.033468008041381836 | Failure message: XCTAssertTrue failed - error message here | Location /path/to/XCTesterAppUITests/XCTesterAppUITests.swift:36 `.trim(); + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); + describe('xctest', function () { it('should parse successful test logs - old version', function () { const results = parseXCTestStdout(xctestLogs1Success); diff --git a/test/unit/css-converter-specs.js b/test/unit/css-converter-specs.js index 34d400cb3..ff7555192 100644 --- a/test/unit/css-converter-specs.js +++ b/test/unit/css-converter-specs.js @@ -1,11 +1,18 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import CssConverter from '../../lib/css-converter'; -chai.should(); -chai.use(chaiAsPromised); describe('css-converter.js', function () { + + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); + describe('simple cases', function () { const simpleCases = [ ['XCUIElementTypeWindow:nth-child(2)', '**/XCUIElementTypeWindow[2]'], diff --git a/test/unit/device-connections-factory-specs.js b/test/unit/device-connections-factory-specs.js index 424e6f1c5..dffaa0f4d 100644 --- a/test/unit/device-connections-factory-specs.js +++ b/test/unit/device-connections-factory-specs.js @@ -1,13 +1,18 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import _ from 'lodash'; import {DeviceConnectionsFactory} from '../../lib/device-connections-factory'; -chai.should(); -chai.use(chaiAsPromised); describe('DeviceConnectionsFactory', function () { let devConFactory; + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); beforeEach(function () { devConFactory = new DeviceConnectionsFactory(); diff --git a/test/unit/driver-specs.js b/test/unit/driver-specs.js index 26973c18c..f8d36bacc 100644 --- a/test/unit/driver-specs.js +++ b/test/unit/driver-specs.js @@ -1,20 +1,13 @@ import xcode from 'appium-xcode'; import {JWProxy} from 'appium/driver'; -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import _ from 'lodash'; import {createSandbox} from 'sinon'; -import sinonChai from 'sinon-chai'; import cmds from '../../lib/commands'; import XCUITestDriver from '../../lib/driver'; import * as utils from '../../lib/utils'; import {MOCHA_LONG_TIMEOUT} from './helpers'; import RealDevice from '../../lib/real-device'; -chai.should(); -chai.use(sinonChai).use(chaiAsPromised); - -const expect = chai.expect; const caps = { fistMatch: [{}], @@ -27,8 +20,20 @@ const caps = { }; describe('XCUITestDriver', function () { - /** @type {sinon.SinonSandbox} */ let sandbox; + let chai; + let expect; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + + expect = chai.expect; + }); + beforeEach(function () { sandbox = createSandbox(); }); @@ -75,7 +80,6 @@ describe('XCUITestDriver', function () { // fake the proxy to WDA const jwproxy = new JWProxy(); jwproxyCommandSpy = sandbox.stub(jwproxy, 'command').resolves({some: 'thing'}); - // @ts-ignore ok for tests driver.wda = { jwproxy, }; @@ -249,7 +253,6 @@ describe('XCUITestDriver', function () { driver = new XCUITestDriver(); const jwproxy = new JWProxy(); sandbox.stub(jwproxy, 'command').resolves(deviceInfoResponse); - // @ts-ignore ok for tests driver.wda = { jwproxy, }; @@ -290,13 +293,13 @@ describe('XCUITestDriver', function () { driver.opts.device = 'some-device'; driver.lifecycleData = {createSim: false}; await driver.installOtherApps('/path/to/iosApp.app'); - expect(driver.isRealDevice).to.have.been.calledOnce; - expect(driver.helpers.configureApp).to.have.been.calledOnce; - expect(RealDeviceManagementModule.installToRealDevice).to.have.been.calledOnceWith( + (driver.isRealDevice).calledOnce.should.be.true; + (driver.helpers.configureApp).calledOnce.should.be.true; + (RealDeviceManagementModule.installToRealDevice).calledOnceWith( '/path/to/iosApp.app', 'bundle-id', {skipUninstall: true, timeout: undefined}, - ); + ).should.be.true; }); it('should install multiple apps from otherApps as JSON array on on real devices', async function () { @@ -313,18 +316,18 @@ describe('XCUITestDriver', function () { driver.opts.device = 'some-device'; driver.lifecycleData = {createSim: false}; await driver.installOtherApps('["/path/to/iosApp1.app","/path/to/iosApp2.app"]'); - expect(driver.isRealDevice).to.have.been.calledTwice; - expect(driver.helpers.configureApp).to.have.been.calledTwice; - expect(RealDeviceManagementModule.installToRealDevice).to.have.been.calledWith( + (driver.isRealDevice).calledTwice.should.be.true; + (driver.helpers.configureApp).calledTwice.should.be.true; + (RealDeviceManagementModule.installToRealDevice).calledWith( '/path/to/iosApp1.app', 'bundle-id', {skipUninstall: true, timeout: undefined}, - ); - expect(RealDeviceManagementModule.installToRealDevice).to.have.been.calledWith( + ).should.be.true; + (RealDeviceManagementModule.installToRealDevice).calledWith( '/path/to/iosApp2.app', 'bundle-id2', {skipUninstall: true, timeout: undefined}, - ); + ).should.be.true; }); it('should install multiple apps from otherApps as string on simulators', async function () { @@ -339,13 +342,13 @@ describe('XCUITestDriver', function () { driver.opts.device = 'some-device'; driver.lifecycleData = {createSim: false}; await driver.installOtherApps('/path/to/iosApp.app'); - expect(driver.isRealDevice).to.have.been.calledOnce; - expect(driver.helpers.configureApp).to.have.been.calledOnce; - expect(SimulatorManagementModule.installToSimulator).to.have.been.calledOnceWith( + (driver.isRealDevice).calledOnce.should.be.true; + (driver.helpers.configureApp).calledOnce.should.be.true; + (SimulatorManagementModule.installToSimulator).calledOnceWith( '/path/to/iosApp.app', 'bundle-id', {newSimulator: false}, - ); + ).should.be.true; }); it('should install multiple apps from otherApps as JSON array on simulators', async function () { @@ -361,18 +364,18 @@ describe('XCUITestDriver', function () { driver.opts.noReset = false; driver.lifecycleData = {createSim: false}; await driver.installOtherApps('["/path/to/iosApp1.app","/path/to/iosApp2.app"]'); - expect(driver.isRealDevice).to.have.been.calledTwice; - expect(driver.helpers.configureApp).to.have.been.calledTwice; - expect(SimulatorManagementModule.installToSimulator).to.have.been.calledWith( + (driver.isRealDevice).calledTwice.should.be.true; + (driver.helpers.configureApp).calledTwice.should.be.true; + (SimulatorManagementModule.installToSimulator).calledWith( '/path/to/iosApp1.app', 'bundle-id', {newSimulator: false}, - ); - expect(SimulatorManagementModule.installToSimulator).to.have.been.calledWith( + ).should.be.true; + (SimulatorManagementModule.installToSimulator).calledWith( '/path/to/iosApp2.app', 'bundle-id2', {newSimulator: false}, - ); + ).should.be.true; }); }); diff --git a/test/unit/language-specs.js b/test/unit/language-specs.js index d141e7b50..94e3abaa7 100644 --- a/test/unit/language-specs.js +++ b/test/unit/language-specs.js @@ -1,9 +1,7 @@ import sinon from 'sinon'; -import chai from 'chai'; import _ from 'lodash'; import XCUITestDriver from '../../lib/driver'; -chai.should(); describe('language and locale', function () { const LANGUAGE = 'en'; @@ -27,6 +25,24 @@ describe('language and locale', function () { environment: {}, }; + + let mockDriver; + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); + + afterEach(function () { + if (mockDriver) { + mockDriver.verify(); + } + }); + describe('send only language and locale', function () { it('should send translated POST /session request with valid desired caps to WDA', async function () { const expectedWDACapabilities = { @@ -59,13 +75,15 @@ describe('language and locale', function () { }); let driver = new XCUITestDriver(desiredCapabilities); - let proxySpy = sinon.stub(driver, 'proxyCommand'); + + mockDriver = sinon.mock(driver); + mockDriver.expects('proxyCommand').once().withExactArgs('/session', 'POST', expectedWDACapabilities); + driver.validateDesiredCaps(desiredCapabilities); await driver.startWdaSession( desiredCapabilities.bundleId, desiredCapabilities.processArguments, ); - proxySpy.should.have.been.calledOnceWith('/session', 'POST', expectedWDACapabilities); }); }); @@ -115,17 +133,16 @@ describe('language and locale', function () { processArguments, }); let driver = new XCUITestDriver(desiredCapabilities); - let proxySpy = sinon.stub(driver, 'proxyCommand'); + + mockDriver = sinon.mock(driver); + mockDriver.expects('proxyCommand').once().withExactArgs('/session', 'POST', expectedWDACapabilities); + driver.validateDesiredCaps(desiredCapabilities); await driver.startWdaSession( desiredCapabilities.bundleId, desiredCapabilities.processArguments, ); - proxySpy.calledOnce.should.be.true; - proxySpy.firstCall.args[0].should.eql('/session'); - proxySpy.firstCall.args[1].should.eql('POST'); desiredCapabilities.processArguments.should.eql(expectedProcessArguments); - /** @type {any} */ (proxySpy.firstCall.args[2]).should.eql(expectedWDACapabilities); }); }); }); diff --git a/test/unit/processargs-specs.js b/test/unit/processargs-specs.js index 566d6fb15..6698f19ad 100644 --- a/test/unit/processargs-specs.js +++ b/test/unit/processargs-specs.js @@ -1,14 +1,12 @@ import sinon from 'sinon'; -import chai from 'chai'; import XCUITestDriver from '../../lib/driver'; -chai.should(); describe('process args', function () { const BUNDLE_ID = 'com.test.app'; let driver = new XCUITestDriver(); driver.opts.platformVersion = '10.3'; - let proxySpy = sinon.stub(driver, 'proxyCommand'); + let mockDriver; const DEFAULT_CAPS = { elementResponseFields: undefined, disableAutomaticScreenshots: undefined, @@ -46,12 +44,28 @@ describe('process args', function () { }, }; + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); + + beforeEach(function () { + mockDriver = sinon.mock(driver); + }); + afterEach(function () { - proxySpy.reset(); + mockDriver.verify(); }); describe('send process args as object', function () { it('should send translated POST /session request with valid desired caps to WDA', async function () { + mockDriver.expects('proxyCommand').once().withExactArgs('/session', 'POST', desired); + let desiredWithProArgsObject = { platformName: 'iOS', platformVersion: '10.3', @@ -65,12 +79,13 @@ describe('process args', function () { desiredWithProArgsObject.bundleId, desiredWithProArgsObject.processArguments, ); - proxySpy.should.have.been.calledOnceWith('/session', 'POST', desired); }); }); describe('send process args json string', function () { it('should send translated POST /session request with valid desired caps to WDA', async function () { + mockDriver.expects('proxyCommand').once().withExactArgs('/session', 'POST', desired); + let desiredWithProArgsString = { platformName: 'iOS', platformVersion: '10.3', @@ -84,7 +99,6 @@ describe('process args', function () { desiredWithProArgsString.bundleId, desiredWithProArgsString.processArguments, ); - proxySpy.should.have.been.calledOnceWith('/session', 'POST', desired); }); }); }); diff --git a/test/unit/real-device-management-specs.js b/test/unit/real-device-management-specs.js index 5510b1c40..de8173fda 100644 --- a/test/unit/real-device-management-specs.js +++ b/test/unit/real-device-management-specs.js @@ -1,24 +1,26 @@ -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import {createSandbox} from 'sinon'; -import sinonChai from 'sinon-chai'; import { installToRealDevice } from '../../lib/real-device-management'; import RealDevice from '../../lib/real-device'; import XCUITestDriver from '../../lib/driver'; -chai.should(); -chai.use(sinonChai).use(chaiAsPromised); - -const expect = chai.expect; describe('installToRealDevice', function () { const udid = 'test-udid'; const app = '/path/to.app'; const bundleId = 'test.bundle.id'; - /** @type {sinon.SinonSandbox} */ let sandbox; let driver; + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); + beforeEach(function () { sandbox = createSandbox(); driver = new XCUITestDriver(); @@ -36,8 +38,8 @@ describe('installToRealDevice', function () { driver._device = realDevice; await installToRealDevice.bind(driver)(undefined, bundleId, {}); - expect(realDevice.remove).to.not.have.been.called; - expect(realDevice.install).to.not.have.been.called; + (realDevice.remove).called.should.be.false; + (realDevice.install).called.should.be.false; }); it('nothing happen without bundle id', async function () { @@ -48,8 +50,8 @@ describe('installToRealDevice', function () { driver.opts = {udid}; await installToRealDevice.bind(driver)(app, undefined, {}); - expect(realDevice.remove).to.not.have.been.called; - expect(realDevice.install).to.not.have.been.called; + (realDevice.remove).called.should.be.false; + (realDevice.install).called.should.be.false; }); it('should install without remove', async function () { @@ -64,8 +66,8 @@ describe('installToRealDevice', function () { await installToRealDevice.bind(driver)(app, bundleId, opts); - expect(realDevice.remove).to.not.have.been.called; - expect(realDevice.install).to.have.been.calledOnce; + (realDevice.remove).called.should.be.false; + (realDevice.install).calledOnce.should.be.true; }); it('should install after remove', async function () { @@ -80,8 +82,8 @@ describe('installToRealDevice', function () { await installToRealDevice.bind(driver)(app, bundleId, opts); - expect(realDevice.remove).to.have.been.calledOnce; - expect(realDevice.install).to.have.been.calledOnce; + (realDevice.remove).calledOnce.should.be.true; + (realDevice.install).calledOnce.should.be.true; }); it('should raise an error for invalid verification error after uninstall', async function () { @@ -96,8 +98,8 @@ describe('installToRealDevice', function () { driver.opts = {udid}; await installToRealDevice.bind(driver)(app, bundleId, opts).should.be.rejectedWith('ApplicationVerificationFailed'); - expect(realDevice.remove).to.have.been.calledOnce; - expect(realDevice.install).to.have.been.calledOnce; + (realDevice.remove).calledOnce.should.be.true; + (realDevice.install).calledOnce.should.be.true; }); it('should install after removal once because of MismatchedApplicationIdentifierEntitlement error', async function () { @@ -116,8 +118,8 @@ describe('installToRealDevice', function () { await installToRealDevice.bind(driver)(app, bundleId, opts); - expect(realDevice.remove).to.have.been.calledOnce; - expect(realDevice.install).to.have.been.calledTwice; + (realDevice.remove).calledOnce.should.be.true; + (realDevice.install).calledTwice.should.be.true; }); it('should raise an error in the install ApplicationVerificationFailed error because it is not recoverable', async function () { @@ -133,7 +135,7 @@ describe('installToRealDevice', function () { driver.opts = {udid}; await installToRealDevice.bind(driver)(app, bundleId, opts).should.be.rejectedWith('ApplicationVerificationFailed'); - expect(realDevice.remove).to.not.have.been.called; - expect(realDevice.install).to.have.been.calledOnce; + (realDevice.remove).called.should.be.false; + (realDevice.install).calledOnce.should.be.true; }); }); diff --git a/test/unit/simulator-management-specs.js b/test/unit/simulator-management-specs.js index 1d09816d4..a2d3dd729 100644 --- a/test/unit/simulator-management-specs.js +++ b/test/unit/simulator-management-specs.js @@ -1,10 +1,16 @@ import {runSimulatorReset} from '../../lib/simulator-management.js'; -import chai from 'chai'; import XCUITestDriver from '../../lib/driver'; -const should = chai.should(); - describe('simulator management', function () { + + let chai; + let should; + + before(async function () { + chai = await import('chai'); + should = chai.should(); + }); + describe('runSimulatorReset', function () { let result; let driver; diff --git a/test/unit/utils-specs.js b/test/unit/utils-specs.js index 48082e9fd..059c0f067 100644 --- a/test/unit/utils-specs.js +++ b/test/unit/utils-specs.js @@ -4,18 +4,25 @@ import { markSystemFilesForCleanup, isLocalHost, } from '../../lib/utils'; -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import {withMocks} from '@appium/test-support'; import {fs} from 'appium/support'; import * as iosUtils from '../../lib/utils'; -chai.should(); -chai.use(chaiAsPromised); const DERIVED_DATA_ROOT = '/path/to/DerivedData/WebDriverAgent-eoyoecqmiqfeodgstkwbxkfyagll'; describe('utils', function () { + + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); + describe( 'clearSystemFiles', withMocks({iosUtils, fs}, function (mocks) { @@ -28,13 +35,9 @@ describe('utils', function () { return DERIVED_DATA_ROOT; }, }; - // @ts-ignore withMocks is wonky mocks.fs.expects('glob').once().returns([]); - // @ts-ignore withMocks is wonky mocks.fs.expects('walkDir').once().returns(); - // @ts-ignore withMocks is wonky mocks.fs.expects('exists').atLeast(1).returns(true); - // @ts-ignore withMocks is wonky mocks.iosUtils .expects('clearLogs') .once() @@ -49,13 +52,9 @@ describe('utils', function () { return DERIVED_DATA_ROOT; }, }; - // @ts-ignore withMocks is wonky mocks.fs.expects('glob').once().returns([]); - // @ts-ignore withMocks is wonky mocks.fs.expects('walkDir').once().returns(); - // @ts-ignore withMocks is wonky mocks.fs.expects('exists').atLeast(1).returns(true); - // @ts-ignore withMocks is wonky mocks.iosUtils .expects('clearLogs') .once() @@ -72,7 +71,6 @@ describe('utils', function () { return null; }, }; - // @ts-ignore withMocks is wonky mocks.iosUtils.expects('clearLogs').never(); await clearSystemFiles(wda); }); diff --git a/tsconfig.json b/tsconfig.json index f7ccca9a9..15a8c09c7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,12 +3,11 @@ "extends": "@appium/tsconfig/tsconfig.json", "compilerOptions": { "outDir": "build", - "types": ["node", "mocha", "chai", "chai-as-promised", "sinon-chai", "sinon"], + "types": ["node", "mocha"], "checkJs": true }, "include": [ "index.js", - "lib", - "test" + "lib" ] }