Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: find *.cjs configs #4358

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading