Skip to content

Commit

Permalink
fix: config-path, examples, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed May 25, 2020
1 parent 7a2f03f commit 33e2ecf
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 17 deletions.
10 changes: 10 additions & 0 deletions detox/local-cli/__mocks__/detox.config.js
@@ -0,0 +1,10 @@
module.exports = {
configurations: {
only: {
type: 'ios.simulator',
device: {
type: 'iPhone 11'
}
},
},
};
1 change: 0 additions & 1 deletion detox/local-cli/build.js
Expand Up @@ -2,7 +2,6 @@ const _ = require('lodash');
const cp = require('child_process');
const log = require('../src/utils/logger').child({ __filename });
const {composeDetoxConfig} = require('../src/configuration');
const DetoxConfigErrorBuilder = require('../src/errors/DetoxConfigErrorBuilder');

module.exports.command = 'build';
module.exports.desc = "Convenience method. Run the command defined in 'build' property of the specified configuration.";
Expand Down
2 changes: 2 additions & 0 deletions detox/local-cli/test.js
Expand Up @@ -209,6 +209,7 @@ module.exports.handler = async function test(program) {
(path.join('node_modules', '.bin', runnerConfig.testRunner)),
...safeGuardArguments([
(runnerConfig.runnerConfig ? `--${configParam} ${runnerConfig.runnerConfig}` : ''),
(cliConfig.configPath ? `--config-path ${cliConfig.configPath}` : ''),
(cliConfig.configuration ? `--configuration ${cliConfig.configuration}` : ''),
(cliConfig.loglevel ? `--loglevel ${cliConfig.loglevel}` : ''),
(cliConfig.noColor ? '--no-colors' : ''),
Expand Down Expand Up @@ -269,6 +270,7 @@ module.exports.handler = async function test(program) {

const detoxEnvironmentVariables = {
..._.pick(cliConfig, [
'configPath',
'configuration',
'loglevel',
'cleanup',
Expand Down
30 changes: 29 additions & 1 deletion detox/local-cli/test.test.js
Expand Up @@ -2,7 +2,7 @@ jest.mock('../src/utils/logger');
jest.mock('../src/configuration');
jest.mock('child_process');

const fs = require('fs-extra');
const path = require('path');
const {normalize} = require('path');
const shellQuote = require('./utils/shellQuote');

Expand Down Expand Up @@ -58,6 +58,17 @@ describe('test', () => {
);
});

it('passes custom Detox config', async () => {
mockAndroidMochaConfiguration();

await callCli('./test', `test -C ${path.join(__dirname, '__mocks__/detox.config.js')}`);

expect(execSync).toHaveBeenCalledWith(
expect.stringMatching(/mocha.* --config-path .*__mocks__.detox\.config\.js/),
expect.anything()
);
});

it('changes --opts to --config, when given non ".opts" file extension', async () => {
mockAndroidMochaConfiguration({
'runner-config': 'e2e/.mocharc.json'
Expand Down Expand Up @@ -106,6 +117,23 @@ describe('test', () => {
);
});

it('passes custom Detox config', async () => {
mockAndroidJestConfiguration();

await callCli('./test', `test -C ${path.join(__dirname, '__mocks__/detox.config.js')}`);

expect(execSync).toHaveBeenCalledWith(
expect.stringContaining(
`${normalize('node_modules/.bin/jest')} --config e2e/config.json`
),
expect.objectContaining({
env: expect.objectContaining({
configPath: expect.stringMatching(/__mocks__.detox\.config\.js$/),
}),
})
);
});

it('should pass in device-launch-args as an environment variable', async () => {
mockAndroidJestConfiguration();

Expand Down
4 changes: 2 additions & 2 deletions detox/src/DetoxExportWrapper.js
Expand Up @@ -29,12 +29,12 @@ class DetoxExportWrapper {
this._defineProxy('device');
}

async init(detoxConfigOverride, userParams) {
async init(configOverride, userParams) {
let configError, exposeGlobals, resolvedConfig;

try {
resolvedConfig = await configuration.composeDetoxConfig({
override: detoxConfigOverride,
override: configOverride,
userParams,
});

Expand Down
2 changes: 1 addition & 1 deletion detox/src/configuration/composeDeviceConfig.js
Expand Up @@ -8,7 +8,7 @@ const _ = require('lodash');
* @returns {*}
*/
function composeDeviceConfig({ errorBuilder, rawDeviceConfig, cliConfig }) {
if (!rawDeviceConfig.type) {
if (!rawDeviceConfig || !rawDeviceConfig.type) {
throw errorBuilder.missingConfigurationType();
}

Expand Down
5 changes: 5 additions & 0 deletions detox/src/configuration/composeDeviceConfig.test.js
Expand Up @@ -27,6 +27,11 @@ describe('composeDeviceConfig', () => {
});

describe('validation', () => {
it('should throw if configuration is not defined', () => {
rawDeviceConfig = undefined;
expect(compose).toThrowError(errorBuilder.missingConfigurationType());
});

it('should throw if configuration driver (type) is not defined', () => {
delete rawDeviceConfig.type;
expect(compose).toThrowError(errorBuilder.missingConfigurationType());
Expand Down
1 change: 0 additions & 1 deletion detox/src/configuration/index.js
@@ -1,5 +1,4 @@
const _ = require('lodash');
const DetoxConfigError = require('../errors/DetoxConfigError');
const DetoxConfigErrorBuilder = require('../errors/DetoxConfigErrorBuilder');
const collectCliConfig = require('./collectCliConfig');
const loadExternalConfig = require('./loadExternalConfig');
Expand Down
2 changes: 1 addition & 1 deletion detox/test/e2e/init.js
Expand Up @@ -19,7 +19,7 @@ jasmine.getEnv().addReporter(assignReporter);
jest.setTimeout(timeoutUtils.testTimeout);

beforeAll(async () => {
await detox.init();
await detox.init(config);
}, timeoutUtils.initTimeout);

beforeEach(async () => {
Expand Down
1 change: 0 additions & 1 deletion examples/demo-native-ios/e2e/init.js
@@ -1,6 +1,5 @@
require('babel-polyfill');
const detox = require('detox');
const config = require('../package.json').detox;

before(async () => {
await detox.init();
Expand Down
1 change: 0 additions & 1 deletion examples/demo-plugin/e2e/init.js
@@ -1,5 +1,4 @@
const detox = require('detox');
const config = require('../package.json').detox;
const adapter = require('detox/runners/jest/adapter');
const specReporter = require('detox/runners/jest/specReporter');
const assignReporter = require('detox/runners/jest/assignReporter');
Expand Down
3 changes: 1 addition & 2 deletions examples/demo-react-native-detox-instruments/e2e/init.js
@@ -1,9 +1,8 @@
const detox = require('detox');
const config = require('../package.json').detox;
const adapter = require('detox/runners/mocha/adapter');

before(async () => {
await detox.init(config);
await detox.init();
});

beforeEach(async function () {
Expand Down
1 change: 0 additions & 1 deletion examples/demo-react-native-jest/e2e/init-circus.js
@@ -1,5 +1,4 @@
const detox = require('detox');
const config = require('../package.json').detox;
const adapter = require('detox/runners/jest/adapter');
const specReporter = require('detox/runners/jest/specReporter');
const assignReporter = require('detox/runners/jest/assignReporter');
Expand Down
1 change: 0 additions & 1 deletion examples/demo-react-native-jest/e2e/init.js
@@ -1,5 +1,4 @@
const detox = require('detox');
const config = require('../package.json').detox;
const adapter = require('detox/runners/jest/adapter');
const specReporter = require('detox/runners/jest/specReporter');
const assignReporter = require('detox/runners/jest/assignReporter');
Expand Down
2 changes: 1 addition & 1 deletion examples/demo-react-native/detox.config.js
Expand Up @@ -3,7 +3,7 @@ module.exports = {
"runner-config": "e2e/.mocharc.json",
"behavior": {
"init": {
"exposeGlobals": process.env.DETOX_NO_EXPOSE === '1' ? false : true,
"exposeGlobals": process.env.DETOX_EXPOSE_GLOBALS === '0' ? false : true,
},
},
"configurations": {
Expand Down
1 change: 0 additions & 1 deletion examples/demo-react-native/e2e/init.js
@@ -1,5 +1,4 @@
const detox = require('detox');
const config = require('../detox.config');
const adapter = require('detox/runners/mocha/adapter');

before(async () => {
Expand Down
4 changes: 2 additions & 2 deletions examples/demo-react-native/package.json
Expand Up @@ -12,8 +12,8 @@
"test:android-debug": "detox test --configuration android.emu.debug",
"test:android-release": "detox test --configuration android.emu.release",
"test:android-release-ci": "detox test --configuration android.emu.release -l verbose --headless --record-logs all --take-screenshots all",
"test:android-explicit-require": "DETOX_NO_EXPOSE=1 detox test e2eExplicitRequire -c android.emu.release",
"test:android-explicit-require-ci": "DETOX_NO_EXPOSE=1 detox test e2eExplicitRequire -c android.emu.release -l verbose --headless --record-logs all --take-screenshots all",
"test:android-explicit-require": "DETOX_EXPOSE_GLOBALS=0 detox test e2eExplicitRequire -c android.emu.release",
"test:android-explicit-require-ci": "DETOX_EXPOSE_GLOBALS=0 detox test e2eExplicitRequire -c android.emu.release -l verbose --headless --record-logs all --take-screenshots all",
"e2e:ios": "npm run build:ios && npm run test:ios",
"e2e:android-debug": "npm run build:android-debug && npm run test:android-debug",
"e2e:android-release": "npm run build:android-release && npm run test:android-release"
Expand Down

0 comments on commit 33e2ecf

Please sign in to comment.