Skip to content

Commit a2ded4e

Browse files
committed
Add tests for running from command line
1 parent 97d7542 commit a2ded4e

File tree

6 files changed

+52
-0
lines changed

6 files changed

+52
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "missing-translations"
3+
}

fixtures/no-issues/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "no-issues"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "remove-unused-translations"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "unused-translations"
3+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"eslint-config-prettier": "8.5.0",
3636
"eslint-plugin-node": "11.1.0",
3737
"eslint-plugin-prettier": "4.0.0",
38+
"execa": "^5.0.0",
3839
"jest": "27.5.1",
3940
"lerna-changelog": "2.2.0",
4041
"prettier": "2.6.2",

test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const execa = require('execa');
12
const fs = require('fs');
23
const { run, generateFileList } = require('./index');
34

@@ -59,3 +60,41 @@ describe('generateFileList', () => {
5960
expect(() => generateFileList([])).toThrow('Unexpected empty file list');
6061
});
6162
});
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

Comments
 (0)