Skip to content

Commit 3cdc7a2

Browse files
authored
Merge pull request #4732 from wix/update-wix-pilot
chore: update Detox Pilot version (formerly Copilot).
2 parents 3ad6fc5 + a2bbc1d commit 3cdc7a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3531
-1298
lines changed

detox/detox.d.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// * Dor Ben Baruch <https://github.com/Dor256>
1010

1111
import { BunyanDebugStreamOptions } from 'bunyan-debug-stream';
12-
import { CopilotFacade, PromptHandler } from "detox-copilot";
12+
import type { Pilot, PromptHandler as _PromptHandler } from '@wix-pilot/core'
1313

1414
declare global {
1515
namespace Detox {
@@ -446,7 +446,13 @@ declare global {
446446

447447
readonly system: SystemFacade;
448448

449-
readonly copilot: DetoxCopilotFacade;
449+
readonly pilot: PilotFacade;
450+
451+
/**
452+
* @deprecated This API is deprecated and will be removed in the next major version.
453+
* Please use `pilot` instead of `pilot`.
454+
*/
455+
readonly copilot: PilotFacade;
450456

451457
readonly DetoxConstants: {
452458
userNotificationTriggers: {
@@ -1329,17 +1335,17 @@ declare global {
13291335
element(systemMatcher: SystemMatcher): IndexableSystemElement;
13301336
}
13311337

1332-
interface DetoxCopilotFacade extends Pick<CopilotFacade, "perform"> {
1338+
interface PilotFacade extends Pick<Pilot, "perform" | "autopilot" | "extendAPICatalog"> {
13331339
/**
1334-
* Initializes the Copilot with the given prompt handler.
1335-
* Must be called before any other Copilot methods.
1336-
* @note Copilot APIs are still in experimental phase and are subject to changes in the near future.
1340+
* Initializes the Pilot with the given prompt handler.
1341+
* Must be called before any other Pilot methods.
1342+
* @note Wix-Pilot APIs are still in experimental phase and are subject to changes in the near future.
13371343
* @param promptHandler The prompt handler to use.
13381344
*/
1339-
init: (promptHandler: DetoxCopilotPromptHandler) => void;
1345+
init: (promptHandler: PromptHandler) => void;
13401346
}
13411347

1342-
interface DetoxCopilotPromptHandler extends PromptHandler {}
1348+
type PromptHandler = _PromptHandler;
13431349

13441350
interface IndexableSystemElement extends SystemElement {
13451351
/**

detox/globals.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ declare global {
1010
const web: Detox.DetoxExportWrapper['web'];
1111
const system: Detox.DetoxExportWrapper['system'];
1212
const copilot: Detox.DetoxExportWrapper['copilot'];
13+
const pilot: Detox.DetoxExportWrapper['pilot'];
1314

1415
namespace NodeJS {
1516
interface Global {
@@ -22,6 +23,7 @@ declare global {
2223
web: Detox.DetoxExportWrapper['web'];
2324
system: Detox.DetoxExportWrapper['system'];
2425
copilot: Detox.DetoxExportWrapper['copilot'];
26+
pilot: Detox.DetoxExportWrapper['pilot'];
2527
}
2628
}
2729
}

detox/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module.exports = {
7575
'src/DetoxWorker.js',
7676
'src/logger/utils/streamUtils.js',
7777
'src/realms',
78-
'src/copilot',
78+
'src/pilot',
7979
],
8080
resetMocks: true,
8181
resetModules: true,

detox/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@
6868
"wtfnode": "^0.9.1"
6969
},
7070
"dependencies": {
71+
"@wix-pilot/core": "^3.1.4",
72+
"@wix-pilot/detox": "^1.0.8",
7173
"ajv": "^8.6.3",
7274
"bunyan": "^1.8.12",
7375
"bunyan-debug-stream": "^3.1.0",
7476
"caf": "^15.0.1",
7577
"chalk": "^4.0.0",
76-
"detox-copilot": "^0.0.27",
7778
"execa": "^5.1.1",
7879
"find-up": "^5.0.0",
7980
"fs-extra": "^11.0.0",

detox/src/DetoxWorker.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
const CAF = require('caf');
2-
const copilot = require('detox-copilot').default;
32
const _ = require('lodash');
43

54
const Client = require('./client/Client');
6-
const DetoxCopilot = require('./copilot/DetoxCopilot');
75
const environmentFactory = require('./environmentFactory');
86
const { DetoxRuntimeErrorComposer } = require('./errors');
97
const { InvocationManager } = require('./invoke');
8+
const DetoxPilot = require('./pilot/DetoxPilot');
109
const symbols = require('./realms/symbols');
1110
const AsyncEmitter = require('./utils/AsyncEmitter');
1211
const uuid = require('./utils/uuid');
@@ -62,8 +61,8 @@ class DetoxWorker {
6261
this.web = null;
6362
/** @type {Detox.SystemFacade} */
6463
this.system = null;
65-
/** @type {Detox.DetoxCopilotFacade} */
66-
this.copilot = new DetoxCopilot();
64+
/** @type {Detox.PilotFacade} */
65+
this.pilot = null;
6766

6867
this._deviceCookie = null;
6968

@@ -103,14 +102,14 @@ class DetoxWorker {
103102
// @ts-ignore
104103
this._sessionConfig.sessionId = sessionConfig.sessionId || uuid.UUID();
105104
this._runtimeErrorComposer.appsConfig = this._appsConfig;
106-
107105
this._client = new Client(sessionConfig);
108106
this._client.terminateApp = async () => {
109107
// @ts-ignore
110108
if (this.device && this.device._isAppRunning()) {
111109
await this.device.terminateApp();
112110
}
113111
};
112+
this.pilot = new DetoxPilot();
114113

115114
yield this._client.connect();
116115

@@ -163,12 +162,19 @@ class DetoxWorker {
163162
const injectedGlobals = {
164163
...matchers,
165164
device: this.device,
166-
copilot: this.copilot,
165+
pilot: this.pilot,
167166
detox: this,
168167
};
169168

170169
this._injectedGlobalProperties = Object.keys(injectedGlobals);
171170
Object.assign(DetoxWorker.global, injectedGlobals);
171+
Object.defineProperty(DetoxWorker.global, 'copilot', {
172+
get: () => {
173+
console.warn('Warning: "copilot" is deprecated. Please use "pilot" instead.');
174+
return this.pilot;
175+
},
176+
configurable: true,
177+
});
172178
}
173179

174180
// @ts-ignore
@@ -226,8 +232,8 @@ class DetoxWorker {
226232
};
227233

228234
onTestStart = function* (_signal, testSummary){
229-
if (copilot.isInitialized()) {
230-
copilot.start();
235+
if (this.pilot.isInitialized()) {
236+
this.pilot.start();
231237
}
232238

233239
this._validateTestSummary('beforeEach', testSummary);
@@ -258,8 +264,8 @@ class DetoxWorker {
258264
testName: testSummary.fullName,
259265
});
260266

261-
if (copilot.isInitialized()) {
262-
copilot.end(testSummary.status !== 'passed');
267+
if (this.pilot.isInitialized()) {
268+
this.pilot.end(testSummary.status === 'passed');
263269
}
264270
};
265271

detox/src/DetoxWorker.test.js

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
// @ts-nocheck
22
const testSummaries = require('./artifacts/__mocks__/testSummaries.mock');
33
const configuration = require('./configuration');
4+
const DetoxPilot = require('./pilot/DetoxPilot');
45
const Deferred = require('./utils/Deferred');
6+
jest.mock('@wix-pilot/detox', () => ({
7+
DetoxFrameworkDriver: jest.fn(),
8+
}));
59

610
jest.mock('./utils/logger');
711
jest.mock('./client/Client');
@@ -10,16 +14,20 @@ jest.mock('./invoke');
1014
jest.mock('./utils/wrapWithStackTraceCutter');
1115
jest.mock('./environmentFactory');
1216

13-
let mockIsInitialized = false;
14-
jest.mock('detox-copilot', () => ({
15-
default: {
16-
init: jest.fn(),
17-
isInitialized: jest.fn(() => mockIsInitialized),
18-
start: jest.fn(),
19-
end: jest.fn(),
20-
perform: jest.fn(),
21-
},
22-
}));
17+
18+
jest.mock('./pilot/DetoxPilot', () => {
19+
return jest.fn().mockImplementation(() => {
20+
return {
21+
init: jest.fn(),
22+
start: jest.fn(),
23+
perform: jest.fn(),
24+
autopilot: jest.fn(),
25+
extendAPICatalog: jest.fn(),
26+
end: jest.fn(),
27+
isInitialized: jest.fn().mockReturnValue(false),
28+
};
29+
});
30+
});
2331

2432
describe('DetoxWorker', () => {
2533
const fakeCookie = {
@@ -51,7 +59,6 @@ describe('DetoxWorker', () => {
5159
let runtimeDevice;
5260
let Detox;
5361
let detox;
54-
let copilot;
5562

5663
beforeEach(() => {
5764
mockEnvironmentFactories();
@@ -67,8 +74,6 @@ describe('DetoxWorker', () => {
6774
});
6875

6976
beforeEach(async () => {
70-
mockIsInitialized = false;
71-
7277
detoxConfig = await configuration.composeDetoxConfig({
7378
override: {
7479
configurations: {
@@ -100,7 +105,6 @@ describe('DetoxWorker', () => {
100105
[symbols.deallocateDevice]: jest.fn(),
101106
};
102107

103-
copilot = require('detox-copilot').default;
104108
});
105109

106110
describe('when DetoxWorker#init() is called', () => {
@@ -307,23 +311,21 @@ describe('DetoxWorker', () => {
307311
});
308312
});
309313

310-
describe('copilot initialization', () => {
311-
let DetoxCopilot;
312-
314+
describe('pilot initialization', () => {
313315
beforeEach(async () => {
314-
DetoxCopilot = require('./copilot/DetoxCopilot');
315-
316316
await init();
317317
});
318318

319319

320-
it('should assign the DetoxCopilot instance to the copilot property', () => {
321-
expect(detox.copilot).toBeDefined();
322-
expect(detox.copilot).toBeInstanceOf(DetoxCopilot);
320+
it('should assign the DetoxPilot instance to the pilot property', () => {
321+
expect(detox.pilot).toBeDefined();
322+
323+
const detoxPilot = new DetoxPilot();
324+
expect(typeof detox.pilot).toBe(typeof detoxPilot);
323325
});
324326

325-
it('should not initialize the copilot', () => {
326-
expect(copilot.init).not.toHaveBeenCalled();
327+
it('should not initialize the pilot', () => {
328+
expect(detox.pilot.init).not.toHaveBeenCalled();
327329
});
328330
});
329331
});
@@ -349,27 +351,29 @@ describe('DetoxWorker', () => {
349351
});
350352

351353
describe('with a valid test summary', () => {
352-
beforeEach(() => detox.onTestStart(testSummaries.running()));
354+
beforeEach(() => {
355+
detox.onTestStart(testSummaries.running());
356+
});
353357

354358
it('should notify artifacts manager about "testStart', () =>
355359
expect(artifactsManager.onTestStart).toHaveBeenCalledWith(testSummaries.running()));
356360

357-
it('should not start copilot if copilot init was not called', async () => {
361+
it('should not start pilot if pilot init was not called', async () => {
358362
try {
359363
await detox.onTestStart('Test');
360364
} catch {}
361365

362-
expect(copilot.start).not.toHaveBeenCalled();
366+
expect(detox.pilot.start).not.toHaveBeenCalled();
363367
});
364368

365-
it('should start copilot if copilot init was called', async () => {
366-
mockIsInitialized = true;
369+
it('should start pilot if pilot init was called', async () => {
370+
detox.pilot.isInitialized = () => true;
367371

368372
try {
369373
await detox.onTestStart('Test');
370374
} catch {}
371375

372-
expect(copilot.start).toHaveBeenCalled();
376+
expect(detox.pilot.start).toHaveBeenCalled();
373377
});
374378

375379
it('should not relaunch app', async () => {
@@ -401,8 +405,8 @@ describe('DetoxWorker', () => {
401405
it('should notify artifacts manager about "testDone"', () =>
402406
expect(artifactsManager.onTestDone).toHaveBeenCalledWith(testSummaries.passed()));
403407

404-
it('should not end copilot if copilot init was not called', async () => {
405-
expect(copilot.end).not.toHaveBeenCalled();
408+
it('should not end pilot if pilot init was not called', async () => {
409+
expect(detox.pilot.end).not.toHaveBeenCalled();
406410
});
407411
});
408412

@@ -420,20 +424,20 @@ describe('DetoxWorker', () => {
420424
expect(client().dumpPendingRequests).toHaveBeenCalled());
421425
});
422426

423-
it('should end copilot with cache enabled if test has passed', async () => {
424-
mockIsInitialized = true;
427+
it('should end pilot with cache enabled if test has passed', async () => {
428+
detox.pilot.isInitialized = () => true;
425429

426430
await detox.onTestDone(testSummaries.passed());
427431

428-
expect(copilot.end).toHaveBeenCalledWith(false);
432+
expect(detox.pilot.end).toHaveBeenCalledWith(true);
429433
});
430434

431-
it('should end copilot without cache if test has failed', async () => {
432-
mockIsInitialized = true;
435+
it('should end pilot without cache if test has failed', async () => {
436+
detox.pilot.isInitialized = () => true;
433437

434438
await detox.onTestDone(testSummaries.failed());
435439

436-
expect(copilot.end).toHaveBeenCalledWith(true);
440+
expect(detox.pilot.end).toHaveBeenCalledWith(false);
437441
});
438442
});
439443

detox/src/copilot/DetoxCopilot.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)