test: importing an unparsable config file fails and keeps the config
parent
e471a39e82
commit
ea9cfba627
|
|
@ -1,5 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const exec = util.promisify(require('child_process').exec);
|
const exec = util.promisify(require('child_process').exec);
|
||||||
|
|
||||||
|
|
@ -46,6 +47,27 @@ describe('Test the config-sync CLI', () => {
|
||||||
expect(diffOutput).toContain('No differences between DB and sync directory');
|
expect(diffOutput).toContain('No differences between DB and sync directory');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Import (unparsable file)', async () => {
|
||||||
|
// A file that can't be parsed (a merge conflict left in it, a typo) is not a missing file:
|
||||||
|
// importing it must fail, and leave the config in the database.
|
||||||
|
const file = 'config/sync/user-role.public.json';
|
||||||
|
const original = fs.readFileSync(file, 'utf8');
|
||||||
|
fs.writeFileSync(file, '<<<<<<< HEAD\n{ "name": "Public",\n');
|
||||||
|
let output;
|
||||||
|
try {
|
||||||
|
const { stdout, stderr } = await exec('yarn cs import -p user-role.public -y');
|
||||||
|
output = stdout + stderr;
|
||||||
|
} catch (e) {
|
||||||
|
output = `${e.stdout}${e.stderr}`;
|
||||||
|
} finally {
|
||||||
|
fs.writeFileSync(file, original);
|
||||||
|
}
|
||||||
|
expect(output).toContain('is not valid JSON');
|
||||||
|
// The role is still in the database: with its file back, nothing differs.
|
||||||
|
const { stdout: diffOutput } = await exec('yarn cs diff');
|
||||||
|
expect(diffOutput).toContain('No differences between DB and sync directory');
|
||||||
|
});
|
||||||
|
|
||||||
test('Non-empty diff returns 1', async () => {
|
test('Non-empty diff returns 1', async () => {
|
||||||
await exec('rm -rf config/sync/admin-role.strapi-editor.json');
|
await exec('rm -rf config/sync/admin-role.strapi-editor.json');
|
||||||
// Work around Jest not supporting custom error matching.
|
// Work around Jest not supporting custom error matching.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue