Skip to content

Commit 3c457f9

Browse files
committed
Add tests for running from command line
1 parent 03f23cf commit 3c457f9

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
@@ -34,6 +34,7 @@
3434
"eslint-config-prettier": "8.5.0",
3535
"eslint-plugin-node": "11.1.0",
3636
"eslint-plugin-prettier": "4.0.0",
37+
"execa": "^5.0.0",
3738
"jest": "27.5.1",
3839
"lerna-changelog": "2.2.0",
3940
"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

@@ -64,3 +65,41 @@ describe('generateFileList', () => {
6465
expect(() => generateFileList([])).toThrow('Unexpected empty file list');
6566
});
6667
});
68+
69+
describe('Running from cli', () => {
70+
test('without unused translations', async () => {
71+
let { stdout } = await execa('node', ['../../bin/cli'], {
72+
cwd: `${__dirname}/fixtures/no-issues`,
73+
});
74+
75+
expect(stdout).toMatch('No unused translations');
76+
});
77+
78+
test('with unused translations', async () => {
79+
expect(
80+
execa('node', ['../../bin/cli'], { cwd: `${__dirname}/fixtures/unused-translations` })
81+
).rejects.toThrowError('Found 2 unused translations');
82+
});
83+
84+
test('with missing translations', async () => {
85+
expect(
86+
execa('node', ['../../bin/cli'], { cwd: `${__dirname}/fixtures/missing-translations` })
87+
).rejects.toThrowError('Found 2 missing translations');
88+
});
89+
90+
describe('with auto-fix', () => {
91+
afterEach(async function () {
92+
await execa('git', ['checkout', 'HEAD', 'fixtures/remove-unused-translations/translations'], {
93+
cwd: __dirname,
94+
});
95+
});
96+
97+
test('with unused translations', async () => {
98+
let { stdout } = await execa('node', ['../../bin/cli', '--fix'], {
99+
cwd: `${__dirname}/fixtures/remove-unused-translations`,
100+
});
101+
102+
expect(stdout).toMatch('All unused translations were removed');
103+
});
104+
});
105+
});

0 commit comments

Comments
 (0)