From 6738b6674900362108cf3cb9a898e294a2ffe78f Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 18 Jun 2024 19:53:56 +0200 Subject: [PATCH 1/2] chore: Bump chai and chai-as-promised --- .github/workflows/unit-test.yml | 6 +-- package.json | 8 +--- test/functional/simulator-e2e-specs.js | 61 ++++++++++++++++++++------ test/functional/utils-e2e-specs.js | 16 ++++--- test/unit/defaults-utils-specs.js | 11 +++-- test/unit/simulator-specs.js | 15 ++++--- test/unit/utils-specs.js | 25 ++++++++--- 7 files changed, 97 insertions(+), 45 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index ef98e4c..b23ecbe 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -7,11 +7,11 @@ jobs: prepare_matrix: runs-on: ubuntu-latest outputs: - versions: ${{ steps.generate-matrix.outputs.versions }} + versions: ${{ steps.generate-matrix.outputs.active }} steps: - - name: Select 3 most recent LTS versions of Node.js + - name: Select all active LTS versions of Node.js id: generate-matrix - run: echo "versions=$(curl -s https://endoflife.date/api/nodejs.json | jq -c '[[.[] | select(.lts != false)][:3] | .[].cycle | tonumber]')" >> "$GITHUB_OUTPUT" + uses: msimerson/node-lts-versions@v1 test: needs: diff --git a/package.json b/package.json index b91028e..fb9aabf 100644 --- a/package.json +++ b/package.json @@ -71,16 +71,12 @@ "@semantic-release/changelog": "^6.0.1", "@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/sinon": "^17.0.0", - "@types/sinon-chai": "^3.2.9", "@types/teen_process": "^2.0.2", - "chai": "^4.1.0", - "chai-as-promised": "^7.1.1", + "chai": "^5.1.1", + "chai-as-promised": "^8.0.0", "conventional-changelog-conventionalcommits": "^8.0.0", "mocha": "^10.0.0", "pem": "^1.8.3", diff --git a/test/functional/simulator-e2e-specs.js b/test/functional/simulator-e2e-specs.js index b67625a..56c437c 100644 --- a/test/functional/simulator-e2e-specs.js +++ b/test/functional/simulator-e2e-specs.js @@ -3,24 +3,17 @@ import _ from 'lodash'; import { killAllSimulators, MOBILE_SAFARI_BUNDLE_ID } from '../../lib/utils'; import { getSimulator } from '../../lib/simulator'; import Simctl from 'node-simctl'; -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import B from 'bluebird'; import { retryInterval, waitForCondition } from 'asyncbox'; import path from 'path'; import xcode from 'appium-xcode'; import { LONG_TIMEOUT, verifyStates } from './helpers'; - const BUNDLE_ID = 'io.appium.TestApp'; const OS_VERSION = process.env.MOBILE_OS_VERSION || '16.2'; const DEVICE_NAME = process.env.MOBILE_DEVICE_NAME || 'iPhone 14'; const CUSTOM_APP = path.resolve(__dirname, '..', 'assets', 'TestApp-iphonesimulator.app'); -chai.should(); -chai.use(chaiAsPromised); -const expect = chai.expect; - async function deleteSimulator (udid, version) { // only want to get rid of the device if it is present const simctl = new Simctl(); @@ -37,15 +30,22 @@ async function deleteSimulator (udid, version) { } } -let xcodeVersion; describe(`simulator ${OS_VERSION}`, function () { this.timeout(LONG_TIMEOUT); this.retries(2); let simctl; + let chai; + let xcodeVersion; before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + xcodeVersion = await xcode.getVersion(true); }); @@ -181,8 +181,15 @@ describe(`reuse an already-created already-run simulator ${OS_VERSION}`, functio this.retries(2); let sim; + let chai; before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + await killAllSimulators(); const udid = await new Simctl().createDevice( 'ios-simulator testing', @@ -210,9 +217,20 @@ describe(`reuse an already-created already-run simulator ${OS_VERSION}`, functio describe('advanced features', function () { let sim; + let chai; + let xcodeVersion; + this.timeout(LONG_TIMEOUT); before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + + xcodeVersion = await xcode.getVersion(true); + await killAllSimulators(); const udid = await new Simctl().createDevice( 'ios-simulator testing', @@ -353,10 +371,10 @@ describe('advanced features', function () { describe('Permission', function () { it('should set and get with simctrl privacy command', async function () { // no exceptions - await expect(sim.setPermission('com.apple.Maps', 'location', 'yes')).not.to.be.rejected; - await expect(sim.setPermission('com.apple.Maps', 'location', 'NO')).not.to.be.rejected; - await expect(sim.setPermission('com.apple.Maps', 'location', 'unset')).not.to.be.rejected; - await expect(sim.setPermission('com.apple.Maps', 'location', 'unsupported')).to.be.rejected; + await chai.expect(sim.setPermission('com.apple.Maps', 'location', 'yes')).not.to.be.rejected; + await chai.expect(sim.setPermission('com.apple.Maps', 'location', 'NO')).not.to.be.rejected; + await chai.expect(sim.setPermission('com.apple.Maps', 'location', 'unset')).not.to.be.rejected; + await chai.expect(sim.setPermission('com.apple.Maps', 'location', 'unsupported')).to.be.rejected; }); it('should set and get with wix command', async function () { @@ -379,9 +397,19 @@ describe(`multiple instances of ${OS_VERSION} simulator on Xcode9+`, function () this.retries(2); let simulatorsMapping = {}; + let chai; + let xcodeVersion; const DEVICES_COUNT = 2; before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + + xcodeVersion = await xcode.getVersion(true); + if (_.isEmpty(xcodeVersion)) { xcodeVersion = await xcode.getVersion(true); } @@ -449,8 +477,15 @@ describe(`multiple instances of ${OS_VERSION} simulator on Xcode9+`, function () describe('getWebInspectorSocket', function () { this.timeout(LONG_TIMEOUT); let sim; + let chai; before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + await killAllSimulators(); const udid = await new Simctl().createDevice( 'ios-simulator testing', @@ -469,7 +504,7 @@ describe('getWebInspectorSocket', function () { let socket = await sim.getWebInspectorSocket(); if (parseFloat(OS_VERSION) < 11.3) { - expect(socket).to.be.null; + chai.expect(socket).to.be.null; } else { socket.should.include('/private/tmp/com.apple.launchd'); socket.should.include('com.apple.webinspectord_sim.socket'); diff --git a/test/functional/utils-e2e-specs.js b/test/functional/utils-e2e-specs.js index d79e65d..11d658c 100644 --- a/test/functional/utils-e2e-specs.js +++ b/test/functional/utils-e2e-specs.js @@ -2,14 +2,8 @@ import { killAllSimulators } from '../../lib/utils'; import { getSimulator } from '../../lib/simulator'; import Simctl from 'node-simctl'; -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import { LONG_TIMEOUT, verifyStates } from './helpers'; - -chai.should(); -chai.use(chaiAsPromised); - const OS_VERSION = process.env.MOBILE_OS_VERSION || '14.0'; const DEVICE_NAME = process.env.MOBILE_DEVICE_NAME || 'iPhone 11'; @@ -17,6 +11,16 @@ describe('killAllSimulators', function () { this.timeout(LONG_TIMEOUT); let sim; + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); + beforeEach(async function () { await killAllSimulators(); let udid = await new Simctl().createDevice( diff --git a/test/unit/defaults-utils-specs.js b/test/unit/defaults-utils-specs.js index bf86912..bee4798 100644 --- a/test/unit/defaults-utils-specs.js +++ b/test/unit/defaults-utils-specs.js @@ -1,9 +1,12 @@ import { toXmlArg, generateDefaultsCommandArgs } from '../../lib/defaults-utils'; -import chai, { expect } from 'chai'; - -chai.should(); describe('defaults-utils', function () { + let chai; + + before(async function () { + chai = await import('chai'); + chai.should(); + }); describe('toXmlArg', function () { @@ -29,7 +32,7 @@ describe('defaults-utils', function () { }); it('fails to convert an unknown value type', function () { - expect(() => toXmlArg(null)).to.throw; + chai.expect(() => toXmlArg(null)).to.throw; }); }); diff --git a/test/unit/simulator-specs.js b/test/unit/simulator-specs.js index 68a9a6d..64fcf4b 100644 --- a/test/unit/simulator-specs.js +++ b/test/unit/simulator-specs.js @@ -1,8 +1,6 @@ import { getSimulator } from '../../lib/simulator'; import * as teenProcess from 'teen_process'; import * as deviceUtils from '../../lib/device-utils'; -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import sinon from 'sinon'; import { devices } from '../assets/deviceList'; import B from 'bluebird'; @@ -11,15 +9,20 @@ import { SimulatorXcode10 } from '../../lib/simulator-xcode-10'; import { SimulatorXcode11 } from '../../lib/simulator-xcode-11'; import { SimulatorXcode11_4 } from '../../lib/simulator-xcode-11.4'; - -chai.should(); -chai.use(chaiAsPromised); - const UDID = devices['10.0'][0].udid; describe('simulator', function () { let xcodeMock; let getDevicesStub; + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); beforeEach(function () { xcodeMock = sinon.mock(xcode); diff --git a/test/unit/utils-specs.js b/test/unit/utils-specs.js index 20223da..dc03c5e 100644 --- a/test/unit/utils-specs.js +++ b/test/unit/utils-specs.js @@ -1,7 +1,3 @@ -// transpile:mocha - -import chai from 'chai'; -import chaiAsPromised from 'chai-as-promised'; import sinon from 'sinon'; import B from 'bluebird'; import * as TeenProcess from 'teen_process'; @@ -14,9 +10,6 @@ import * as deviceUtils from '../../lib/device-utils'; import { devices } from '../assets/deviceList'; import { SimulatorXcode10 } from '../../lib/simulator-xcode-10'; -chai.should(); -chai.use(chaiAsPromised); - const XCODE_VERSION_10 = { versionString: '10.0', versionFloat: 10.0, @@ -44,6 +37,15 @@ describe('util', function () { let execStub; let xcodeMock; let getDevicesStub; + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); beforeEach(function () { execStub = sinon.stub(TeenProcess, 'exec'); @@ -119,6 +121,15 @@ describe('util', function () { describe('Device preferences verification', function () { const sim = new SimulatorXcode10('1234', XCODE_VERSION_10); + let chai; + + before(async function () { + chai = await import('chai'); + const chaiAsPromised = await import('chai-as-promised'); + + chai.should(); + chai.use(chaiAsPromised.default); + }); describe('for SimulatorWindowLastScale option', function () { From 88569e12f6f4fed5d7206d345090b17f76d434c8 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Tue, 18 Jun 2024 19:58:32 +0200 Subject: [PATCH 2/2] Delete extra check --- test/functional/simulator-e2e-specs.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/functional/simulator-e2e-specs.js b/test/functional/simulator-e2e-specs.js index 56c437c..2fd2656 100644 --- a/test/functional/simulator-e2e-specs.js +++ b/test/functional/simulator-e2e-specs.js @@ -409,10 +409,6 @@ describe(`multiple instances of ${OS_VERSION} simulator on Xcode9+`, function () chai.use(chaiAsPromised.default); xcodeVersion = await xcode.getVersion(true); - - if (_.isEmpty(xcodeVersion)) { - xcodeVersion = await xcode.getVersion(true); - } if (xcodeVersion.major < 9) { return this.skip(); }