Skip to content

Commit

Permalink
fix: find *.cjs configs (#4358)
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph authored Feb 6, 2024
1 parent 700b750 commit 85f0874
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
11 changes: 11 additions & 0 deletions detox/src/configuration/__mocks__/configuration/cjs/.detoxrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
configurations: {
simple: {
device: {
type: "android.attached",
device: "Hello from .detoxrc",
},
apps: [],
},
},
};
8 changes: 7 additions & 1 deletion detox/src/configuration/loadExternalConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ const log = require('../utils/logger').child({ cat: 'config' });

async function locateExternalConfig(cwd) {
return findUp([
'.detoxrc.cjs',
'.detoxrc.js',
'.detoxrc.json',
'.detoxrc',
'detox.config.cjs',
'detox.config.js',
'detox.config.json',
'package.json',
], { cwd });
}

async function loadConfig(configPath) {
let config = path.extname(configPath) === '.js'
let config = isJS(path.extname(configPath))
? require(configPath)
: JSON.parse(await fs.readFile(configPath, 'utf8'));

Expand All @@ -34,6 +36,10 @@ async function loadConfig(configPath) {
};
}

function isJS(ext) {
return ext === '.js' || ext === '.cjs';
}

async function resolveConfigPath(configPath, cwd) {
if (!configPath) {
return locateExternalConfig(cwd);
Expand Down
8 changes: 8 additions & 0 deletions detox/src/configuration/loadExternalConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const os = require('os');
const path = require('path');

describe('loadExternalConfig', () => {
const DIR_CJS = path.join(__dirname, '__mocks__/configuration/cjs');
const DIR_PACKAGEJSON = path.join(__dirname, '__mocks__/configuration/packagejson');
const DIR_PRIORITY = path.join(__dirname, '__mocks__/configuration/priority');
const DIR_EXTENDS = path.join(__dirname, '__mocks__/configuration/extends');
Expand Down Expand Up @@ -35,6 +36,13 @@ describe('loadExternalConfig', () => {
expect(logger.warn).not.toHaveBeenCalled();
});

it('should implicitly use .detoxrc.cjs', async () => {
const { filepath, config } = await loadExternalConfig({ cwd: DIR_CJS });
expect(filepath).toBe(path.join(DIR_CJS, '.detoxrc.cjs'));
expect(config).toMatchObject({ configurations: expect.anything() });
expect(logger.warn).not.toHaveBeenCalled();
});

it('should implicitly use package.json, even if there is no .detoxrc', async () => {
const { filepath, config } = await loadExternalConfig({ cwd: DIR_PACKAGEJSON });

Expand Down

0 comments on commit 85f0874

Please sign in to comment.