|
| 1 | +const execa = require('execa'); |
1 | 2 | const fs = require('fs'); |
2 | 3 | const { run, generateFileList } = require('./index'); |
3 | 4 |
|
@@ -59,3 +60,41 @@ describe('generateFileList', () => { |
59 | 60 | expect(() => generateFileList([])).toThrow('Unexpected empty file list'); |
60 | 61 | }); |
61 | 62 | }); |
| 63 | + |
| 64 | +describe('Running from cli', () => { |
| 65 | + test('without unused translations', async () => { |
| 66 | + let { stdout } = await execa('node', ['../../bin/cli'], { |
| 67 | + cwd: `${__dirname}/fixtures/no-issues`, |
| 68 | + }); |
| 69 | + |
| 70 | + expect(stdout).toMatch('No unused translations'); |
| 71 | + }); |
| 72 | + |
| 73 | + test('with unused translations', async () => { |
| 74 | + expect( |
| 75 | + execa('node', ['../../bin/cli'], { cwd: `${__dirname}/fixtures/unused-translations` }) |
| 76 | + ).rejects.toThrowError('Found 2 unused translations'); |
| 77 | + }); |
| 78 | + |
| 79 | + test('with missing translations', async () => { |
| 80 | + expect( |
| 81 | + execa('node', ['../../bin/cli'], { cwd: `${__dirname}/fixtures/missing-translations` }) |
| 82 | + ).rejects.toThrowError('Found 2 missing translations'); |
| 83 | + }); |
| 84 | + |
| 85 | + describe('with auto-fix', () => { |
| 86 | + afterEach(async function () { |
| 87 | + await execa('git', ['checkout', 'HEAD', 'fixtures/remove-unused-translations/translations'], { |
| 88 | + cwd: __dirname, |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + test('with unused translations', async () => { |
| 93 | + let { stdout } = await execa('node', ['../../bin/cli', '--fix'], { |
| 94 | + cwd: `${__dirname}/fixtures/remove-unused-translations`, |
| 95 | + }); |
| 96 | + |
| 97 | + expect(stdout).toMatch('All unused translations were removed'); |
| 98 | + }); |
| 99 | + }); |
| 100 | +}); |
0 commit comments