Skip to content

Commit

Permalink
Merge pull request #303 from quantizor/fix-handle-esm-config-file
Browse files Browse the repository at this point in the history
fix: handle ESM-style config file
  • Loading branch information
lencioni authored Dec 19, 2024
2 parents 36e8bde + 5684b43 commit 14c60fe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/loadUserConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ async function load(pathToConfigFile) {
// await if the config is a function, async or not
if (typeof userConfig === 'function') {
userConfig = await userConfig();
} else if (userConfig?.default) {
// handle esm
userConfig = userConfig.default;
}
return { ...defaultConfig, ...userConfig };
} catch (e) {
Expand Down
19 changes: 19 additions & 0 deletions test/loadUserConfig-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,22 @@ it('warns when using an unknown config key', async () => {
'Unknown config key used in .happo.js: "foobar"',
);
});

it('handles an ESM-style config', async () => {
requireRelative.mockImplementation(() => ({
__esModule: true,
default: {
apiKey: '1',
apiSecret: '2',
targets: {
firefox: new RemoteBrowserTarget('firefox', { viewport: '800x600' }),
},
},
}));
const config = await loadUserConfig('bogus', {});
expect(config.apiKey).toEqual('1');
expect(config.apiSecret).toEqual('2');
expect(config.targets).toEqual({
firefox: new RemoteBrowserTarget('firefox', { viewport: '800x600' }),
});
});

0 comments on commit 14c60fe

Please sign in to comment.