chore(driver-test-support): Bump chai and chai-as-promised (#20344)

This commit is contained in:
Mykola Mokhnach
2024-07-08 22:56:16 +02:00
committed by GitHub
parent b7999aed03
commit 16015de1b5
121 changed files with 1083 additions and 3492 deletions

View File

@@ -3,7 +3,7 @@
'use strict';
module.exports = {
require: [require.resolve('./test/setup.js')],
require: ['ts-node/register'],
// forbids use of .only() in CI
forbidOnly: Boolean(process.env.CI),
color: true,

3305
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -98,9 +98,8 @@
"@typescript-eslint/eslint-plugin": "7.15.0",
"@typescript-eslint/parser": "7.15.0",
"asyncbox": "3.0.0",
"chai": "4.4.1",
"chai-as-promised": "7.1.2",
"chai-webdriverio-async": "3.0.0",
"chai": "5.1.1",
"chai-as-promised": "8.0.0",
"conventional-changelog-conventionalcommits": "7.0.2",
"cpy-cli": "5.0.0",
"eslint": "8.57.0",
@@ -120,14 +119,12 @@
"mjpeg-consumer": "2.0.0",
"mjpeg-server": "0.3.1",
"mocha": "10.6.0",
"mocha-chai-jest-snapshot": "1.1.4",
"npm-run-all2": "6.2.2",
"prettier": "3.3.2",
"rewiremock": "3.14.5",
"rimraf": "5.0.8",
"serve-static": "1.15.0",
"sinon": "18.0.0",
"sinon-chai": "3.7.0",
"sync-monorepo-packages": "1.0.2",
"through2": "4.0.2",
"ts-node": "10.9.2",

View File

@@ -10,15 +10,20 @@ import {
runAppiumRaw,
} from './e2e-helpers';
const {expect} = chai;
describe('argument parsing', function () {
/**
* @type {string}
*/
let appiumHome;
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
appiumHome = await tempDir.openDir();
});

View File

@@ -16,8 +16,6 @@ import {
import {FAKE_DRIVER_DIR, resolveFixture} from '../helpers';
import {installLocalExtension, runAppiumJson, runAppiumRaw} from './e2e-helpers';
const {expect} = chai;
const TEST_DRIVER_DIR = path.dirname(resolveFixture('test-driver/package.json'));
const TEST_DRIVER_INVALID_PEERS_DIR = path.dirname(
@@ -56,6 +54,7 @@ describe('Driver CLI', function () {
* @type {(args: string[]) => Promise<ExtRecord<DriverType>>}
*/
let runDoctor;
let expect;
async function resetAppiumHome() {
await fs.rimraf(appiumHome);
@@ -63,6 +62,12 @@ describe('Driver CLI', function () {
}
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
appiumHome = await tempDir.openDir();
const run = runAppiumJson(appiumHome);
runInstall = async (args) =>

View File

@@ -5,8 +5,6 @@ import {EXT_SUBCOMMAND_RUN as RUN, PLUGIN_TYPE} from '../../lib/constants';
import {FAKE_PLUGIN_DIR} from '../helpers';
import {installLocalExtension, runAppiumJson} from './e2e-helpers';
const {expect} = chai;
describe('Plugin CLI', function () {
/**
* @type {string}
@@ -17,8 +15,15 @@ describe('Plugin CLI', function () {
* @type {(args: string[]) => Promise<{ output: string, error?: string }>}
*/
let runRun;
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
appiumHome = await tempDir.openDir();
const run = runAppiumJson(appiumHome);
runRun = async (args) =>

View File

@@ -22,6 +22,13 @@ describe('config file behavior', function () {
const EXT_PROPS_FILEPATH = resolveConfigFixture('appium-config-ext-good.json');
const LOG_FILTERS_FILEPATH = resolveConfigFixture('appium-config-log-filters.json');
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
beforeEach(function () {
finalizeSchema();
});

View File

@@ -6,6 +6,7 @@ import * as teenProcess from 'teen_process';
describe('Config', function () {
let sandbox;
let should;
beforeEach(function () {
sandbox = createSandbox();
@@ -15,6 +16,13 @@ describe('Config', function () {
sandbox.restore();
});
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
should = chai.should();
});
describe('getGitRev', function () {
it('should get a reasonable git revision', async function () {
let rev = await getGitRev();

View File

@@ -23,8 +23,6 @@ import {
W3C_PREFIXED_CAPS,
} from '../helpers';
const should = chai.should();
/** @type {string} */
let testServerBaseUrl;
@@ -87,8 +85,14 @@ describe('FakeDriver via HTTP', function () {
/** @type {import('sinon').SinonSandbox} */
let sandbox;
let should;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
should = chai.should();
sandbox = createSandbox();
appiumHome = await tempDir.openDir();
wdOpts.port = port = await getTestPort();
@@ -637,8 +641,14 @@ describe('Bidi over SSL', function () {
let certPath = 'certificate.cert';
let keyPath = 'certificate.key';
const capabilities = {...caps, webSocketUrl: true};
let should;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
should = chai.should();
try {
await generateCertificate(certPath, keyPath);
} catch (e) {

View File

@@ -14,7 +14,6 @@ import {FAKE_DRIVER_DIR, resolveFixture} from '../helpers';
import {installLocalExtension, runAppiumJson} from './e2e-helpers';
const {MANIFEST_RELATIVE_PATH} = env;
const {expect} = chai;
const testDriverPath = path.dirname(resolveFixture('test-driver/package.json'));
describe('when Appium is a dependency of the current project', function () {
@@ -26,8 +25,15 @@ describe('when Appium is a dependency of the current project', function () {
let appiumHomePkgPath;
/** @type {string} */
let appiumHome;
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
appiumHome = await tempDir.openDir();
});

View File

@@ -10,8 +10,6 @@ import {
import {FAKE_DRIVER_DIR, resolveFixture} from '../helpers';
import {installLocalExtension, runAppiumJson} from './e2e-helpers';
const {expect} = chai;
describe('manifest handling', function () {
/**
* @type {string}
@@ -27,6 +25,7 @@ describe('manifest handling', function () {
* @type {(args?: string[]) => Promise<ExtensionListData>}
*/
let runList;
let expect;
async function resetAppiumHome() {
await fs.rimraf(appiumHome);
@@ -34,6 +33,12 @@ describe('manifest handling', function () {
}
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
appiumHome = await tempDir.openDir();
manifestPath = path.join(appiumHome, CACHE_DIR_RELATIVE_PATH, 'extensions.yaml');
const run = runAppiumJson(appiumHome);

View File

@@ -21,8 +21,6 @@ import {
const FAKE_ARGS = {sillyWebServerPort: 1234, host: 'hey'};
const FAKE_PLUGIN_ARGS = {fake: FAKE_ARGS};
const should = chai.should();
/** @type {import('webdriverio').RemoteOptions} */
const wdOpts = {
hostname: TEST_HOST,
@@ -41,8 +39,14 @@ describe('FakePlugin w/ FakeDriver via HTTP', function () {
let port;
/** @type {string} */
let testServerBaseSessionUrl;
let should;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
should = chai.should();
resetSchema();
appiumHome = await tempDir.openDir();
wdOpts.port = port = await getTestPort();

View File

@@ -5,15 +5,20 @@ import {DRIVER_TYPE} from '../../lib/constants';
import {resolveFixture} from '../helpers';
import {installLocalExtension, runAppium} from './e2e-helpers';
const {expect} = chai;
describe('CLI behavior controlled by schema', function () {
/**
* @type {string}
*/
let appiumHome;
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
appiumHome = await tempDir.openDir();
});

View File

@@ -14,8 +14,6 @@ import BasePlugin from '@appium/base-plugin';
const SESSION_ID = '1';
const {expect} = chai;
describe('AppiumDriver', function () {
/** @type {import('sinon').SinonSandbox} */
let sandbox;
@@ -25,6 +23,15 @@ describe('AppiumDriver', function () {
/** @type {MockConfig} */
let MockConfig;
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
});
beforeEach(function () {
sandbox = createSandbox();
@@ -64,10 +71,10 @@ describe('AppiumDriver', function () {
// triggers the `log` getter to set `_log`
ad.log;
// now we can stub `_log`, since it exists
sandbox.stub(ad._log, 'debug');
const debugStrub = sandbox.stub(ad._log, 'debug');
// finally, wait for `updateBuildInfo()` to finish up
await promise;
ad._log.debug.should.have.been.calledOnce;
debugStrub.calledOnce.should.be.true;
});
});
@@ -403,7 +410,7 @@ describe('AppiumDriver', function () {
[ArgsPlugin, 'args'],
]);
for (const plugin of appium.createPluginInstances()) {
chai.expect(plugin.cliArgs).to.eql({});
expect(plugin.cliArgs).to.eql({});
}
});
});

View File

@@ -17,6 +17,11 @@ describe('DriverCommand', function () {
let sandbox;
before(async function () {
const chai = await import('chai');
chai.should();
});
beforeEach(async function () {
sandbox = createSandbox();
appiumHome = await tempDir.openDir();

View File

@@ -2,8 +2,6 @@ import {createSandbox} from 'sinon';
import {finalizeSchema, resetSchema, SchemaFinalizationError} from '../../../lib/schema/schema';
import {rewiremock} from '../../helpers';
const expect = chai.expect;
describe('cli/schema-args', function () {
/** @type {import('appium/lib/schema/cli-args').toParserArgs} */
let toParserArgs;
@@ -12,6 +10,15 @@ describe('cli/schema-args', function () {
* @type {sinon.SinonSandbox}
*/
let sandbox;
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
});
beforeEach(function () {
sandbox = createSandbox();

View File

@@ -2,10 +2,17 @@ import {createSandbox} from 'sinon';
import {system} from '@appium/support';
import {getPresetDrivers} from '../../../lib/cli/setup-command';
const expect = chai.expect;
describe('SetupCommand', function () {
let sandbox;
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
});
beforeEach(function () {
sandbox = createSandbox();

View File

@@ -6,8 +6,6 @@ import YAML from 'yaml';
import * as schema from '../../lib/schema/schema';
import {resolveFixture, rewiremock} from '../helpers';
const expect = chai.expect;
describe('config-file', function () {
const GOOD_YAML_CONFIG_FILEPATH = resolveFixture('config', 'appium-config-good.yaml');
const GOOD_JSON_CONFIG_FILEPATH = resolveFixture('config', 'appium-config-good.json');
@@ -47,8 +45,15 @@ describe('config-file', function () {
let lc;
let mocks;
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
before(function () {
// generally called via the CLI parser, this needs to be done manually in tests.
// we don't need to do this before _each_ test, because we're not changing the schema.
// if we did change the schema, this would need to be in `beforeEach()` and `afterEach()`
@@ -120,19 +125,22 @@ describe('config-file', function () {
it('should support yaml', async function () {
const {config} = await readConfigFile(GOOD_YAML_CONFIG_FILEPATH);
expect(config).to.eql(normalizeConfig(GOOD_JSON_CONFIG));
expect(schema.validate).to.have.been.calledOnce;
// @ts-ignore
schema.validate.calledOnce.should.be.true;
});
it('should support json', async function () {
const {config} = await readConfigFile(GOOD_JSON_CONFIG_FILEPATH);
expect(config).to.eql(normalizeConfig(GOOD_JSON_CONFIG));
expect(schema.validate).to.have.been.calledOnce;
// @ts-ignore
schema.validate.calledOnce.should.be.true;
});
it('should support js', async function () {
const {config} = await readConfigFile(GOOD_JS_CONFIG_FILEPATH);
expect(config).to.eql(normalizeConfig(GOOD_JSON_CONFIG));
expect(schema.validate).to.have.been.calledOnce;
// @ts-ignore
schema.validate.calledOnce.should.be.true;
});
describe('when no filepath provided', function () {
@@ -141,12 +149,13 @@ describe('config-file', function () {
});
it('should search for a config file', function () {
expect(lc.search).to.have.been.calledOnce;
expect(schema.validate).to.have.been.calledOnce;
lc.search.calledOnce.should.be.true;
// @ts-ignore
schema.validate.calledOnce.should.be.true;
});
it('should not try to load a config file directly', function () {
expect(lc.load).to.not.have.been.called;
lc.load.called.should.be.false;
});
describe('when no config file is found', function () {
@@ -160,7 +169,8 @@ describe('config-file', function () {
it('should resolve with an empty object', function () {
expect(result).to.be.an('object').that.is.empty;
expect(schema.validate).not.to.have.been.called;
// @ts-ignore
schema.validate.calledOnce.should.be.false;
});
});
@@ -183,7 +193,8 @@ describe('config-file', function () {
describe('when the config file is not empty', function () {
it('should validate the config against a schema', function () {
expect(schema.validate).to.have.been.calledOnceWith(GOOD_JSON_CONFIG);
// @ts-ignore
schema.validate.calledOnceWith(GOOD_JSON_CONFIG).should.be.true;
});
describe('when the config file is valid', function () {
@@ -226,11 +237,11 @@ describe('config-file', function () {
});
it('should not attempt to find a config file', function () {
expect(lc.search).to.not.have.been.called;
lc.search.called.should.be.false;
});
it('should try to load a config file directly', function () {
expect(lc.load).to.have.been.calledOnce;
lc.load.calledOnce.should.be.true;
});
describe('when no config file exists at path', function () {
@@ -285,7 +296,8 @@ describe('config-file', function () {
describe('when the config file is not empty', function () {
it('should validate the config against a schema', function () {
expect(schema.validate).to.have.been.calledOnceWith(GOOD_JSON_CONFIG);
// @ts-ignore
schema.validate.calledOnceWith(GOOD_JSON_CONFIG).should.be.true;
});
describe('when the config file is valid', function () {
@@ -340,12 +352,12 @@ describe('config-file', function () {
it('should call `betterAjvErrors()` with option `json: opts.json`', function () {
// @ts-expect-error
formatErrors([{}], {}, {json: '{"foo": "bar"}'});
expect(mocks['@sidvind/better-ajv-errors']).to.have.been.calledWith(
mocks['@sidvind/better-ajv-errors'].calledWith(
schema.getSchema(),
{},
[{}],
{format: 'cli', json: '{"foo": "bar"}'}
);
).should.be.true;
});
});
});

View File

@@ -23,6 +23,13 @@ describe('Config', function () {
/** @type {sinon.SinonSandbox} */
let sandbox;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
beforeEach(function () {
sandbox = createSandbox();
});
@@ -45,7 +52,7 @@ describe('Config', function () {
it('should log build info to console', async function () {
const config = getBuildInfo();
await showBuildInfo();
log.should.have.been.calledOnce;
log.calledOnce.should.be.true;
log.firstCall.args.should.contain(JSON.stringify(config));
});
});
@@ -64,7 +71,7 @@ describe('Config', function () {
{port: 1234},
{allowCors: false}
);
log.should.have.been.calledWith('Appium Configuration\n');
log.calledWith('Appium Configuration\n').should.be.true;
});
it('should skip empty objects', function () {
@@ -75,7 +82,7 @@ describe('Config', function () {
{spam: 'food'},
{}
);
dir.should.have.been.calledWith({foo: 'bar', sheep: 0, ducks: false});
dir.calledWith({foo: 'bar', sheep: 0, ducks: false}).should.be.true;
});
});
@@ -88,7 +95,7 @@ describe('Config', function () {
{spam: 'food'},
{}
);
log.should.have.been.calledWith('\n(no configuration file loaded)');
log.calledWith('\n(no configuration file loaded)').should.be.true;
});
});
@@ -96,7 +103,7 @@ describe('Config', function () {
it('should not dump CLI args', function () {
// @ts-expect-error
showConfig({}, {}, {}, {});
log.should.have.been.calledWith('\n(no CLI parameters provided)');
log.calledWith('\n(no CLI parameters provided)').should.be.true;
});
});
});

View File

@@ -6,8 +6,6 @@ import {resetSchema} from '../../../lib/schema';
import {resolveFixture, rewiremock} from '../../helpers';
import {initMocks} from './mocks';
const {expect} = chai;
describe('DriverConfig', function () {
/** @type {string} */
let yamlFixture;
@@ -31,7 +29,15 @@ describe('DriverConfig', function () {
*/
let DriverConfig;
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
yamlFixture = await fs.readFile(resolveFixture('manifest', 'v3.yaml'), 'utf8');
});
@@ -338,7 +344,7 @@ describe('DriverConfig', function () {
driverConfig.readExtensionSchema(extName, extData);
// we don't have access to the schema registration cache directly, so this is as close as we can get.
expect(MockResolveFrom).to.have.been.calledOnce;
MockResolveFrom.calledOnce.should.be.true;
});
});
});

View File

@@ -5,8 +5,6 @@ import sinon from 'sinon';
import {FAKE_DRIVER_DIR} from '../../helpers';
import {Manifest} from '../../../lib/extension/manifest';
const {expect} = chai;
/**
* Relative path from actual `package.json` of `FakeDriver` for the `fake-stdin` script
*/
@@ -20,6 +18,16 @@ describe('ExtensionCommand', function () {
/** @type {sinon.SinonSandbox} */
let sandbox;
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
});
beforeEach(function () {
sandbox = sinon.createSandbox();
const driverConfig = DriverConfig.create(sandbox.createStubInstance(Manifest));

View File

@@ -4,8 +4,6 @@ import {version as APPIUM_VER} from '../../../package.json';
import {FAKE_DRIVER_DIR, PROJECT_ROOT, rewiremock} from '../../helpers';
import {initMocks} from './mocks';
const {expect} = chai;
describe('ExtensionConfig', function () {
/** @type {import('sinon').SinonSandbox} */
let sandbox;
@@ -19,6 +17,16 @@ describe('ExtensionConfig', function () {
/** @type {import('./mocks').MockAppiumSupport} */
let MockAppiumSupport;
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
});
beforeEach(function () {
let overrides;
({MockAppiumSupport, overrides, sandbox} = initMocks());
@@ -270,9 +278,9 @@ describe('ExtensionConfig', function () {
it('should display a warning count of 1', async function () {
await config._validate({foo: {}});
expect(MockAppiumSupport.logger.__logger.warn).to.be.calledWith(
MockAppiumSupport.logger.__logger.warn.calledWith(
'Appium encountered 1 warning while validating drivers found in manifest /some/path/extensions.yaml'
);
).should.be.true;
});
});
@@ -284,9 +292,9 @@ describe('ExtensionConfig', function () {
it('should display an error count of 1', async function () {
await config._validate({foo: {}});
expect(MockAppiumSupport.logger.__logger.error).to.be.calledWith(
MockAppiumSupport.logger.__logger.error.calledWith(
'Appium encountered 1 error while validating drivers found in manifest /some/path/extensions.yaml'
);
).should.be.true;
});
});
});

View File

@@ -2,9 +2,17 @@ import {Manifest} from '../../../lib/extension/manifest';
import {migrate} from '../../../lib/extension/manifest-migrations';
import {DRIVER_TYPE} from '../../../lib/constants';
const {expect} = chai;
describe('manifest-migrations', function () {
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
});
describe('when no installPath property present in manifest', function () {
it('should trigger refresh', async function () {
const manifest = Manifest.getInstance(process.cwd());

View File

@@ -7,8 +7,6 @@ import {initMocks} from './mocks';
import {version as APPIUM_VER} from '../../../package.json';
import EventEmitter from 'events';
const {expect} = chai;
describe('Manifest', function () {
/**
* @type {sinon.SinonSandbox}
@@ -27,7 +25,15 @@ describe('Manifest', function () {
/** @type {import('./mocks').MockGlob} */
let MockGlob;
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
yamlFixture = await fs.readFile(resolveFixture('manifest', 'v3.yaml'), 'utf8');
});
@@ -143,7 +149,7 @@ describe('Manifest', function () {
});
it('should create a new file', function () {
expect(MockAppiumSupport.fs.writeFile).to.be.calledOnce;
MockAppiumSupport.fs.writeFile.calledOnce.should.be.true;
});
});
@@ -179,10 +185,10 @@ describe('Manifest', function () {
await B.all([manifest.read(), manifest.read()]);
});
it('should not read the file twice', function () {
expect(MockAppiumSupport.fs.readFile).to.have.been.calledOnceWith(
MockAppiumSupport.fs.readFile.calledOnceWith(
'/some/path/extensions.yaml',
'utf8'
);
).should.be.true;
});
});
@@ -193,15 +199,16 @@ describe('Manifest', function () {
});
it('should attempt to read the file at `filepath`', function () {
expect(MockAppiumSupport.fs.readFile).to.have.been.calledOnceWith(
MockAppiumSupport.fs.readFile.calledOnceWith(
'/some/path/extensions.yaml',
'utf8'
);
).should.be.true;
});
describe('when the data has not changed', function () {
it('should not write the data', function () {
expect(manifest.write).not.to.be.called;
// @ts-ignore
manifest.write.called.should.be.false;
});
});
@@ -218,12 +225,13 @@ describe('Manifest', function () {
it('should synchronize manifest with installed extensions', async function () {
await manifest.read();
expect(manifest.syncWithInstalledExtensions).to.be.calledOnce;
// @ts-ignore
manifest.syncWithInstalledExtensions.calledOnce.should.be.true;
});
it('should check if the `package.json` has changed', async function () {
await manifest.read();
expect(MockPackageChanged.isPackageChanged).to.be.calledOnce;
MockPackageChanged.isPackageChanged.calledOnce.should.be.true;
});
});
});
@@ -258,7 +266,7 @@ describe('Manifest', function () {
describe('when called again before the first call resolves', function () {
it('should not write the file twice', async function () {
await B.all([manifest.write(), manifest.write()]);
expect(MockAppiumSupport.fs.writeFile).to.have.been.calledOnce;
MockAppiumSupport.fs.writeFile.calledOnce.should.be.true;
});
});

View File

@@ -4,8 +4,6 @@ import {PKG_HASHFILE_RELATIVE_PATH} from '../../../lib/constants';
import {rewiremock} from '../../helpers';
import {initMocks} from './mocks';
const {expect} = chai;
describe('package-changed', function () {
/** @type {typeof import('appium/lib/extension/package-changed').packageDidChange} */
let packageDidChange;
@@ -19,6 +17,16 @@ describe('package-changed', function () {
/** @type {import('./mocks').MockAppiumSupport} */
let MockAppiumSupport;
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
});
beforeEach(function () {
({MockPackageChanged, MockAppiumSupport, sandbox} = initMocks());
({packageDidChange} = rewiremock.proxy(
@@ -46,17 +54,17 @@ describe('package-changed', function () {
it('it should attempt to create the parent dir for the hash file', async function () {
await packageDidChange('/some/path');
expect(MockAppiumSupport.fs.mkdirp).to.have.been.calledWith(
MockAppiumSupport.fs.mkdirp.calledWith(
path.dirname(path.join('/some/path', PKG_HASHFILE_RELATIVE_PATH))
);
).should.be.true;
});
it('should call `package-changed` with a cwd and relative path to hash file', async function () {
await packageDidChange('/some/path');
expect(MockPackageChanged.isPackageChanged).to.have.been.calledWith({
MockPackageChanged.isPackageChanged.calledWith({
cwd: '/some/path',
hashFilename: PKG_HASHFILE_RELATIVE_PATH,
});
}).should.be.true;
});
describe('when it cannot create the parent dir', function () {
@@ -85,14 +93,14 @@ describe('package-changed', function () {
it('should not write the hash file', async function () {
await packageDidChange('/some/where');
expect(MockPackageChanged.__writeHash).not.to.have.been.called;
MockPackageChanged.__writeHash.called.should.be.false;
});
});
describe('when the package has changed per `package-changed`', function () {
it('should write the hash file', async function () {
await packageDidChange('/some/where');
expect(MockPackageChanged.__writeHash).to.have.been.calledOnce;
MockPackageChanged.__writeHash.calledOnce.should.be.true;
});
it('should resolve `true`', async function () {

View File

@@ -6,8 +6,6 @@ import {resetSchema} from '../../../lib/schema';
import {resolveFixture, rewiremock} from '../../helpers';
import {initMocks} from './mocks';
const {expect} = chai;
describe('PluginConfig', function () {
/** @type {string} */
let yamlFixture;
@@ -31,7 +29,15 @@ describe('PluginConfig', function () {
*/
let PluginConfig;
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
yamlFixture = await fs.readFile(resolveFixture('manifest', 'v3.yaml'), 'utf8');
});
@@ -337,7 +343,7 @@ describe('PluginConfig', function () {
describe('when the extension schema has not yet been registered', function () {
it('should resolve and load the extension schema file', function () {
pluginConfig.readExtensionSchema(extName, extData);
expect(MockResolveFrom).to.have.been.calledOnce;
MockResolveFrom.calledOnce.should.be.true;
});
});
});

View File

@@ -6,6 +6,13 @@ import {rewiremock} from '../helpers';
describe('grid-register', function () {
let sandbox;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
beforeEach(function () {
sandbox = createSandbox();
});
@@ -38,18 +45,18 @@ describe('grid-register', function () {
describe('when provided a path to a config file', function () {
it('should read the config file', async function () {
await registerNode('/path/to/config-file.json');
mocks['@appium/support'].fs.readFile.should.have.been.calledOnceWith(
mocks['@appium/support'].fs.readFile.calledOnceWith(
'/path/to/config-file.json',
'utf-8'
);
).should.be.true;
});
it('should parse the config file as JSON', async function () {
sandbox.spy(JSON, 'parse');
const parseSpy = sandbox.spy(JSON, 'parse');
await registerNode('/path/to/config-file.json');
JSON.parse.should.have.been.calledOnceWith(
parseSpy.calledOnceWith(
await mocks['@appium/support'].fs.readFile.firstCall.returnValue
);
).should.be.true;
});
describe('when the config file is invalid', function () {
@@ -65,13 +72,13 @@ describe('grid-register', function () {
describe('when provided a config object', function () {
it('should not attempt to read the object as a config file', async function () {
await registerNode({my: 'config'});
mocks['@appium/support'].fs.readFile.should.not.have.been.called;
mocks['@appium/support'].fs.readFile.called.should.be.false;
});
it('should not attempt to parse any JSON', async function () {
sandbox.spy(JSON, 'parse');
const parseSpy = sandbox.spy(JSON, 'parse');
await registerNode({my: 'config'});
JSON.parse.should.not.have.been.called;
parseSpy.called.should.be.false;
});
});
});

View File

@@ -11,7 +11,12 @@ describe('logging', function () {
let sandbox;
let stderrSpy;
let stdoutSpy;
beforeEach(function () {
beforeEach(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
sandbox = createSandbox();
stderrSpy = sandbox.spy(process.stderr, 'write');
stdoutSpy = sandbox.spy(process.stdout, 'write');

View File

@@ -14,6 +14,14 @@ const LOG_FILTERS_FIXTURE = resolveFixture('log-filters.json');
describe('parser', function () {
let p;
let should;
beforeEach(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
should = chai.should();
});
describe('Main Parser', function () {
beforeEach(function () {

View File

@@ -3,9 +3,15 @@
import {DRIVER_TYPE} from '../../../lib/constants';
import {ArgSpec} from '../../../lib/schema/arg-spec';
const {expect} = chai;
describe('ArgSpec', function () {
let expect;
before(async function () {
const chai = await import('chai');
chai.should();
expect = chai.expect;
});
describe('class method', function () {
describe('create()', function () {
it('should return a new ArgSpec', function () {
@@ -69,9 +75,11 @@ describe('ArgSpec', function () {
});
describe('when provided the schema ID of an extension schema', function () {
expect(ArgSpec.extensionInfoFromRootSchemaId('driver-stuff.json')).to.eql({
extType: DRIVER_TYPE,
normalizedExtName: 'stuff',
it('should return an proper object', function () {
expect(ArgSpec.extensionInfoFromRootSchemaId('driver-stuff.json')).to.eql({
extType: DRIVER_TYPE,
normalizedExtName: 'stuff',
});
});
});
});

View File

@@ -5,9 +5,17 @@ import {PLUGIN_TYPE} from '../../../lib/constants';
import {finalizeSchema, registerSchema, resetSchema} from '../../../lib/schema';
import {toParserArgs} from '../../../lib/schema/cli-args';
const {expect} = chai;
describe('cli-args', function () {
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
});
describe('toParserArgs()', function () {
/**
*

View File

@@ -10,12 +10,12 @@ import DRIVER_SCHEMA_FIXTURE from '../../fixtures/driver-schema';
import flattenedSchemaFixture from '../../fixtures/flattened-schema';
import {rewiremock} from '../../helpers';
const {expect} = chai;
describe('schema', function () {
/** @type {sinon.SinonSandbox} */
let sandbox;
let expect;
/**
* @type {import('@appium/types').Class<import('appium/lib/schema/schema').SchemaFinalizationError>}
*/
@@ -78,6 +78,14 @@ describe('schema', function () {
*/
let RoachHotelMap;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
});
beforeEach(function () {
sandbox = createSandbox();

View File

@@ -15,6 +15,15 @@ import logger from '../../lib/logger';
import {fs} from '@appium/support';
describe('utils', function () {
let should;
beforeEach(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
should = chai.should();
});
describe('parseCapsForInnerDriver()', function () {
it('should return an error if only JSONWP provided', function () {
let {error, protocol} = parseCapsForInnerDriver(BASE_CAPS);

View File

@@ -15,6 +15,13 @@ function getFixture(file) {
}
describe('app download and configuration', function () {
before(async function () {
const chai = await import('chai');
const chaisAsPromised = await import('chai-as-promised');
chai.use(chaisAsPromised.default);
chai.should();
});
describe('configureApp', function () {
it('should get the path for a local .app', async function () {
let newAppPath = await configureApp(getFixture('FakeIOSApp.app'), '.app');

View File

@@ -13,6 +13,11 @@ describe('Websockets (e2e)', function () {
const WS_DATA = 'Hello';
before(async function () {
const chai = await import('chai');
const chaisAsPromised = await import('chai-as-promised');
chai.use(chaisAsPromised.default);
chai.should();
driver = new FakeDriver();
driver.sessionId = SESSION_ID;
port = await getTestPort();

View File

@@ -21,6 +21,11 @@ describe('server', function () {
let port;
let sandbox;
before(async function () {
const chai = await import('chai');
const chaisAsPromised = await import('chai-as-promised');
chai.use(chaisAsPromised.default);
chai.should();
port = await getTestPort(true);
function configureRoutes(app) {
@@ -119,6 +124,11 @@ describe('tls server', function () {
});
before(async function () {
const chai = await import('chai');
const chaisAsPromised = await import('chai-as-promised');
chai.use(chaisAsPromised.default);
chai.should();
try {
await generateCertificate(certPath, keyPath);
} catch (e) {
@@ -167,6 +177,11 @@ describe('server plugins', function () {
let port;
before(async function () {
const chai = await import('chai');
const chaisAsPromised = await import('chai-as-promised');
chai.use(chaisAsPromised.default);
chai.should();
port = await getTestPort(true);
});

View File

@@ -4,7 +4,14 @@ import {FakeDriver} from '../protocol/fake-driver';
describe('proxy', function () {
const jwproxy = new JWProxy();
let baseServer;
let should;
before(async function () {
const chai = await import('chai');
const chaisAsPromised = await import('chai-as-promised');
chai.use(chaisAsPromised.default);
should = chai.should();
baseServer = await server({
routeConfiguringFunction: routeConfiguringFunction(new FakeDriver()),
port: 4444,

View File

@@ -12,6 +12,7 @@ let baseUrl;
describe('Protocol', function () {
let sandbox;
let should;
beforeEach(function () {
sandbox = createSandbox();
@@ -22,6 +23,11 @@ describe('Protocol', function () {
});
before(async function () {
const chai = await import('chai');
const chaisAsPromised = await import('chai-as-promised');
chai.use(chaisAsPromised.default);
should = chai.should();
port = await getTestPort();
baseUrl = `http://${TEST_HOST}:${port}`;
});

View File

@@ -14,6 +14,15 @@ import {BASE_DESIRED_CAP_CONSTRAINTS} from '@appium/types';
import {isW3cCaps} from '../../../lib/helpers/capabilities';
describe('caps', function () {
let should;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
should = chai.should();
});
// Tests based on: https://www.w3.org/TR/webdriver/#dfn-validate-caps
describe('#validateCaps', function () {
it('returns invalid argument error if "capability" is not a JSON object (1)', function () {

View File

@@ -11,12 +11,24 @@ describe('Desired Capabilities', function () {
/** @type {BaseDriver} */
let d;
let sandbox;
/** @type {import('sinon').SinonSpy} */
let logWarnSpy;
/** @type {import('sinon').SinonStub} */
let deprecatedStub;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
beforeEach(function () {
d = new BaseDriver();
sandbox = createSandbox();
sandbox.spy(d.log, 'warn');
sandbox.stub(validator.validators, 'deprecated');
logWarnSpy = sandbox.spy(d.log, 'warn');
deprecatedStub = sandbox.stub(validator.validators, 'deprecated');
});
afterEach(function () {
@@ -118,7 +130,7 @@ describe('Desired Capabilities', function () {
firstMatch: [{}],
});
d.log.warn.should.have.been.called;
logWarnSpy.called.should.be.true;
});
it('should be sensitive to the case of caps', async function () {
@@ -143,7 +155,7 @@ describe('Desired Capabilities', function () {
},
firstMatch: [{}],
});
d.log.warn.should.have.been.called;
logWarnSpy.called.should.be.true;
let sessions = await d.getSessions();
sessions[0].capabilities.noReset.should.eql(false);
@@ -158,7 +170,7 @@ describe('Desired Capabilities', function () {
},
firstMatch: [{}],
});
d.log.warn.should.have.been.called;
logWarnSpy.called.should.be.true;
let sessions = await d.getSessions();
sessions[0].capabilities.noReset.should.eql(true);
@@ -172,7 +184,7 @@ describe('Desired Capabilities', function () {
},
firstMatch: [{}],
});
d.log.warn.should.not.have.been.called;
logWarnSpy.called.should.be.false;
let sessions = await d.getSessions();
sessions[0].capabilities.language.should.eql('true');
@@ -189,7 +201,7 @@ describe('Desired Capabilities', function () {
},
firstMatch: [{}],
});
d.log.warn.should.have.been.called;
logWarnSpy.called.should.be.true;
let sessions = await d.getSessions();
sessions[0].capabilities.newCommandTimeout.should.eql(1);
@@ -204,7 +216,7 @@ describe('Desired Capabilities', function () {
},
firstMatch: [{}],
});
d.log.warn.should.have.been.called;
logWarnSpy.called.should.be.true;
let sessions = await d.getSessions();
sessions[0].capabilities.newCommandTimeout.should.eql(1.1);
@@ -218,7 +230,7 @@ describe('Desired Capabilities', function () {
},
firstMatch: [{}],
});
d.log.warn.should.not.have.been.called;
logWarnSpy.called.should.be.false;
let sessions = await d.getSessions();
sessions[0].capabilities.language.should.eql('1');
@@ -254,7 +266,7 @@ describe('Desired Capabilities', function () {
firstMatch: [{}],
});
validator.validators.deprecated.should.have.been.calledWith(5, true, 'lynx-version');
(deprecatedStub.calledWith(5, true, 'lynx-version')).should.be.true;
});
it('should not warn if deprecated=false', async function () {
@@ -274,7 +286,7 @@ describe('Desired Capabilities', function () {
firstMatch: [{}],
});
d.log.warn.should.not.have.been.called;
logWarnSpy.called.should.be.false;
});
it('should not validate against null/undefined caps', async function () {

View File

@@ -2,6 +2,13 @@ import _ from 'lodash';
import {BaseDriver} from '../../../../lib';
describe('logging custom events', function () {
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
it('should allow logging of events', async function () {
const d = new BaseDriver();
d._eventHistory.should.eql({commands: []});
@@ -19,6 +26,13 @@ describe('logging custom events', function () {
});
describe('#getLogEvents', function () {
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
it('should allow to get all events', async function () {
const d = new BaseDriver();
d._eventHistory.should.eql({commands: []});

View File

@@ -3,8 +3,6 @@ import {createSandbox} from 'sinon';
import _ from 'lodash';
import BaseDriver from '../../../../lib';
const expect = chai.expect;
const FIRST_LOGS = ['first', 'logs'];
const SECOND_LOGS = ['second', 'logs'];
const SUPPORTED_LOG_TYPES = {
@@ -20,8 +18,14 @@ const SUPPORTED_LOG_TYPES = {
describe('log commands -', function () {
let sandbox;
let driver;
let expect;
before(async function () {
const chai = await import('chai');
chai.should();
expect = chai.expect;
});
beforeEach(function () {
sandbox = createSandbox();

View File

@@ -3,10 +3,17 @@ import sinon from 'sinon';
import {DeviceSettings, MAX_SETTINGS_SIZE} from '../../../lib/basedriver/device-settings';
import {InvalidArgumentError} from '../../../lib/protocol/errors';
const {expect} = chai;
describe('DeviceSettings', function () {
let sandbox;
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
});
beforeEach(function () {
sandbox = sinon.createSandbox();
@@ -91,7 +98,7 @@ describe('DeviceSettings', function () {
it('should not call the `_onSettingsUpdate` listener', async function () {
const deviceSettings = new DeviceSettings({stuff: 'things'}, onSettingsUpdate);
await deviceSettings.update({stuff: 'things'});
expect(onSettingsUpdate).not.to.have.been.called;
onSettingsUpdate.called.should.be.false;
});
});
@@ -99,11 +106,11 @@ describe('DeviceSettings', function () {
it('should call the `_onSettingsUpdate` listener', async function () {
const deviceSettings = new DeviceSettings({}, onSettingsUpdate);
await deviceSettings.update({stuff: 'things'});
expect(onSettingsUpdate).to.have.been.calledOnceWithExactly(
onSettingsUpdate.calledOnceWithExactly(
'stuff',
'things',
undefined
);
).should.be.true;
});
});
});

View File

@@ -1,14 +1,20 @@
import BaseDriver from '../../../lib';
import {driverUnitTestSuite} from '@appium/driver-test-support';
const {expect} = chai;
driverUnitTestSuite(BaseDriver, {
platformName: 'iOS',
'appium:deviceName': 'Delorean',
});
describe('BaseDriver', function () {
let expect;
before(async function () {
const chai = await import('chai');
chai.should();
expect = chai.expect;
});
describe('constructor', function () {
it('should initialize "opts"', function () {
const driver = new BaseDriver();

View File

@@ -8,6 +8,15 @@ import {
import sinon from 'sinon';
describe('helpers', function () {
let should;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
should = chai.should();
});
describe('#isPackageOrBundle', function () {
it('should accept packages and bundles', function () {
isPackageOrBundle('io.appium.testapp').should.be.true;

View File

@@ -4,6 +4,13 @@ import BaseDriver from '../../../lib';
import {createSandbox} from 'sinon';
describe('timeout', function () {
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
let driver = new BaseDriver();
let implicitWaitSpy;
let sandbox;

View File

@@ -1,6 +1,11 @@
import {pathToRegexp} from 'path-to-regexp';
describe('middleware', function () {
before(async function () {
const chai = await import('chai');
chai.should();
});
describe('pathToRegexp', function () {
it('should match static path pattern', function () {
const pathname = '/ws/session/1234/appium/device/syslog';

View File

@@ -23,8 +23,15 @@ function fakeDriver() {
describe('server configuration', function () {
let port;
let sandbox;
let should;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
should = chai.should();
});
function fakeApp() {
const app = {

View File

@@ -6,6 +6,11 @@ import {createSandbox} from 'sinon';
describe('welcome', function () {
let sandbox;
before(async function () {
const chai = await import('chai');
chai.should();
});
beforeEach(function () {
sandbox = createSandbox();
});

View File

@@ -7,6 +7,13 @@ import ProtocolConverter, {
const {MJSONWP, W3C} = PROTOCOLS;
describe('Protocol Converter', function () {
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
describe('getTimeoutRequestObjects', function () {
let converter;
before(function () {

View File

@@ -25,6 +25,14 @@ function buildReqRes(url, method, body) {
describe('proxy', function () {
let port;
let should;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
should = chai.should();
});
function mockProxy(opts = {}) {
// sets default server/port

View File

@@ -21,6 +21,11 @@ describe('JWProxy', function () {
}
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
port = await getTestPort();
createTestURL = createAppiumURL(TEST_HOST, port);
testStatusURL = createTestURL('', 'status');

View File

@@ -2,6 +2,15 @@ import _ from 'lodash';
import {statusCodes, getSummaryByCode} from '../../../lib';
describe('jsonwp-status', function () {
let should;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
should = chai.should();
});
describe('codes', function () {
it('should export code numbers and summaries', function () {
for (let obj of _.values(statusCodes)) {

View File

@@ -227,6 +227,11 @@ let errorsList = [
];
describe('errors', function () {
before(async function () {
const chai = await import('chai');
chai.should();
});
for (let error of errorsList) {
it(error.errorName + ' should have a JSONWP code or W3C code and message', function () {
if (error.errorCode) {
@@ -247,6 +252,11 @@ describe('errors', function () {
});
});
describe('errorFromMJSONWPStatusCode', function () {
before(async function () {
const chai = await import('chai');
chai.should();
});
for (let error of errorsList) {
if (error.errorName !== 'NotYetImplementedError') {
it(error.errorCode + ' should return correct error', function () {
@@ -285,6 +295,11 @@ describe('errorFromMJSONWPStatusCode', function () {
});
});
describe('errorFromW3CJsonCode', function () {
before(async function () {
const chai = await import('chai');
chai.should();
});
for (let error of errorsList) {
if (error.errorName !== 'NotYetImplementedError') {
it(error.errorName + ' should return correct error', function () {
@@ -307,6 +322,11 @@ describe('errorFromW3CJsonCode', function () {
});
});
describe('w3c Status Codes', function () {
before(async function () {
const chai = await import('chai');
chai.should();
});
it('should match the correct error codes', function () {
let non400Errors = [
['NoSuchDriverError', 404],
@@ -341,6 +361,11 @@ describe('w3c Status Codes', function () {
});
});
describe('.getResponseForW3CError', function () {
before(async function () {
const chai = await import('chai');
chai.should();
});
it('should return an error, message and stacktrace for just a generic exception', function () {
try {
throw new Error('Some random error');
@@ -388,6 +413,11 @@ describe('.getResponseForW3CError', function () {
});
});
describe('.getActualError', function () {
before(async function () {
const chai = await import('chai');
chai.should();
});
describe('MJSONWP', function () {
it('should map a status code 7 no such element error as a NoSuchElementError', function () {
const actualError = new errors.ProxyRequestError('Error message does not matter', {

View File

@@ -7,6 +7,14 @@ import crypto from 'crypto';
describe('Protocol', function () {
// TODO test against an explicit protocol rather than a hash of a previous
// protocol
let chai;
before(async function () {
chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
describe('ensure protocol consistency', function () {
it('should not change protocol between patch versions', function () {

View File

@@ -3,6 +3,11 @@
import {validators} from '../../../lib/protocol/validators';
describe('Protocol', function () {
before(async function () {
const chai = await import('chai');
chai.should();
});
describe('direct to driver', function () {
describe('setUrl', function () {
it('should fail when no url passed', function () {

View File

@@ -1,6 +1,13 @@
import BasePlugin from '../../lib/plugin';
describe('base plugin', function () {
let should;
before(async function () {
const chai = await import('chai');
should = chai.should();
});
it('should exist', function () {
should.exist(BasePlugin);
});

View File

@@ -18,6 +18,14 @@ describe('android', function () {
const apkAnalyzerFilename = system.isWindows() ? 'apkanalyzer.bat' : 'apkanalyzer';
const gstLaunchFilename = system.isWindows() ? 'gst-launch-1.0.exe' : 'gst-launch-1.0';
const gstInspectFilename = system.isWindows() ? 'gst-inspect-1.0.exe' : 'gst-inspect-1.0';
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
describe(
'EnvVarAndPathCheck',
withMocks({fs}, (mocks) => {

View File

@@ -8,6 +8,13 @@ import {withMocks, withSandbox, stubLog} from '@appium/test-support';
import B from 'bluebird';
describe('demo', function () {
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
describe(
'DirCheck',
withMocks({fs}, (mocks) => {

View File

@@ -7,6 +7,13 @@ import B from 'bluebird';
import {removeColors} from './helper';
describe('dev', function () {
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
describe(
'BinaryIsInPathCheck',
withMocks({tp, fs}, (mocks) => {

View File

@@ -4,6 +4,13 @@ import log from '../../lib/logger';
import B from 'bluebird';
describe('doctor', function () {
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
it('register', function () {
let doctor = new Doctor();
doctor.checks.should.have.length(0);

View File

@@ -1,6 +1,11 @@
import newDoctor from '../../lib/factory';
describe('factory', function () {
before(async function () {
const chai = await import('chai');
chai.should();
});
function getTest(config) {
return function runTest() {
let doctor = newDoctor(config);

View File

@@ -12,6 +12,13 @@ import B from 'bluebird';
import {removeColors} from './helper';
describe('general', function () {
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
describe(
'NodeBinaryCheck',
withMocks({NodeDetector}, (mocks) => {

View File

@@ -1,6 +1,11 @@
import {newDoctor, Doctor, DoctorCheck} from '../../lib';
describe('index', function () {
before(async function () {
const chai = await import('chai');
chai.should();
});
it('should work', function () {
newDoctor.should.exist;
Doctor.should.exist;

View File

@@ -19,6 +19,13 @@ import {withMocks, withSandbox, stubLog} from '@appium/test-support';
import {removeColors} from './helper';
describe('ios', function () {
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
describe(
'XcodeCheck',
withMocks({tp, fs}, (mocks) => {

View File

@@ -3,11 +3,18 @@ import NodeDetector from '../../lib/node-detector';
import B from 'bluebird';
import {withSandbox} from '@appium/test-support';
let expect = chai.expect;
describe(
'NodeDetector',
withSandbox({mocks: {fs, system}}, (S) => {
let expect;
before(async function () {
const chai = await import('chai');
chai.should();
expect = chai.expect;
});
it('retrieveUsingSystemCall - success - where returns multiple lines ', async function () {
S.mocks.fs.expects('which').once().returns(B.resolve('/a/b/node.exe'));
S.mocks.fs.expects('exists').once().returns(B.resolve(true));

View File

@@ -6,6 +6,11 @@ import B from 'bluebird';
describe(
'prompt',
withMocks({utils}, (mocks) => {
before(async function () {
const chai = await import('chai');
chai.should();
});
it('fixit - yes', async function () {
clear();
mocks.utils

View File

@@ -4,6 +4,11 @@ import path from 'path';
import {Doctor} from '../../lib/doctor';
describe('utils', function () {
before(async function () {
const chai = await import('chai');
chai.should();
});
it('fs.readFile', async function () {
(await fs.readFile(path.resolve(__dirname, 'fixtures', 'wow.txt'), 'utf8')).should.include(
'WOW'

View File

@@ -2,6 +2,11 @@ import {argify} from '../../lib/util';
import _ from 'lodash';
describe('argify', function () {
before(async function () {
const chai = await import('chai');
chai.should();
});
it('should create args from params', function () {
// deploy example
const version = '2.0';

View File

@@ -3,13 +3,9 @@ import {server, routeConfiguringFunction, DeviceSettings} from 'appium/driver';
import axios from 'axios';
import B from 'bluebird';
import {TEST_HOST, getTestPort, createAppiumURL} from './helpers';
import chai from 'chai';
import sinon from 'sinon';
import {Agent} from 'node:http';
const should = chai.should();
const {expect} = chai;
/**
* Creates some helper functions for E2E tests to manage sessions.
* @template [CommandData=unknown]
@@ -129,7 +125,16 @@ export function driverE2ETestSuite(DriverClass, defaultCaps = {}) {
let getCommand;
/** @type {SessionHelpers['postCommand']} */
let postCommand;
let expect;
let should;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
expect = chai.expect;
should = chai.should();
port = port ?? (await getTestPort());
defaultCaps = {...defaultCaps};
d = new DriverClass({port, address});
@@ -143,9 +148,8 @@ export function driverE2ETestSuite(DriverClass, defaultCaps = {}) {
({startSession, getSession, endSession, newSessionURL, getCommand, postCommand} =
createSessionHelpers(port, address));
});
after(async function () {
await baseServer.close();
await baseServer?.close();
});
describe('session handling', function () {

View File

@@ -2,11 +2,6 @@ import _ from 'lodash';
import B from 'bluebird';
import {createSandbox} from 'sinon';
import chai from 'chai';
const should = chai.should();
const {expect} = chai;
// wrap these tests in a function so we can export the tests and re-use them
// for actual driver implementations
@@ -31,6 +26,16 @@ export function driverUnitTestSuite(
let w3cCaps;
/** @type {import('sinon').SinonSandbox} */
let sandbox;
let expect;
let should;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
expect = chai.expect;
should = chai.should();
});
beforeEach(function () {
sandbox = createSandbox();
@@ -45,8 +50,8 @@ export function driverUnitTestSuite(
};
});
afterEach(async function () {
sandbox.restore();
await d.deleteSession();
sandbox?.restore();
await d?.deleteSession();
});
describe('static property', function () {

View File

@@ -46,7 +46,8 @@
"@types/stoppable": "1.1.3",
"axios": "1.7.2",
"bluebird": "3.7.2",
"chai": "4.4.1",
"chai": "5.1.1",
"chai-as-promised": "8.0.0",
"get-port": "5.1.1",
"lodash": "4.17.21",
"sinon": "18.0.0",

View File

@@ -4,9 +4,17 @@ import {Agent} from 'node:http';
import {startStoppableAppium, TestAppiumServer} from '../../lib';
import getPort from 'get-port';
const {expect} = chai;
describe('startStoppableAppium()', function () {
let expect: any;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
});
it('should start an Appium server', async function () {
let server: TestAppiumServer | undefined;
try {

View File

@@ -1,15 +1,29 @@
import {TEST_HOST, getTestPort, createAppiumURL} from '../../lib';
import _ from 'lodash';
const {expect} = chai;
describe('TEST_HOST', function () {
let expect;
before(async function () {
const chai = await import('chai');
chai.should();
expect = chai.expect;
});
it('should be localhost', function () {
expect(TEST_HOST).to.equal('127.0.0.1');
});
});
describe('getTestPort()', function () {
let expect;
before(async function () {
const chai = await import('chai');
chai.should();
expect = chai.expect;
});
it('should get a free test port', async function () {
const port = await getTestPort();
expect(port).to.be.a('number');
@@ -17,6 +31,14 @@ describe('getTestPort()', function () {
});
describe('createAppiumURL()', function () {
let expect;
before(async function () {
const chai = await import('chai');
chai.should();
expect = chai.expect;
});
it('should create a "new session" URL', function () {
const actual = createAppiumURL(TEST_HOST, 31337, '', 'session');
const expected = `http://${TEST_HOST}:31337/session`;

View File

@@ -1,6 +1,13 @@
import {ExecuteDriverPlugin} from '../../lib/plugin';
describe('execute driver plugin', function () {
let should;
before(async function () {
const chai = await import('chai');
should = chai.should();
});
it('should exist', function () {
should.exist(ExecuteDriverPlugin);
});

View File

@@ -4,6 +4,10 @@ function alertTests() {
describe('alerts', function () {
let driver;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
driver = await initSession(W3C_PREFIXED_CAPS);
});
after(async function () {

View File

@@ -4,6 +4,11 @@ function contextTests() {
describe('contexts, webviews, frames', function () {
let driver;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
driver = await initSession(W3C_PREFIXED_CAPS);
});
after(async function () {

View File

@@ -22,7 +22,14 @@ driverE2ETestSuite(FakeDriver, W3C_PREFIXED_CAPS);
describe('FakeDriver - via HTTP', function () {
let server = null;
let should;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
should = chai.should();
if (shouldStartServer) {
server = await startServer(TEST_PORT, TEST_HOST);
}

View File

@@ -1,13 +1,17 @@
import chaiWebdriverIOAsync from 'chai-webdriverio-async';
import {initSession, deleteSession, W3C_PREFIXED_CAPS} from '../helpers';
function elementTests() {
describe('element interaction and introspection', function () {
let driver;
let should;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
should = chai.should();
driver = await initSession(W3C_PREFIXED_CAPS);
chai.use(chaiWebdriverIOAsync(driver));
});
after(async function () {
return await deleteSession(driver);
@@ -20,7 +24,7 @@ function elementTests() {
it('should set value on an element and retrieve text', async function () {
let el = await driver.$('//MockInputField');
await el.setValue('test value');
await el.should.have.text('test value');
(await el.getText()).should.equal('test value');
});
it('should not clear an invalid element', async function () {
await (await driver.$('//MockListItem'))
@@ -30,9 +34,9 @@ function elementTests() {
it('should clear an element', async function () {
let el = await driver.$('//MockInputField');
await el.setValue('test value');
await el.should.not.have.text('');
(await el.getText()).should.not.equal('');
await el.clearValue();
await el.should.have.text('');
(await el.getText()).should.equal('');
});
it('should not click an invisible element', async function () {
await (await driver.$('#Button1')).click().should.eventually.be.rejectedWith(/invalid state/);
@@ -51,16 +55,16 @@ function elementTests() {
(await el.getTagName()).should.equal('MockWebView');
});
it('should detect whether an element is displayed', async function () {
(await driver.$('#Button1')).should.not.be.displayed();
(await driver.$('#Button2')).should.be.displayed();
(await (await driver.$('#Button1')).isDisplayed()).should.be.false;
(await (await driver.$('#Button2')).isDisplayed()).should.be.true;
});
it('should detect whether an element is enabled', async function () {
(await driver.$('#Button1')).should.not.be.enabled();
(await driver.$('#Button2')).should.be.enabled();
(await (await driver.$('#Button1')).isEnabled()).should.be.false;
(await (await driver.$('#Button2')).isEnabled()).should.be.true;
});
it('should detect whether an element is selected', async function () {
(await driver.$('#Button1')).should.not.be.selected();
(await driver.$('#Button2')).should.be.selected();
(await (await driver.$('#Button1')).isSelected()).should.be.false;
(await (await driver.$('#Button2')).isSelected()).should.be.true;
});
it('should get the rect of an element', async function () {
let {elementId} = await driver.$('#nav');

View File

@@ -1,12 +1,18 @@
import {initSession, deleteSession, W3C_PREFIXED_CAPS} from '../helpers';
import chaiWebdriverIOAsync from 'chai-webdriverio-async';
function findElementTests() {
describe('finding elements', function () {
let driver;
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
driver = await initSession(W3C_PREFIXED_CAPS);
chai.use(chaiWebdriverIOAsync(driver));
});
after(async function () {
return await deleteSession(driver);
@@ -14,33 +20,33 @@ function findElementTests() {
describe('by XPath', function () {
it('should find a single element by xpath', async function () {
(await driver.$('//MockWebView')).should.be.existing();
(await driver.$('//MockWebView')).should.not.be.empty;
});
it('should not find a single element that is not there', async function () {
(await driver.$('//dontexist')).should.not.be.existing();
(await driver.$$('//dontexist')).length.should.equal(0);
});
it('should find multiple elements', async function () {
(await driver.$$('//MockListItem')).should.have.count(3);
(await driver.$$('//MockListItem')).length.should.be.equal(3);
});
});
describe('by classname', function () {
it('should find a single element by class', async function () {
(await driver.$('.MockWebView')).should.be.existing();
(await driver.$('.MockWebView')).should.not.be.empty;
});
it('should not find a single element by class that is not there', async function () {
(await driver.$('.dontexist')).should.not.be.existing();
(await driver.$$('.dontexist')).length.should.equal(0);;
});
});
describe('using bad selectors', function () {
it('should not find a single element with bad selector', async function () {
await chai.expect(driver.$('badsel')).to.eventually.be.rejectedWith({code: 32});
await expect(driver.$('badsel')).to.eventually.be.rejectedWith({code: 32});
});
it('should not find multiple elements with bad selector', async function () {
await chai.expect(driver.$$('badsel')).to.eventually.be.rejectedWith({code: 32});
await expect(driver.$$('badsel')).to.eventually.be.rejectedWith({code: 32});
});
});
@@ -53,19 +59,15 @@ function findElementTests() {
});
it('should find multiple elements from another element', async function () {
let el = await driver.$('html');
(await el.$$('title')).should.have.count(2);
});
it(`should not find an element that doesn't exist from another element`, async function () {
let el = await driver.$('#1');
(await el.$('marquee')).should.not.be.existing();
(await el.$$('title')).length.should.equal(2);
});
it(`should not find multiple elements that don't exist from another element`, async function () {
let el = await driver.$('#1');
(await el.$$('marquee')).should.have.count(0);
(await el.$$('marquee')).length.should.equal(0);
});
it('should not find elements if root element does not exist', async function () {
let el = await driver.$('#blub');
await chai.expect(el.$('body')).to.eventually.be.rejectedWith(/Can't call \$/);
await expect(el.$('body')).to.eventually.be.rejectedWith(/Can't call \$/);
});
});
});

View File

@@ -1,13 +1,16 @@
import chaiWebdriverIOAsync from 'chai-webdriverio-async';
import {initSession, deleteSession, W3C_PREFIXED_CAPS} from '../helpers';
function generalTests() {
describe('generic actions', function () {
let driver;
let should;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
should = chai.should();
driver = await initSession(W3C_PREFIXED_CAPS);
chai.use(chaiWebdriverIOAsync(driver));
});
after(async function () {

View File

@@ -25,6 +25,15 @@ class FakeExpress {
}
describe('fake plugin', function () {
let should;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
should = chai.should();
});
it('should exist', function () {
should.exist(FakePlugin);
});

View File

@@ -26,6 +26,14 @@ class PluginDriver extends BaseDriver {
describe('finding elements by image', function () {
let sandbox;
let should;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
should = chai.should();
});
beforeEach(function () {
sandbox = sinon.createSandbox();
@@ -158,7 +166,7 @@ describe('finding elements by image', function () {
compareStub.onFirstCall().throws(new Error('Cannot find any occurrences'));
const imgElProto = await f.findByImage(template, d, {multiple: false});
basicImgElVerify(imgElProto, f);
compareStub.should.have.been.calledTwice;
compareStub.calledTwice.should.be.true;
});
it('should not add element to cache and return it directly when checking staleness', async function () {
const imgEl = await f.findByImage(template, d, {

View File

@@ -15,6 +15,13 @@ describe('ImageElement', function () {
let sandbox;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
beforeEach(function () {
sandbox = sinon.createSandbox();
});

View File

@@ -13,6 +13,14 @@ describe('ImageElementPlugin#handle', function () {
const next = () => {};
const driver = new BaseDriver();
const p = new ImageElementPlugin();
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
describe('compareImages', function () {
this.timeout(6000);
it('should compare images via match features mode', async function () {

View File

@@ -17,6 +17,11 @@ describe('OpenCV helpers', function () {
let numberImage = null;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
const imagePath = path.resolve(FIXTURES_ROOT, 'full-image.b64');
imgFixture = Buffer.from(await fs.readFile(imagePath, 'binary'), 'base64');
fullImage = await fs.readFile(path.resolve(FIXTURES_ROOT, 'findwaldo.jpg'));

View File

@@ -1,6 +1,11 @@
import {initOpenCv} from '../../lib';
describe('OpenCV', function () {
before(async function () {
const chai = await import('chai');
chai.should();
});
it('should initialize opencv library', async function () {
this.timeout('10s');
await initOpenCv();

View File

@@ -36,6 +36,11 @@ export function pluginE2EHarness(opts) {
let server;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
const setupAppiumHome = async () => {
/**
* @type {AppiumEnv}

View File

@@ -8,7 +8,7 @@
"@appium/types": ["../types"],
"appium/support": ["../appium/support"]
},
"types": ["mocha", "chai", "sinon", "sinon-chai", "chai-as-promised"]
"types": ["mocha", "chai", "sinon", "chai-as-promised"]
},
"include": ["./lib"],
"references": [{"path": "../types"}, {"path": "../support"}]

View File

@@ -39,6 +39,12 @@ const ADJUSTED_VENDOR_CAPS = {
describe('relaxed caps plugin', function () {
let sandbox;
let should;
before(async function () {
const chai = await import('chai');
should = chai.should();
});
beforeEach(function () {
sandbox = sinon.createSandbox();

View File

@@ -1,9 +1,17 @@
import {readFile} from 'node:fs/promises';
import {Item, Strongbox, strongbox} from '../../lib';
const {expect} = chai;
describe('@appium/strongbox', function () {
let expect: any;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
});
describe('default behavior', function () {
let box: Strongbox;

View File

@@ -4,7 +4,6 @@ import {createSandbox, SinonSandbox, SinonStubbedMember} from 'sinon';
import type fs from 'node:fs/promises';
import {Item, Strongbox} from '../../lib';
const {expect} = chai;
type MockFs = {
[K in keyof typeof fs]: SinonStubbedMember<(typeof fs)[K]>;
};
@@ -15,6 +14,15 @@ describe('Strongbox', function () {
const DATA_DIR = path.resolve(path.sep, 'some', 'dir');
// note to self: looks like this is safe to do before the rewiremock.proxy call
let BaseItem: typeof import('../../lib/base-item').BaseItem;
let expect: any;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import ('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
});
beforeEach(function () {
sandbox = createSandbox();
@@ -50,7 +58,7 @@ describe('Strongbox', function () {
describe('clear()', function () {
it('should remove the item from the filesystem', async function () {
await item.clear();
expect(MockFs.unlink).to.have.been.calledWith(item.id);
MockFs.unlink.calledWith(item.id).should.be.true;
});
describe('if the item does not exist', function () {
@@ -92,11 +100,11 @@ describe('Strongbox', function () {
});
it('should write the new item value to the filesystem', async function () {
expect(MockFs.writeFile).to.have.been.calledWith(item.id, 'bar');
MockFs.writeFile.calledWith(item.id, 'bar').should.be.true;
});
it('should create the container', function () {
expect(MockFs.mkdir).to.have.been.calledWith(path.dirname(item.id), {recursive: true});
MockFs.mkdir.calledWith(path.dirname(item.id), {recursive: true}).should.be.true;
});
});
});

View File

@@ -4,7 +4,6 @@ import type {Strongbox as TStrongbox, StrongboxOpts, Item, Value} from '../../li
import {createSandbox, SinonSandbox, SinonStubbedMember} from 'sinon';
import type fs from 'node:fs/promises';
const {expect} = chai;
type MockFs = {
[K in keyof typeof fs]: SinonStubbedMember<(typeof fs)[K]>;
};
@@ -15,9 +14,16 @@ describe('Strongbox', function () {
let sandbox: SinonSandbox;
let DEFAULT_SUFFIX: string;
let MockFs: MockFs = {} as any;
let expect: any;
const DATA_DIR = path.resolve('some', 'dir', 'strongbox');
before(async function () {
const chai = await import('chai');
chai.should();
expect = chai.expect;
});
beforeEach(function () {
sandbox = createSandbox();
({strongbox, DEFAULT_SUFFIX, Strongbox} = rewiremock.proxy(
@@ -125,11 +131,11 @@ describe('Strongbox', function () {
const item = await box.createItem('test');
await item.write('boo bah');
expect(MockFs.writeFile).to.have.been.calledWith(
MockFs.writeFile.calledWith(
path.resolve(DATA_DIR, DEFAULT_SUFFIX, 'test'),
'boo bah',
'utf8'
);
).should.be.true;
});
it('should update the underlying value', async function () {
@@ -168,7 +174,7 @@ describe('Strongbox', function () {
it('should call clear() on each item', async function () {
await box.clearAll();
expect(clear).to.have.been.calledOnce;
clear.calledOnce.should.be.true;
});
describe('when there is some other error', function () {
@@ -190,10 +196,10 @@ describe('Strongbox', function () {
it('should write the value to disk', async function () {
await box.createItemWithValue('test', 'value');
expect(MockFs.writeFile).to.have.been.calledWith(
MockFs.writeFile.calledWith(
path.resolve(DATA_DIR, DEFAULT_SUFFIX, 'test'),
'value'
);
).should.be.true;
});
describe('when the third parameter is a valid encoding', function () {

View File

@@ -5,7 +5,7 @@
"outDir": "build",
"strict": true,
"checkJs": true,
"types": ["node", "mocha", "chai", "chai-as-promised", "sinon-chai"]
"types": ["node", "mocha", "chai", "chai-as-promised"]
},
"include": ["lib", "test"],
"exclude": ["**/*.test-d.ts"]

View File

@@ -10,15 +10,20 @@ import {
findAppiumDependencyPackage,
} from '../../lib/env';
const {expect} = chai;
describe('environment', function () {
/** @type {string} */
let cwd;
/** @type {string|undefined} */
let oldEnvAppiumHome;
let expect;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
expect = chai.expect;
cwd = await tempDir.openDir();
});
@@ -133,13 +138,7 @@ describe('environment', function () {
});
it('should resolve with `cwd`', async function () {
// NOTE: resolveAppiumHome() can resolve w/ a _real_ path by way of output from npm.
// on macOS, /var/whatever is really /private/var/whatever.
if (process.platform === 'darwin' && cwd.startsWith('/var/')) {
await expect(resolveAppiumHome(cwd)).to.eventually.equal(path.join('/private', cwd));
} else {
await expect(resolveAppiumHome(cwd)).to.eventually.equal(cwd);
}
await expect(resolveAppiumHome(cwd)).to.eventually.equal(cwd);
});
});
describe('when `appium` is an old version', function () {

View File

@@ -2,6 +2,13 @@ import fs from '../../lib/fs';
import {isWindows} from '../../lib/system';
describe('isExecutable()', function () {
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
describe('when the path does not exist', function () {
it('should return `false`', async function () {
await fs.isExecutable('/path/to/nowhere').should.eventually.be.false;

View File

@@ -11,6 +11,13 @@ async function getImage(name) {
}
describe('image-util', function () {
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
describe('cropBase64Image', function () {
let originalImageB64 = null;

View File

@@ -42,8 +42,14 @@ function initMJpegServer(port, intMs = 300, times = 20) {
describe('MJpeg Stream (e2e)', function () {
let mJpegServer, stream;
let serverUrl, port;
let should;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
should = chai.should();
// TODO: remove when buffertools can handle v12
if (process.version.startsWith('v12')) {
return this.skip();

View File

@@ -5,6 +5,13 @@ import {tempDir, fs} from '../../lib/index';
describe('#net', function () {
let tmpRoot;
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
beforeEach(async function () {
tmpRoot = await tempDir.openDir();
});

View File

@@ -1,9 +1,16 @@
import {node} from '../../lib';
describe('node utilities', function () {
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
chai.use(chaiAsPromised.default);
chai.should();
});
describe('requirePackage', function () {
it('should be able to require a local package', async function () {
await node.requirePackage('chai').should.not.be.rejected;
await node.requirePackage('sinon').should.not.be.rejected;
});
// XXX: see #15951
it.skip('should be able to require a global package', async function () {

Some files were not shown because too many files have changed in this diff Show More