Skip to content

Commit

Permalink
feat: detox.init() will be always logging inner errors near the actua…
Browse files Browse the repository at this point in the history
…l place they happened, cleanup and disable other methods: beforeEach, afterEach, cleanup (#840)
  • Loading branch information
noomorph authored and rotemmiz committed Jul 19, 2018
1 parent de5cc9a commit 0d4ae31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
17 changes: 12 additions & 5 deletions detox/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const DetoxConstants = require('./DetoxConstants');
const platform = require('./platform');
const exportWrapper = require('./exportWrapper');
const argparse = require('./utils/argparse');
const logError = require('./utils/logError');
const onTerminate = require('./utils/onTerminate');
const configuration = require('./configuration');

Expand Down Expand Up @@ -31,17 +32,16 @@ function getDeviceConfig(configurations) {
return deviceConfig;
}

function validateConfig(config) {
async function initializeDetox(config, params) {
if (!config) {
throw new Error(`No configuration was passed to detox, make sure you pass a config when calling 'detox.init(config)'`);
}

if (!(config.configurations && _.size(config.configurations) >= 1)) {
throw new Error(`No configured devices`);
}
}

async function initializeDetox({configurations, session}, params) {
const {configurations, session} = config;
const deviceConfig = getDeviceConfig(configurations);

detox = new Detox({deviceConfig, session});
Expand All @@ -50,8 +50,15 @@ async function initializeDetox({configurations, session}, params) {
}

async function init(config, params) {
validateConfig(config);
await initializeDetox(config, params);
try {
await initializeDetox(config, params);
} catch (err) {
logError(err);
await cleanup();

detox = null;
throw err;
}
}

async function beforeEach(testSummary) {
Expand Down
3 changes: 3 additions & 0 deletions detox/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('index', () => {
.mock('detox-server')
.mock('./devices/Device')
.mock('./utils/onTerminate')
.mock('./utils/logError')
.mock('./client/Client')
.mock('./Detox', () => jest.fn(() => mockDetox))
.mock('./platform');
Expand All @@ -35,6 +36,7 @@ describe('index', () => {
});

it(`throws if there was no config passed`, async () => {
let logError = require('./utils/logError');
let exception = undefined;

try {
Expand All @@ -44,6 +46,7 @@ describe('index', () => {
}

expect(exception).toBeDefined();
expect(logError).toHaveBeenCalledWith(exception);
});

it(`throws if there is no devices in config`, async () => {
Expand Down

0 comments on commit 0d4ae31

Please sign in to comment.