diff --git a/lib/index.js b/lib/index.js index 925c4dfb..27cd4f0d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -197,6 +197,12 @@ function base() { * @returns {void} */ function addPreset(result) { + if (!('plugins' in result) && !('settings' in result)) { + throw new Error( + 'Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither' + ) + } + addList(result.plugins) if (result.settings) { diff --git a/test/use.js b/test/use.js index 1a3eb423..0c9591ab 100644 --- a/test/use.js +++ b/test/use.js @@ -308,11 +308,13 @@ test('use(preset)', (t) => { 'should throw on invalid `plugins` (2)' ) - t.test('should support empty presets', (t) => { - const processor = unified().use({}).freeze() - t.equal(processor.attachers.length, 0) - t.end() - }) + t.throws( + () => { + unified().use({}).freeze() + }, + /Expected usable value but received an empty preset/, + 'should throw on empty presets' + ) t.test('should support presets with empty plugins', (t) => { const processor = unified().use({plugins: []}).freeze()