@appium/driver-test-support 0.3.7 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/index.d.ts +1 -0
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.js +2 -0
- package/build/lib/index.js.map +1 -1
- package/build/lib/stoppable.d.ts +33 -0
- package/build/lib/stoppable.d.ts.map +1 -0
- package/build/lib/stoppable.js +38 -0
- package/build/lib/stoppable.js.map +1 -0
- package/build/test/e2e/stoppable.e2e.spec.d.ts +2 -0
- package/build/test/e2e/stoppable.e2e.spec.d.ts.map +1 -0
- package/build/test/e2e/stoppable.e2e.spec.js +42 -0
- package/build/test/e2e/stoppable.e2e.spec.js.map +1 -0
- package/build/test/unit/index.spec.d.ts +2 -0
- package/build/test/unit/index.spec.d.ts.map +1 -0
- package/build/test/unit/index.spec.js +41 -0
- package/build/test/unit/index.spec.js.map +1 -0
- package/lib/index.js +3 -0
- package/lib/stoppable.ts +57 -0
- package/package.json +7 -5
- package/tsconfig.json +1 -1
package/build/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./unit-suite";
|
|
2
2
|
export * from "./helpers";
|
|
3
|
+
export * from "./stoppable";
|
|
3
4
|
export type DriverClass = import('@appium/types').DriverClass;
|
|
4
5
|
export type BaseNSCapabilities = import('@appium/types').BaseNSCapabilities;
|
|
5
6
|
export type W3CCapabilities<C extends Readonly<Record<string, import("@appium/types").Constraint>> = typeof import("@appium/types").BASE_DESIRED_CAP_CONSTRAINTS, Extra extends void | import("@appium/types").StringRecord = void> = import('@appium/types').W3CCapabilities<C, Extra>;
|
package/build/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.js"],"names":[],"mappings":";;;0BAQa,OAAO,eAAe,EAAE,WAAW;iCACnC,OAAO,eAAe,EAAE,kBAAkB;sOAM1C,OAAO,eAAe,EAAE,eAAe,CAAC,CAAC,EAAE,KAAK,CAAC"}
|
package/build/lib/index.js
CHANGED
|
@@ -20,6 +20,8 @@ Object.defineProperty(exports, "createSessionHelpers", { enumerable: true, get:
|
|
|
20
20
|
Object.defineProperty(exports, "driverE2ETestSuite", { enumerable: true, get: function () { return e2e_suite_1.driverE2ETestSuite; } });
|
|
21
21
|
__exportStar(require("./unit-suite"), exports);
|
|
22
22
|
__exportStar(require("./helpers"), exports);
|
|
23
|
+
// eslint-disable-next-line import/no-unresolved
|
|
24
|
+
__exportStar(require("./stoppable"), exports);
|
|
23
25
|
/**
|
|
24
26
|
* @typedef {import('@appium/types').DriverClass} DriverClass
|
|
25
27
|
* @typedef {import('@appium/types').BaseNSCapabilities} BaseNSCapabilities
|
package/build/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yCAAqE;AAA7D,iHAAA,oBAAoB,OAAA;AAAE,+GAAA,kBAAkB,OAAA;AAChD,+CAA6B;AAC7B,4CAA0B;AAE1B;;;GAGG;AAEH;;;;GAIG"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yCAAqE;AAA7D,iHAAA,oBAAoB,OAAA;AAAE,+GAAA,kBAAkB,OAAA;AAChD,+CAA6B;AAC7B,4CAA0B;AAE1B,gDAAgD;AAChD,8CAA4B;AAE5B;;;GAGG;AAEH;;;;GAIG"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { AppiumServer } from '@appium/types';
|
|
3
|
+
import type { Args, CliCommandServer } from 'appium/types';
|
|
4
|
+
import type { Server } from 'node:http';
|
|
5
|
+
import stoppable from 'stoppable';
|
|
6
|
+
import type { Asyncify } from 'type-fest';
|
|
7
|
+
/**
|
|
8
|
+
* Options for {@linkcode startStoppableAppium}
|
|
9
|
+
*/
|
|
10
|
+
export type AppiumServerOpts = Args<CliCommandServer>;
|
|
11
|
+
/**
|
|
12
|
+
* An {@linkcode AppiumServer} with a method `stop() => Promise<void>`, which closes all sockets and fully stops the server.
|
|
13
|
+
*
|
|
14
|
+
* Returned by {@linkcode startStoppableAppium}
|
|
15
|
+
*/
|
|
16
|
+
export type TestAppiumServer = Omit<NormativeAppiumServer, 'close'> & {
|
|
17
|
+
stop: Asyncify<stoppable.WithStop['stop']>;
|
|
18
|
+
close: (callback: (err?: Error) => void) => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The {@linkcode AppiumServer} type, but with the `close` method normalized to a callback-style function.
|
|
22
|
+
*/
|
|
23
|
+
export type NormativeAppiumServer = Omit<AppiumServer, 'close'> & {
|
|
24
|
+
close: Server['close'];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Coerces {@linkcode AppiumServer} into a {@linkcode TestAppiumServer}.
|
|
28
|
+
* @param opts Options for {@linkcode startAppium}
|
|
29
|
+
* @todo This should be moved into `@appium/driver-test-support` or something
|
|
30
|
+
* @returns A stoppable Appium server
|
|
31
|
+
*/
|
|
32
|
+
export declare function startStoppableAppium(opts: AppiumServerOpts): Promise<TestAppiumServer>;
|
|
33
|
+
//# sourceMappingURL=stoppable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stoppable.d.ts","sourceRoot":"","sources":["../../lib/stoppable.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAEhD,OAAO,KAAK,EAAC,IAAI,EAAE,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAEzD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,WAAW,CAAC;AACtC,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,WAAW,CAAC;AAExC;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAC;AAEtD;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,qBAAqB,EAAE,OAAO,CAAC,GAAG;IACpE,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3C,KAAK,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,KAAK,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,GAAG;IAChE,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;CACxB,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAoB5F"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.startStoppableAppium = void 0;
|
|
7
|
+
const appium_1 = require("appium");
|
|
8
|
+
const bluebird_1 = __importDefault(require("bluebird"));
|
|
9
|
+
const stoppable_1 = __importDefault(require("stoppable"));
|
|
10
|
+
/**
|
|
11
|
+
* Coerces {@linkcode AppiumServer} into a {@linkcode TestAppiumServer}.
|
|
12
|
+
* @param opts Options for {@linkcode startAppium}
|
|
13
|
+
* @todo This should be moved into `@appium/driver-test-support` or something
|
|
14
|
+
* @returns A stoppable Appium server
|
|
15
|
+
*/
|
|
16
|
+
async function startStoppableAppium(opts) {
|
|
17
|
+
const appiumServer = (await (0, appium_1.main)(opts));
|
|
18
|
+
const stoppableServer = (0, stoppable_1.default)(appiumServer, 0);
|
|
19
|
+
const originalAsyncClose = appiumServer.close;
|
|
20
|
+
stoppableServer.close = async function (callback) {
|
|
21
|
+
if (callback) {
|
|
22
|
+
try {
|
|
23
|
+
await originalAsyncClose.call(this);
|
|
24
|
+
callback();
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
callback(err);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
await originalAsyncClose.call(this);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
stoppableServer.stop = bluebird_1.default.promisify(stoppableServer.stop, { context: stoppableServer });
|
|
35
|
+
return stoppableServer;
|
|
36
|
+
}
|
|
37
|
+
exports.startStoppableAppium = startStoppableAppium;
|
|
38
|
+
//# sourceMappingURL=stoppable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stoppable.js","sourceRoot":"","sources":["../../lib/stoppable.ts"],"names":[],"mappings":";;;;;;AACA,mCAA2C;AAE3C,wDAAyB;AAEzB,0DAAkC;AAyBlC;;;;;GAKG;AACI,KAAK,UAAU,oBAAoB,CAAC,IAAsB;IAC/D,MAAM,YAAY,GAAG,CAAC,MAAM,IAAA,aAAW,EAAC,IAAI,CAAC,CAAiB,CAAC;IAC/D,MAAM,eAAe,GAAG,IAAA,mBAAS,EAAC,YAAgD,EAAE,CAAC,CAAC,CAAC;IACvF,MAAM,kBAAkB,GAAG,YAAY,CAAC,KAAK,CAAC;IAC7C,eAA+C,CAAC,KAAK,GAAG,KAAK,WAC5D,QAAgC;QAEhC,IAAI,QAAQ,EAAE;YACZ,IAAI;gBACF,MAAM,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACpC,QAAQ,EAAE,CAAC;aACZ;YAAC,OAAO,GAAG,EAAE;gBACZ,QAAQ,CAAC,GAAG,CAAC,CAAC;aACf;SACF;aAAM;YACL,MAAM,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACrC;IACH,CAAC,CAAC;IACF,eAAe,CAAC,IAAI,GAAG,kBAAC,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,EAAC,OAAO,EAAE,eAAe,EAAC,CAAC,CAAC;IACrF,OAAO,eAA8C,CAAC;AACxD,CAAC;AApBD,oDAoBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stoppable.e2e.spec.d.ts","sourceRoot":"","sources":["../../../test/e2e/stoppable.e2e.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
const bluebird_1 = __importDefault(require("bluebird"));
|
|
8
|
+
const node_http_1 = require("node:http");
|
|
9
|
+
const lib_1 = require("../../lib");
|
|
10
|
+
const get_port_1 = __importDefault(require("get-port"));
|
|
11
|
+
const { expect } = chai;
|
|
12
|
+
describe('startStoppableAppium()', function () {
|
|
13
|
+
it('should start an Appium server', async function () {
|
|
14
|
+
let server;
|
|
15
|
+
try {
|
|
16
|
+
server = await (0, lib_1.startStoppableAppium)({ port: await (0, get_port_1.default)() });
|
|
17
|
+
expect(server, 'to be an object');
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
if (server) {
|
|
21
|
+
await expect(server.stop()).to.be.fulfilled;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
describe('when the server has connections', function () {
|
|
26
|
+
it('should stop the server and resolve with a boolean', async function () {
|
|
27
|
+
const port = await (0, get_port_1.default)();
|
|
28
|
+
const server = await (0, lib_1.startStoppableAppium)({ port });
|
|
29
|
+
const getConnections = bluebird_1.default.promisify(server.getConnections, { context: server });
|
|
30
|
+
await axios_1.default.get(`http://127.0.0.1:${port}/status`, {
|
|
31
|
+
httpAgent: new node_http_1.Agent({ keepAlive: true }),
|
|
32
|
+
});
|
|
33
|
+
try {
|
|
34
|
+
await expect(getConnections()).to.eventually.be.greaterThan(0);
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
await expect(server.stop()).to.eventually.be.a('boolean');
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=stoppable.e2e.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stoppable.e2e.spec.js","sourceRoot":"","sources":["../../../test/e2e/stoppable.e2e.spec.ts"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAC1B,wDAAyB;AACzB,yCAAgC;AAChC,mCAAiE;AACjE,wDAA+B;AAE/B,MAAM,EAAC,MAAM,EAAC,GAAG,IAAI,CAAC;AAEtB,QAAQ,CAAC,wBAAwB,EAAE;IACjC,EAAE,CAAC,+BAA+B,EAAE,KAAK;QACvC,IAAI,MAAoC,CAAC;QACzC,IAAI;YACF,MAAM,GAAG,MAAM,IAAA,0BAAoB,EAAC,EAAC,IAAI,EAAE,MAAM,IAAA,kBAAO,GAAE,EAAC,CAAC,CAAC;YAC7D,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;SACnC;gBAAS;YACR,IAAI,MAAM,EAAE;gBACV,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC;aAC7C;SACF;IACH,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,iCAAiC,EAAE;QAC1C,EAAE,CAAC,mDAAmD,EAAE,KAAK;YAC3D,MAAM,IAAI,GAAG,MAAM,IAAA,kBAAO,GAAE,CAAC;YAC7B,MAAM,MAAM,GAAG,MAAM,IAAA,0BAAoB,EAAC,EAAC,IAAI,EAAC,CAAC,CAAC;YAClD,MAAM,cAAc,GAAG,kBAAC,CAAC,SAAS,CAAC,MAAM,CAAC,cAAc,EAAE,EAAC,OAAO,EAAE,MAAM,EAAC,CAAC,CAAC;YAC7E,MAAM,eAAK,CAAC,GAAG,CAAC,oBAAoB,IAAI,SAAS,EAAE;gBACjD,SAAS,EAAE,IAAI,iBAAK,CAAC,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC;aACxC,CAAC,CAAC;YACH,IAAI;gBACF,MAAM,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;aAChE;oBAAS;gBACR,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;aAC3D;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.spec.d.ts","sourceRoot":"","sources":["../../../test/unit/index.spec.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const lib_1 = require("../../lib");
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const { expect } = chai;
|
|
9
|
+
describe('TEST_HOST', function () {
|
|
10
|
+
it('should be localhost', function () {
|
|
11
|
+
expect(lib_1.TEST_HOST).to.equal('127.0.0.1');
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
describe('getTestPort()', function () {
|
|
15
|
+
it('should get a free test port', async function () {
|
|
16
|
+
const port = await (0, lib_1.getTestPort)();
|
|
17
|
+
expect(port).to.be.a('number');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
describe('createAppiumURL()', function () {
|
|
21
|
+
it('should create a "new session" URL', function () {
|
|
22
|
+
const actual = (0, lib_1.createAppiumURL)(lib_1.TEST_HOST, 31337, '', 'session');
|
|
23
|
+
const expected = `http://${lib_1.TEST_HOST}:31337/session`;
|
|
24
|
+
expect(actual).to.equal(expected);
|
|
25
|
+
});
|
|
26
|
+
it('should create a URL to get an existing session', function () {
|
|
27
|
+
const sessionId = '12345';
|
|
28
|
+
const createGetSessionURL = (0, lib_1.createAppiumURL)(lib_1.TEST_HOST, 31337, lodash_1.default, 'session');
|
|
29
|
+
const actual = createGetSessionURL(sessionId);
|
|
30
|
+
const expected = `http://${lib_1.TEST_HOST}:31337/session/${sessionId}/session`;
|
|
31
|
+
expect(actual).to.equal(expected);
|
|
32
|
+
});
|
|
33
|
+
it('should create a URL for a command using an existing session', function () {
|
|
34
|
+
const sessionId = '12345';
|
|
35
|
+
const createURLWithPath = (0, lib_1.createAppiumURL)('127.0.0.1', 31337, sessionId);
|
|
36
|
+
const actual = createURLWithPath('moocow');
|
|
37
|
+
const expected = `http://${lib_1.TEST_HOST}:31337/session/${sessionId}/moocow`;
|
|
38
|
+
expect(actual).to.equal(expected);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=index.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../../../test/unit/index.spec.js"],"names":[],"mappings":";;;;;AAAA,mCAAkE;AAClE,oDAAuB;AAEvB,MAAM,EAAC,MAAM,EAAC,GAAG,IAAI,CAAC;AAEtB,QAAQ,CAAC,WAAW,EAAE;IACpB,EAAE,CAAC,qBAAqB,EAAE;QACxB,MAAM,CAAC,eAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,eAAe,EAAE;IACxB,EAAE,CAAC,6BAA6B,EAAE,KAAK;QACrC,MAAM,IAAI,GAAG,MAAM,IAAA,iBAAW,GAAE,CAAC;QACjC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,mBAAmB,EAAE;IAC5B,EAAE,CAAC,mCAAmC,EAAE;QACtC,MAAM,MAAM,GAAG,IAAA,qBAAe,EAAC,eAAS,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;QAChE,MAAM,QAAQ,GAAG,UAAU,eAAS,gBAAgB,CAAC;QACrD,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gDAAgD,EAAE;QACnD,MAAM,SAAS,GAAG,OAAO,CAAC;QAC1B,MAAM,mBAAmB,GAAG,IAAA,qBAAe,EAAC,eAAS,EAAE,KAAK,EAAE,gBAAC,EAAE,SAAS,CAAC,CAAC;QAC5E,MAAM,MAAM,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC;QAC9C,MAAM,QAAQ,GAAG,UAAU,eAAS,kBAAkB,SAAS,UAAU,CAAC;QAC1E,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE;QAChE,MAAM,SAAS,GAAG,OAAO,CAAC;QAC1B,MAAM,iBAAiB,GAAG,IAAA,qBAAe,EAAC,WAAW,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;QACzE,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAC3C,MAAM,QAAQ,GAAG,UAAU,eAAS,kBAAkB,SAAS,SAAS,CAAC;QACzE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -2,6 +2,9 @@ export {createSessionHelpers, driverE2ETestSuite} from './e2e-suite';
|
|
|
2
2
|
export * from './unit-suite';
|
|
3
3
|
export * from './helpers';
|
|
4
4
|
|
|
5
|
+
// eslint-disable-next-line import/no-unresolved
|
|
6
|
+
export * from './stoppable';
|
|
7
|
+
|
|
5
8
|
/**
|
|
6
9
|
* @typedef {import('@appium/types').DriverClass} DriverClass
|
|
7
10
|
* @typedef {import('@appium/types').BaseNSCapabilities} BaseNSCapabilities
|
package/lib/stoppable.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type {AppiumServer} from '@appium/types';
|
|
2
|
+
import {main as startAppium} from 'appium';
|
|
3
|
+
import type {Args, CliCommandServer} from 'appium/types';
|
|
4
|
+
import B from 'bluebird';
|
|
5
|
+
import type {Server} from 'node:http';
|
|
6
|
+
import stoppable from 'stoppable';
|
|
7
|
+
import type {Asyncify} from 'type-fest';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Options for {@linkcode startStoppableAppium}
|
|
11
|
+
*/
|
|
12
|
+
export type AppiumServerOpts = Args<CliCommandServer>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* An {@linkcode AppiumServer} with a method `stop() => Promise<void>`, which closes all sockets and fully stops the server.
|
|
16
|
+
*
|
|
17
|
+
* Returned by {@linkcode startStoppableAppium}
|
|
18
|
+
*/
|
|
19
|
+
export type TestAppiumServer = Omit<NormativeAppiumServer, 'close'> & {
|
|
20
|
+
stop: Asyncify<stoppable.WithStop['stop']>;
|
|
21
|
+
close: (callback: (err?: Error) => void) => Promise<void>;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The {@linkcode AppiumServer} type, but with the `close` method normalized to a callback-style function.
|
|
26
|
+
*/
|
|
27
|
+
export type NormativeAppiumServer = Omit<AppiumServer, 'close'> & {
|
|
28
|
+
close: Server['close'];
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Coerces {@linkcode AppiumServer} into a {@linkcode TestAppiumServer}.
|
|
33
|
+
* @param opts Options for {@linkcode startAppium}
|
|
34
|
+
* @todo This should be moved into `@appium/driver-test-support` or something
|
|
35
|
+
* @returns A stoppable Appium server
|
|
36
|
+
*/
|
|
37
|
+
export async function startStoppableAppium(opts: AppiumServerOpts): Promise<TestAppiumServer> {
|
|
38
|
+
const appiumServer = (await startAppium(opts)) as AppiumServer;
|
|
39
|
+
const stoppableServer = stoppable(appiumServer as unknown as NormativeAppiumServer, 0);
|
|
40
|
+
const originalAsyncClose = appiumServer.close;
|
|
41
|
+
(stoppableServer as unknown as TestAppiumServer).close = async function (
|
|
42
|
+
callback?: (err?: Error) => void
|
|
43
|
+
) {
|
|
44
|
+
if (callback) {
|
|
45
|
+
try {
|
|
46
|
+
await originalAsyncClose.call(this);
|
|
47
|
+
callback();
|
|
48
|
+
} catch (err) {
|
|
49
|
+
callback(err);
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
await originalAsyncClose.call(this);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
stoppableServer.stop = B.promisify(stoppableServer.stop, {context: stoppableServer});
|
|
56
|
+
return stoppableServer as unknown as TestAppiumServer;
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appium/driver-test-support",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Test utilities for Appium drivers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"automation",
|
|
@@ -41,16 +41,18 @@
|
|
|
41
41
|
},
|
|
42
42
|
"types": "./build/lib/index.d.ts",
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@appium/types": "^0.
|
|
44
|
+
"@appium/types": "^0.10.0",
|
|
45
45
|
"@types/lodash": "4.14.191",
|
|
46
|
-
"
|
|
46
|
+
"@types/stoppable": "1.1.1",
|
|
47
|
+
"axios": "1.3.4",
|
|
47
48
|
"bluebird": "3.7.2",
|
|
48
49
|
"chai": "4.3.7",
|
|
49
50
|
"get-port": "5.1.1",
|
|
50
51
|
"lodash": "4.17.21",
|
|
51
52
|
"sinon": "15.0.1",
|
|
52
53
|
"source-map-support": "0.5.21",
|
|
53
|
-
"
|
|
54
|
+
"stoppable": "1.1.0",
|
|
55
|
+
"type-fest": "3.6.0"
|
|
54
56
|
},
|
|
55
57
|
"peerDependencies": {
|
|
56
58
|
"appium": "^2.0.0-beta.43",
|
|
@@ -63,5 +65,5 @@
|
|
|
63
65
|
"publishConfig": {
|
|
64
66
|
"access": "public"
|
|
65
67
|
},
|
|
66
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "7b4935632222123a4fa7422461f6312f1f0dfbe4"
|
|
67
69
|
}
|