-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new global lifecycle for Detox
BREAKING: update your Jest config according to the guide
- Loading branch information
Showing
69 changed files
with
699 additions
and
1,002 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
DetoxReporter: require('./reporters/DetoxReporter'), | ||
context: require('../top/context'), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
.../reporters/DetoxStreamlineJestReporter.js → .../reporters/DetoxStreamlineJestReporter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// @ts-nocheck | ||
const { URL } = require('url'); | ||
const util = require('util'); | ||
|
||
const _ = require('lodash'); | ||
|
||
const configuration = require('../../../src/configuration'); | ||
const DeviceRegistry = require('../../../src/devices/DeviceRegistry'); | ||
const GenyDeviceRegistryFactory = require('../../../src/devices/allocation/drivers/android/genycloud/GenyDeviceRegistryFactory'); | ||
const ipcServer = require('../ipc/server'); | ||
const DetoxServer = require('../../../src/server/DetoxServer'); | ||
const logger = require('../../../src/utils/logger'); | ||
const log = logger.child({ __filename }); | ||
|
||
class DetoxRootContext { | ||
constructor(config) { | ||
this._deviceConfig = config.deviceConfig; | ||
this._sessionConfig = config.sessionConfig; | ||
this._cliConfig = config.cliConfig; | ||
|
||
this._wss = null; | ||
|
||
this.setup = this.setup.bind(this); | ||
this.teardown = this.teardown.bind(this); | ||
} | ||
|
||
async setup({ argv }) { | ||
const detoxConfig = await configuration.composeDetoxConfig({ argv }); | ||
await ipcServer.start({ | ||
sessionId: `detox-${process.pid}`, | ||
detoxConfig, | ||
}); | ||
|
||
try { | ||
await this._doSetup(detoxConfig); | ||
} catch (e) { | ||
await this.teardown(); | ||
throw e; | ||
} | ||
} | ||
|
||
async teardown() { | ||
if (this._wss) { | ||
await this._wss.close(); | ||
this._wss = null; | ||
} | ||
} | ||
|
||
async _doSetup(config) { | ||
log.trace( | ||
{ event: 'DETOX_CONFIG', config }, | ||
'creating Detox server with config:\n%s', | ||
util.inspect(_.omit(config, ['errorComposer']), { | ||
getters: false, | ||
depth: Infinity, | ||
maxArrayLength: Infinity, | ||
maxStringLength: Infinity, | ||
breakLength: false, | ||
compact: false, | ||
}) | ||
); | ||
|
||
|
||
if (!this._cliConfig.keepLockFile) { | ||
await this._resetLockFile(); | ||
} | ||
|
||
const sessionConfig = this._sessionConfig; | ||
|
||
this._wss = new DetoxServer({ | ||
port: sessionConfig.server | ||
? new URL(sessionConfig.server).port | ||
: 0, | ||
standalone: false, | ||
}); | ||
|
||
await this._wss.open(); | ||
|
||
if (!sessionConfig.server) { | ||
sessionConfig.server = `ws://localhost:${this._wss.port}`; | ||
} | ||
|
||
// TODO: think if we need it to be encapsulated | ||
process.env.DETOX_WSS_ADDRESS = sessionConfig.server; | ||
} | ||
|
||
async _resetLockFile() { | ||
const deviceType = this._deviceConfig.type; | ||
|
||
switch (deviceType) { | ||
case 'ios.none': | ||
case 'ios.simulator': | ||
await DeviceRegistry.forIOS().reset(); | ||
break; | ||
case 'android.attached': | ||
case 'android.emulator': | ||
case 'android.genycloud': | ||
await DeviceRegistry.forAndroid().reset(); | ||
break; | ||
} | ||
|
||
if (deviceType === 'android.genycloud') { | ||
await GenyDeviceRegistryFactory.forGlobalShutdown().reset(); | ||
} | ||
} | ||
} | ||
|
||
module.exports = DetoxRootContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const DetoxGlobalContext = require('./DetoxGlobalContext'); | ||
|
||
module.exports = new DetoxGlobalContext(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const ipc = require('node-ipc').default; | ||
|
||
const log = require('../../../src/logger'); | ||
|
||
const state = { | ||
workers: 0, | ||
detoxConfig: null, | ||
}; | ||
|
||
module.exports = { | ||
async start({ sessionId, detoxConfig }) { | ||
state.detoxConfig = detoxConfig; | ||
|
||
debugger; | ||
ipc.config.id = process.env.DETOX_IPC_SERVER_ID = `detox-${sessionId}`; | ||
ipc.config.retry = 1500; | ||
ipc.config.sync = true; | ||
|
||
return new Promise((resolve, reject) => { | ||
ipc.serve(function() { | ||
resolve(); | ||
|
||
ipc.server.on('app.message', function(data, socket) { | ||
const { type, ...payload } = data; | ||
switch (type) { | ||
case 'log': { | ||
const { level, args } = payload; | ||
return log[level](args); | ||
} | ||
|
||
case 'registerWorker': { | ||
const { workerId } = payload; | ||
state.workers = Math.max(state.workers, +workerId); | ||
return ipc.server.emit(socket, 'app.message', { | ||
type: 'registerWorkerDone', | ||
detoxConfig: state.detoxConfig, | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
ipc.server.start(); | ||
}); | ||
}, | ||
}; |
Oops, something went wrong.