test: importing an unparsable config file fails and keeps the config

pull/239/head
paul 2026-10-11 13:35:21 +02:00
parent e471a39e82
commit ea9cfba627
1 changed files with 22 additions and 0 deletions

View File

@ -1,5 +1,6 @@
'use strict';
const fs = require('fs');
const util = require('util');
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');
});
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 () => {
await exec('rm -rf config/sync/admin-role.strapi-editor.json');
// Work around Jest not supporting custom error matching.