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

Update: allow empty string toml config #7418

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.