Skip to content

Commit

Permalink
Update: allow empty string toml config (#7418)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinyaigeek committed Dec 11, 2021
1 parent 17404e9 commit b27515e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
1 change: 0 additions & 1 deletion packages/core/utils/src/config.js
Expand Up @@ -82,7 +82,6 @@ export async function loadConfig(
}

let configContent = await fs.readFile(configFile, 'utf8');
if (!configContent) return null;

let config;
if (parse === false) {
Expand Down
50 changes: 50 additions & 0 deletions 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,
{},
);
});
});
3 changes: 3 additions & 0 deletions packages/core/utils/test/input/config/config.json
@@ -0,0 +1,3 @@
{
"hoge": "fuga"
}
Empty file.
Empty file.

0 comments on commit b27515e

Please sign in to comment.