From 3c0c6d7fdb046159872aa11232c89b154fc9e53e Mon Sep 17 00:00:00 2001 From: Jen Tak Date: Sat, 3 Sep 2022 19:45:03 +0200 Subject: [PATCH] feat(CLI): Exit with 1 when diff is not empty. To make it easier to use the diff command in scripts and CI and to align its API with POSIX diff and diffs on most systems exit with 1 when the diff is not empty. Keep exiting with 0 when it is. Fixes #66. --- playground/__tests__/cli.test.js | 12 ++++++++++++ server/cli.js | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/playground/__tests__/cli.test.js b/playground/__tests__/cli.test.js index 3379fd6..322f416 100644 --- a/playground/__tests__/cli.test.js +++ b/playground/__tests__/cli.test.js @@ -26,4 +26,16 @@ describe('Test the config-sync CLI', () => { const { stdout } = await exec('yarn cs diff'); expect(stdout).toContain('No differences between DB and sync directory'); }); + test('Non-empty diff returns 1', async () => { + await exec('rm -rf config/sync/admin-role.strapi-author.json'); + // Work around Jest not supporting custom error matching. + // https://github.com/facebook/jest/issues/8140 + let error; + try { + await exec('yarn cs diff'); + } catch(e) { + error = e; + } + expect(error).toHaveProperty('code', 1); + }); }); diff --git a/server/cli.js b/server/cli.js index f8c6273..c82b068 100644 --- a/server/cli.js +++ b/server/cli.js @@ -269,7 +269,7 @@ program { color: true }, )); - process.exit(0); + process.exit(1); } // Init table. @@ -283,7 +283,7 @@ program // Print table. console.log(table.toString()); - process.exit(0); + process.exit(1); }); program.parseAsync(process.argv);