-
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.
- Loading branch information
Showing
18 changed files
with
229 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
max_line_length = 120 | ||
tab_width = 4 | ||
trim_trailing_whitespace = true | ||
|
||
[{*.ats,*.cts,*.mts,*.ts}] | ||
indent_size = 2 | ||
tab_width = 2 | ||
|
||
[{*.cjs,*.js}] | ||
indent_size = 2 | ||
tab_width = 2 | ||
|
||
[{*.har,*.jsb2,*.jsb3,*.json,.babelrc,.eslintrc,.prettierrc,.stylelintrc,bowerrc,jest.config}] | ||
indent_size = 2 |
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 |
---|---|---|
@@ -1,7 +1,2 @@ | ||
module.exports = async function detoxGlobalTeardown() { | ||
const instance = global['detox']; | ||
|
||
if (instance) { | ||
await instance.cleanup(); | ||
} | ||
}; |
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
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
module.exports = { | ||
// ...here the new life begins... | ||
hook() { | ||
// TODO: noop | ||
|
||
}, | ||
}; |
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,66 @@ | ||
const ipc = require('node-ipc').default; | ||
|
||
const Deferred = require('../utils/Deferred'); | ||
|
||
const state = { | ||
open: false, | ||
detoxConfig: new Deferred(), | ||
}; | ||
|
||
module.exports = { | ||
async init({ | ||
serverId = process.env.DETOX_IPC_SERVER_ID, | ||
workerId = process.env.JEST_WORKER_ID, | ||
}) { | ||
return new Promise((resolve, reject) => { | ||
ipc.config.id = `${serverId}-${process.env.JEST_WORKER_ID}`; | ||
ipc.config.retry = 1000; | ||
ipc.config.sync = true; | ||
ipc.connectTo(serverId, function() { | ||
const server = state.server = ipc.of[serverId]; | ||
server.on('error', reject); | ||
server.on('connect', () => { | ||
state.open = true; | ||
|
||
server.emit('app.message', { | ||
type: 'registerWorker', | ||
workerId, | ||
}); | ||
|
||
resolve(); | ||
}); | ||
|
||
server.on('disconnect', () => { | ||
state.open = false; | ||
}); | ||
|
||
server.on('app.message', ({ type, ...payload }) => { | ||
switch (type) { | ||
case 'registerWorkerDone': { | ||
const { detoxConfig } = payload; | ||
state.detoxConfig.resolve(detoxConfig); | ||
break; | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
}, | ||
|
||
async getDetoxConfig() { | ||
return state.detoxConfig.promise; | ||
}, | ||
|
||
log(level, meta, ...args) { | ||
if (state.open) { | ||
state.server.emit('app.message', { | ||
type: 'log', | ||
level, | ||
meta, | ||
args, | ||
}); | ||
} else { | ||
console.error('Whoops...', level, meta, ...args); | ||
} | ||
}, | ||
}; |
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('../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(); | ||
}); | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1 +1,51 @@ | ||
module.exports = require('./NullLogger'); | ||
const _ = require('lodash'); | ||
const ipcClient = require('../ipc/client'); | ||
|
||
class IPCLogger { | ||
constructor(config) { | ||
this._config = config; | ||
this._config.level = 'info'; | ||
ipcClient.getDetoxConfig().then(config => { | ||
if (config.cliConfig.loglevel) { | ||
this._config.level = config.cliConfig.loglevel; | ||
} | ||
}); | ||
|
||
} | ||
|
||
child(context) { | ||
return new IPCLogger(_.merge({}, this._config, { context })); | ||
} | ||
|
||
error() { | ||
return this._send('error', [...arguments]); | ||
} | ||
|
||
warn() { | ||
return this._send('warn', [...arguments]); | ||
} | ||
|
||
info() { | ||
return this._send('info', [...arguments]); | ||
} | ||
|
||
debug() { | ||
return this._send('debug', [...arguments]); | ||
} | ||
|
||
trace() { | ||
return this._send('trace', [...arguments]); | ||
} | ||
|
||
_send(level, args) { | ||
const hasContext = _.isObject(arguments[0]); | ||
const meta = _.defaults({}, this._config.context, hasContext ? arguments[0] : undefined); | ||
ipcClient.log(level, meta, hasContext ? args.slice(1) : args); | ||
} | ||
|
||
get level() { | ||
return this._config.level; // ? | ||
} | ||
} | ||
|
||
module.exports = IPCLogger; |
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 |
---|---|---|
@@ -1,10 +1,15 @@ | ||
function resolveLoggerClass() { | ||
switch (process.env.DETOX_LOGGER_IMPL) { | ||
case 'bunyan': return require('./BunyanLogger'); | ||
case 'ipc': return require('./IPCLogger'); | ||
default: return require('./NullLogger'); | ||
if (global.IS_RUNNING_DETOX_UNIT_TESTS) { | ||
// TODO: return NullLogger maybe? | ||
return require('./BunyanLogger'); | ||
} | ||
|
||
if (process.env.JEST_WORKER_ID) { | ||
return require('./IPCLogger'); | ||
} else { | ||
return require('./BunyanLogger'); | ||
} | ||
} | ||
|
||
const Logger = resolveLoggerClass(); | ||
module.exports = new Logger(); | ||
module.exports = new Logger({}); |
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 |
---|---|---|
@@ -1,6 +1 @@ | ||
async function globalSetup() { | ||
const detox = require('detox'); | ||
await detox.globalInit(); | ||
} | ||
|
||
module.exports = globalSetup; | ||
module.exports = require('detox/runners/jest/globalSetup') |
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 |
---|---|---|
@@ -1,7 +1 @@ | ||
const detox = require('detox'); | ||
|
||
async function globalTeardown() { | ||
await detox.globalCleanup(); | ||
} | ||
|
||
module.exports = globalTeardown; | ||
module.exports = require('detox/runners/jest/globalTeardown') |