Skip to content

Commit

Permalink
chore: Bump chai and chai-as-promised (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Jun 18, 2024
1 parent 70ae5aa commit ef29844
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 48 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
63 changes: 47 additions & 16 deletions test/functional/simulator-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
});

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 () {
Expand All @@ -379,12 +397,18 @@ 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 () {
if (_.isEmpty(xcodeVersion)) {
xcodeVersion = await xcode.getVersion(true);
}
chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');

chai.should();
chai.use(chaiAsPromised.default);

xcodeVersion = await xcode.getVersion(true);
if (xcodeVersion.major < 9) {
return this.skip();
}
Expand Down Expand Up @@ -449,8 +473,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',
Expand All @@ -469,7 +500,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');
Expand Down
16 changes: 10 additions & 6 deletions test/functional/utils-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@
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';

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(
Expand Down
11 changes: 7 additions & 4 deletions test/unit/defaults-utils-specs.js
Original file line number Diff line number Diff line change
@@ -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 () {

Expand All @@ -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;
});

});
Expand Down
15 changes: 9 additions & 6 deletions test/unit/simulator-specs.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
Expand Down
25 changes: 18 additions & 7 deletions test/unit/utils-specs.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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 () {

Expand Down

0 comments on commit ef29844

Please sign in to comment.