Skip to content

Commit

Permalink
fix(Windows): ensure configuration file loading (js and cjs) (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwelwel authored Jul 25, 2024
1 parent f82ecd7 commit 2d53660
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
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"');
});
});

0 comments on commit 2d53660

Please sign in to comment.