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(Windows): ensure configuration file loading (js and cjs) #602

Merged
merged 1 commit into from
Jul 25, 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
5 changes: 5 additions & 0 deletions fixtures/config-files/custom-cjs-file/custom.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
debug: true,
};
Empty file.
3 changes: 1 addition & 2 deletions src/parsers/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export const getConfigs = async (

try {
if (filePath.endsWith('.js') || filePath.endsWith('.cjs')) {
/* c8 ignore next */ // ?
return (await import(normalize(filePath))) as ConfigFile;
return require(`file://${normalize(filePath)}`);
}

const configsFile = await readFile(filePath, 'utf-8');
Expand Down
26 changes: 26 additions & 0 deletions test/e2e/config-files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,30 @@ describe('Test Runtimes/Platforms + Extensions', async () => {
assert(/PASS › 1/.test(output.stdout), 'CLI needs to pass 1');
assert(/debug/.test(output.stdout), 'CLI needs to pass able "debug"');
});

await it('Custom (CJS)', async () => {
const output = await inspectCLI(
'npx tsx ../../../src/bin/index.ts --config=custom.cjs',
{
cwd: 'fixtures/config-files/custom-cjs-file',
}
);

assert.strictEqual(output.exitCode, 0, 'Exit Code needs to be 0');
assert(/PASS › 1/.test(output.stdout), 'CLI needs to pass 1');
assert(/debug/.test(output.stdout), 'CLI needs to pass able "debug"');
});

await it('Missing (JS)', async () => {
const output = await inspectCLI(
'npx tsx ../../../src/bin/index.ts --config=missing.js',
{
cwd: 'fixtures/config-files/custom-js-file',
}
);

assert.strictEqual(output.exitCode, 0, 'Exit Code needs to be 0');
assert(/PASS › 1/.test(output.stdout), 'CLI needs to fail 1');
assert(!/debug/.test(output.stdout), 'CLI needs to pass able "debug"');
});
});
Loading