Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2050 from wix/feat/external-config
feat(config): external configuration files
- Loading branch information
Showing
73 changed files
with
2,511 additions
and
1,280 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
configurations: { | ||
only: { | ||
type: 'ios.simulator', | ||
device: { | ||
type: 'iPhone 11' | ||
} | ||
}, | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
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 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`test fails with a different runner 1`] = `"ava is not supported in detox cli tools. You can still run your tests with the runner's own cli tool"`; | ||
exports[`test fails with a different runner 1`] = ` | ||
"\\"ava\\" is not supported in Detox CLI tools. | ||
HINT: You can still run your tests with the runner's own CLI tool" | ||
`; |
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,27 +1,33 @@ | ||
const _ = require('lodash'); | ||
const cp = require('child_process'); | ||
const log = require('../src/utils/logger').child({ __filename }); | ||
const {getDefaultConfiguration, getConfigurationByKey} = require('./utils/configurationUtils'); | ||
const {composeDetoxConfig} = require('../src/configuration'); | ||
|
||
module.exports.command = 'build'; | ||
module.exports.desc = "Convenience method. Run the command defined in 'build' property of the specified configuration."; | ||
module.exports.builder = { | ||
C: { | ||
alias: 'config-path', | ||
group: 'Configuration:', | ||
describe: 'Specify Detox config file path. If not supplied, detox searches for .detoxrc[.js] or "detox" section in package.json', | ||
}, | ||
c: { | ||
alias: 'configuration', | ||
group: 'Configuration:', | ||
describe: | ||
"Select a device configuration from your defined configurations, if not supplied, and there's only one configuration, detox will default to it", | ||
default: getDefaultConfiguration(), | ||
} | ||
}, | ||
}; | ||
|
||
module.exports.handler = async function build(argv) { | ||
const buildScript = getConfigurationByKey(argv.configuration).build; | ||
const { errorBuilder, deviceConfig } = await composeDetoxConfig({ argv }); | ||
|
||
const buildScript = deviceConfig.build; | ||
|
||
if (buildScript) { | ||
log.info(buildScript); | ||
cp.execSync(buildScript, { stdio: 'inherit' }); | ||
} else { | ||
throw new Error(`Could not find build script in detox.configurations["${argv.configuration}"].build`); | ||
throw errorBuilder.missingBuildScript(); | ||
} | ||
}; |
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,85 +1,46 @@ | ||
jest.mock('child_process'); | ||
jest.mock('../src/utils/logger'); | ||
jest.mock('../src/configuration'); | ||
|
||
describe('build', () => { | ||
let mockExec; | ||
beforeEach(() => { | ||
mockExec = jest.fn(); | ||
jest.mock('child_process', () => ({ | ||
execSync: mockExec | ||
})); | ||
}); | ||
const DetoxConfigErrorBuilder = require('../src/errors/DetoxConfigErrorBuilder'); | ||
|
||
it('runs the build script if there is only one config', async () => { | ||
mockPackageJson({ | ||
configurations: { | ||
only: { | ||
build: 'echo "only"' | ||
} | ||
} | ||
}); | ||
describe('build', () => { | ||
let execSync, composeDetoxConfig, detoxConfig; | ||
|
||
await callCli('./build', 'build'); | ||
expect(mockExec).toHaveBeenCalledWith(expect.stringContaining('only'), expect.anything()); | ||
beforeEach(() => { | ||
detoxConfig = { | ||
artifactsConfig: {}, | ||
behaviorConfig: {}, | ||
deviceConfig: {}, | ||
sessionConfig: {}, | ||
errorBuilder: new DetoxConfigErrorBuilder(), | ||
}; | ||
|
||
execSync = require('child_process').execSync; | ||
composeDetoxConfig = require('../src/configuration').composeDetoxConfig; | ||
composeDetoxConfig.mockReturnValue(Promise.resolve(detoxConfig)); | ||
}); | ||
|
||
it('runs the build script of selected config', async () => { | ||
mockPackageJson({ | ||
configurations: { | ||
only: { | ||
build: 'echo "only"' | ||
}, | ||
myconf: { | ||
build: 'echo "myconf"' | ||
} | ||
} | ||
}); | ||
|
||
await callCli('./build', 'build -c myconf'); | ||
expect(mockExec).toHaveBeenCalledWith(expect.stringContaining('myconf'), expect.anything()); | ||
}); | ||
it('passes argv to composeConfig', async () => { | ||
await callCli('./build', 'build -C /etc/.detoxrc.js -c myconf').catch(() => {}); | ||
|
||
it('fails with multiple configs if none is selected', async () => { | ||
mockPackageJson({ | ||
configurations: { | ||
only: { | ||
build: 'echo "only"' | ||
}, | ||
myconf: { | ||
build: 'echo "myconf"' | ||
} | ||
} | ||
expect(composeDetoxConfig).toHaveBeenCalledWith({ | ||
argv: expect.objectContaining({ | ||
'config-path': '/etc/.detoxrc.js', | ||
'configuration': 'myconf', | ||
}), | ||
}); | ||
|
||
await expect(callCli('./build', 'build')).rejects.toThrowErrorMatchingSnapshot(); | ||
expect(mockExec).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('fails without configurations', async () => { | ||
mockPackageJson({}); | ||
it('runs the build script from the composed device config', async () => { | ||
detoxConfig.deviceConfig.build = 'yet another command'; | ||
|
||
await expect(callCli('./build', 'build')).rejects.toThrowErrorMatchingSnapshot(); | ||
expect(mockExec).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('fails without build script', async () => { | ||
mockPackageJson({ | ||
configurations: { | ||
only: {} | ||
} | ||
}); | ||
|
||
await expect(callCli('./build', 'build -c only')).rejects.toThrowErrorMatchingSnapshot(); | ||
expect(mockExec).not.toHaveBeenCalled(); | ||
await callCli('./build', 'build'); | ||
expect(execSync).toHaveBeenCalledWith('yet another command', expect.anything()); | ||
}); | ||
|
||
it('fails without build script and configuration', async () => { | ||
mockPackageJson({ | ||
configurations: { | ||
only: {} | ||
} | ||
}); | ||
|
||
await expect(callCli('./build', 'build')).rejects.toThrowErrorMatchingSnapshot(); | ||
expect(mockExec).not.toHaveBeenCalled(); | ||
it('fails with an error if a build script has not been found', async () => { | ||
delete detoxConfig.deviceConfig.build; | ||
await expect(callCli('./build', 'build')).rejects.toThrowError(/Could not find a build script/); | ||
}); | ||
}); |
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
Oops, something went wrong.