Skip to content

Commit bfd571a

Browse files
authored
Merge pull request #67 from goodhoko/feat-diff-exit-status
feat(CLI): Exit with 1 when diff is not empty.
2 parents dc2ea31 + 78c812d commit bfd571a

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

playground/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ yarn.lock
102102

103103
testApp
104104
coverage
105+
/config/sync
105106

106107
############################
107108
# Strapi

playground/__tests__/cli.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ const exec = util.promisify(require('child_process').exec);
66
jest.setTimeout(20000);
77

88
describe('Test the config-sync CLI', () => {
9+
10+
afterAll(async () => {
11+
// Remove the generated files and the DB.
12+
await exec('rm -rf config/sync');
13+
await exec('rm -rf .tmp');
14+
});
15+
916
test('Export', async () => {
1017
const { stdout } = await exec('yarn cs export -y');
1118
expect(stdout).toContain('Finished export');
@@ -19,4 +26,16 @@ describe('Test the config-sync CLI', () => {
1926
const { stdout } = await exec('yarn cs diff');
2027
expect(stdout).toContain('No differences between DB and sync directory');
2128
});
29+
test('Non-empty diff returns 1', async () => {
30+
await exec('rm -rf config/sync/admin-role.strapi-author.json');
31+
// Work around Jest not supporting custom error matching.
32+
// https://github.com/facebook/jest/issues/8140
33+
let error;
34+
try {
35+
await exec('yarn cs diff');
36+
} catch(e) {
37+
error = e;
38+
}
39+
expect(error).toHaveProperty('code', 1);
40+
});
2241
});

playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@strapi/plugin-users-permissions": "^4.0.0",
2020
"@strapi/strapi": "^4.0.0",
2121
"sqlite3": "5.0.2",
22-
"strapi-plugin-config-sync": "boazpoolman/strapi-plugin-config-sync"
22+
"strapi-plugin-config-sync": "./.."
2323
},
2424
"author": {
2525
"name": "A Strapi developer"

server/cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ program
269269
{ color: true },
270270
));
271271

272-
process.exit(0);
272+
process.exit(1);
273273
}
274274

275275
// Init table.
@@ -283,7 +283,7 @@ program
283283
// Print table.
284284
console.log(table.toString());
285285

286-
process.exit(0);
286+
process.exit(1);
287287
});
288288

289289
program.parseAsync(process.argv);

0 commit comments

Comments
 (0)