Skip to content

Commit

Permalink
Add test for unsupported configs
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Feb 14, 2022
1 parent aaf9d1a commit 0e53b75
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions test/config/next-gen.js
Expand Up @@ -10,13 +10,21 @@ const FIXTURE_ROOT = fileURLToPath(new URL('fixtures', import.meta.url));

const resolve = relpath => path.resolve(FIXTURE_ROOT, relpath);

const loadFromSetup = setup => {
const loadFromSetup = (setup, t) => {
if (typeof setup === 'string') {
return loadConfig();
}

const {configFile, defaults, resolveFrom} = setup;
return loadConfig({configFile, defaults, resolveFrom});
const {
configFile,
defaults,
resolveFrom,
handleUnsupportedConfigs = t => unsupportedConfigs => {
t.is(unsupportedConfigs.length, 0);
},
} = setup;

return loadConfig({configFile, defaults, resolveFrom, handleUnsupportedConfigs: handleUnsupportedConfigs(t)});
};

const ok = setup => async (t, assert = tt => tt.pass()) => {
Expand All @@ -26,7 +34,7 @@ const ok = setup => async (t, assert = tt => tt.pass()) => {
t.teardown(() => stub.restore());
stub.returns(resolve(fixture));

const conf = loadFromSetup(setup);
const conf = loadFromSetup(setup, t);
await t.notThrowsAsync(conf);
const result = await t.try(assert, await conf, setup);
result.commit();
Expand All @@ -39,7 +47,7 @@ const notOk = setup => async (t, assert = (tt, error) => tt.snapshot(error.messa
t.teardown(() => stub.restore());
stub.returns(resolve(fixture));

const conf = loadFromSetup(setup);
const conf = loadFromSetup(setup, t);
const error = await t.throwsAsync(conf);
const result = await t.try(assert, error, setup);
result.commit();
Expand Down Expand Up @@ -67,6 +75,19 @@ test.serial('loads .js config as ESM', ok('js-as-esm'), (t, conf) => {
t.true(conf.failFast);
});

test.serial('finds unsupported configs',
ok({
fixture: 'unsupported-configs',
handleUnsupportedConfigs: t => unsupportedConfigs => {
t.is(unsupportedConfigs.length, 1);
t.regex(unsupportedConfigs[0], /test\/config\/fixtures\/unsupported-configs\/ava.config.json/);
},
}),
(t, conf) => {
t.true(conf.failFast);
},
);

test.serial('handles errors when loading .js config as ESM', notOk({
fixture: 'js-as-esm',
configFile: 'error.js',
Expand Down

0 comments on commit 0e53b75

Please sign in to comment.