diff --git a/packages/core/utils/src/config.js b/packages/core/utils/src/config.js index eb08ba0368c..33df8e8c8e4 100644 --- a/packages/core/utils/src/config.js +++ b/packages/core/utils/src/config.js @@ -82,7 +82,6 @@ export async function loadConfig( } let configContent = await fs.readFile(configFile, 'utf8'); - if (!configContent) return null; let config; if (parse === false) { diff --git a/packages/core/utils/test/config.test.js b/packages/core/utils/test/config.test.js new file mode 100644 index 00000000000..99051548a8c --- /dev/null +++ b/packages/core/utils/test/config.test.js @@ -0,0 +1,50 @@ +// @flow strict-local + +import assert from 'assert'; +import {loadConfig} from '../src/config'; +import {inputFS as fs} from '@parcel/test-utils'; +import path from 'path'; + +describe('loadConfig', () => { + it('load config with json', async () => { + assert.deepEqual( + ( + await loadConfig( + fs, + path.join(__dirname, './input/config/config.json'), + ['config.json'], + path.join(__dirname, './input/config/'), + ) + )?.config, + { + hoge: 'fuga', + }, + ); + }); + + it('should throw error with empty string json', async () => { + // $FlowFixMe[prop-missing] + await assert.rejects(async () => { + await loadConfig( + fs, + path.join(__dirname, './input/config/empty.json'), + ['empty.json'], + path.join(__dirname, './input/config/'), + ); + }); + }); + + it('should load with empty string config toml', async () => { + assert.deepEqual( + ( + await loadConfig( + fs, + path.join(__dirname, './input/config/empty.toml'), + ['empty.toml'], + path.join(__dirname, './input/config/'), + ) + )?.config, + {}, + ); + }); +}); diff --git a/packages/core/utils/test/input/config/config.json b/packages/core/utils/test/input/config/config.json new file mode 100644 index 00000000000..1eab92ec765 --- /dev/null +++ b/packages/core/utils/test/input/config/config.json @@ -0,0 +1,3 @@ +{ + "hoge": "fuga" +} \ No newline at end of file diff --git a/packages/core/utils/test/input/config/empty.json b/packages/core/utils/test/input/config/empty.json new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/core/utils/test/input/config/empty.toml b/packages/core/utils/test/input/config/empty.toml new file mode 100644 index 00000000000..e69de29bb2d