diff --git a/fixtures/missing-translations/package.json b/fixtures/missing-translations/package.json new file mode 100644 index 00000000..21320dfb --- /dev/null +++ b/fixtures/missing-translations/package.json @@ -0,0 +1,3 @@ +{ + "name": "missing-translations" +} diff --git a/fixtures/no-issues/package.json b/fixtures/no-issues/package.json new file mode 100644 index 00000000..433e7bae --- /dev/null +++ b/fixtures/no-issues/package.json @@ -0,0 +1,3 @@ +{ + "name": "no-issues" +} diff --git a/fixtures/remove-unused-translations/package.json b/fixtures/remove-unused-translations/package.json new file mode 100644 index 00000000..cf20f829 --- /dev/null +++ b/fixtures/remove-unused-translations/package.json @@ -0,0 +1,3 @@ +{ + "name": "remove-unused-translations" +} diff --git a/fixtures/unused-translations/package.json b/fixtures/unused-translations/package.json new file mode 100644 index 00000000..b6ecb8ed --- /dev/null +++ b/fixtures/unused-translations/package.json @@ -0,0 +1,3 @@ +{ + "name": "unused-translations" +} diff --git a/package.json b/package.json index d3d2c815..75b89d27 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "eslint-config-prettier": "8.5.0", "eslint-plugin-node": "11.1.0", "eslint-plugin-prettier": "4.0.0", + "execa": "^5.0.0", "jest": "27.5.1", "lerna-changelog": "2.2.0", "prettier": "2.6.2" diff --git a/test.js b/test.js index 95a6227b..6edd46ab 100644 --- a/test.js +++ b/test.js @@ -1,3 +1,4 @@ +const execa = require('execa'); const fs = require('fs'); const { run, generateFileList } = require('./index'); @@ -59,3 +60,41 @@ describe('generateFileList', () => { expect(() => generateFileList([])).toThrow('Unexpected empty file list'); }); }); + +describe('Running from cli', () => { + test('without unused translations', async () => { + let { stdout } = await execa('node', ['../../bin/cli'], { + cwd: `${__dirname}/fixtures/no-issues`, + }); + + expect(stdout).toMatch('No unused translations'); + }); + + test('with unused translations', async () => { + expect( + execa('node', ['../../bin/cli'], { cwd: `${__dirname}/fixtures/unused-translations` }) + ).rejects.toThrowError('Found 2 unused translations'); + }); + + test('with missing translations', async () => { + expect( + execa('node', ['../../bin/cli'], { cwd: `${__dirname}/fixtures/missing-translations` }) + ).rejects.toThrowError('Found 2 missing translations'); + }); + + describe('with auto-fix', () => { + afterEach(async function () { + await execa('git', ['checkout', 'HEAD', 'fixtures/remove-unused-translations/translations'], { + cwd: __dirname, + }); + }); + + test('with unused translations', async () => { + let { stdout } = await execa('node', ['../../bin/cli', '--fix'], { + cwd: `${__dirname}/fixtures/remove-unused-translations`, + }); + + expect(stdout).toMatch('All unused translations were removed'); + }); + }); +});