Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use alternative flow to handle env variables
  • Loading branch information
Alexey committed Oct 16, 2017
commit 8c9dc3b5b5f8d47a1ddd464e69c056f10962a640
47 changes: 27 additions & 20 deletions detox/local-cli/detox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,37 @@ const {
cleanup,
reuse,
debugSynchronization,
artifactsLocation,
artifactsLocation
} = program;

switch (runner) {
case 'mocha':
command = `node_modules/.bin/${runner} ${testFolder} --opts ${testFolder}/${program.runnerConfig}`;
break;
case 'jest':
command = `node_modules/.bin/${runner} ${testFolder} --runInBand`;
const loglevel = program.loglevel ? `--loglevel ${program.loglevel}` : ''; +let runner = config.runner || 'mocha';
const configuration = program.configuration ? `--configuration ${program.configuration}` : '';
const cleanup = program.cleanup ? `--cleanup` : '';
const reuse = program.reuse ? `--reuse` : '';
const artifactsLocation = program.artifactsLocation ? `--artifacts-location ${program.artifactsLocation}` : '';
command = `node_modules/.bin/${program.runner} ${testFolder} --opts ${testFolder}/${program.runnerConfig} ${configuration} ${loglevel} ${cleanup} ${reuse} ${debugSynchronization} ${artifactsLocation}`;

console.log(command);
cp.execSync(command, { stdio: 'inherit' });
break;
default:
case 'jest':
command = `node_modules/.bin/${runner} ${testFolder} --runInBand`;
console.log(command);
cp.execSync(command, {
stdio: 'inherit',
env: {
...process.env,
configuration,
loglevel,
cleanup,
reuse,
debugSynchronization,
artifactsLocation
}
});
break;
default:
throw new Error(`${runner} is not supported in detox cli tools. You can still run your tests with the runner's own cli tool`);
}

console.log(command);
cp.execSync(command, {
stdio: 'inherit',
env: {
...process.env,
configuration,
loglevel,
cleanup,
reuse,
debugSynchronization,
artifactsLocation,
},
});
1 change: 1 addition & 0 deletions detox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"eslint-plugin-react": "^7.1.0",
"eslint-plugin-react-native": "^2.3.2",
"jest": "^20.0.4",
"minimist": "^1.2.0",
"mockdate": "^2.0.1",
"shelljs": "^0.7.3",
"ttab": "^0.3.1"
Expand Down
4 changes: 3 additions & 1 deletion detox/src/utils/argparse.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const argv = require('minimist')(process.argv.slice(2));

function getArgValue(key) {
return process.env[key];
return (argv && argv[key]) ? argv[key] : process.env[key];
}

module.exports = {
Expand Down
39 changes: 30 additions & 9 deletions detox/src/utils/argparse.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
jest.unmock('process');

describe('argparse', () => {
let argparse;
describe('using env variables', () => {
let argparse;

beforeEach(() => {
process.env.test = 'a value';
argparse = require('./argparse');
});
beforeEach(() => {
process.env.test = 'a value';
argparse = require('./argparse');
});

it(`nonexistent key should return undefined result`, () => {
expect(argparse.getArgValue('blah')).not.toBeDefined();
});

it(`nonexistent key should return undefined result`, () => {
expect(argparse.getArgValue('blah')).not.toBeDefined();
it(`existing key should return a result`, () => {
expect(argparse.getArgValue('test')).toBe('a value');
});
});

it(`existing key should return a result`, () => {
expect(argparse.getArgValue('test')).toBe('a value');
describe('using arguments', () => {
let argparse;

beforeEach(() => {
jest.mock('minimist');
const minimist = require('minimist');
minimist.mockReturnValue({test: 'a value'});
argparse = require('./argparse');
});

it(`nonexistent key should return undefined result`, () => {
expect(argparse.getArgValue('blah')).not.toBeDefined();
});

it(`existing key should return a result`, () => {
expect(argparse.getArgValue('test')).toBe('a value');
});
});
});