From 0e25b7ad6dd6a9fb0e42306b41ffb6f03fc4b9c5 Mon Sep 17 00:00:00 2001 From: Jen Tak Date: Sun, 4 Sep 2022 10:35:57 +0200 Subject: [PATCH 1/4] Git-ignore sync files generated by tests. --- playground/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/playground/.gitignore b/playground/.gitignore index 3a3c26f..39e2e19 100644 --- a/playground/.gitignore +++ b/playground/.gitignore @@ -102,6 +102,7 @@ yarn.lock testApp coverage +/config/sync ############################ # Strapi From 8f9b34460470ba9a14d2aed40ab3a2532e61e689 Mon Sep 17 00:00:00 2001 From: Jen Tak Date: Sun, 4 Sep 2022 10:42:52 +0200 Subject: [PATCH 2/4] Cleanup after integration tests. Running the tests repeatedly failed as the DB was left in an altered state which interfered with the subsequent test invocation. Remove the DB and generated config files after all the tests run. --- playground/__tests__/cli.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/playground/__tests__/cli.test.js b/playground/__tests__/cli.test.js index b5b3b93..3379fd6 100644 --- a/playground/__tests__/cli.test.js +++ b/playground/__tests__/cli.test.js @@ -6,6 +6,13 @@ const exec = util.promisify(require('child_process').exec); jest.setTimeout(20000); describe('Test the config-sync CLI', () => { + + afterAll(async () => { + // Remove the generated files and the DB. + await exec('rm -rf config/sync'); + await exec('rm -rf .tmp'); + }); + test('Export', async () => { const { stdout } = await exec('yarn cs export -y'); expect(stdout).toContain('Finished export'); From 3c0c6d7fdb046159872aa11232c89b154fc9e53e Mon Sep 17 00:00:00 2001 From: Jen Tak Date: Sat, 3 Sep 2022 19:45:03 +0200 Subject: [PATCH 3/4] 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); From 78c812d31f7801c2303a6928b28cbe618baca7d1 Mon Sep 17 00:00:00 2001 From: Jen Tak Date: Mon, 5 Sep 2022 14:53:41 +0200 Subject: [PATCH 4/4] Link to local version of strapi-plugin-config-sync. Linking to "boazpoolman/strapi-plugin-config-sync" resolves to the version of strapi-plugin-config-sync currently on master branch on GitHub. Which prevents running tests in the playground against the local version. --- playground/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playground/package.json b/playground/package.json index 6af6628..3c84274 100644 --- a/playground/package.json +++ b/playground/package.json @@ -19,7 +19,7 @@ "@strapi/plugin-users-permissions": "^4.0.0", "@strapi/strapi": "^4.0.0", "sqlite3": "5.0.2", - "strapi-plugin-config-sync": "boazpoolman/strapi-plugin-config-sync" + "strapi-plugin-config-sync": "./.." }, "author": { "name": "A Strapi developer"