Skip to content

Commit

Permalink
Add tests for running from command line
Browse files Browse the repository at this point in the history
  • Loading branch information
robinborst95 committed Apr 16, 2022
1 parent 97d7542 commit a2ded4e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fixtures/missing-translations/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "missing-translations"
}
3 changes: 3 additions & 0 deletions fixtures/no-issues/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "no-issues"
}
3 changes: 3 additions & 0 deletions fixtures/remove-unused-translations/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "remove-unused-translations"
}
3 changes: 3 additions & 0 deletions fixtures/unused-translations/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "unused-translations"
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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",
Expand Down
39 changes: 39 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const execa = require('execa');
const fs = require('fs');
const { run, generateFileList } = require('./index');

Expand Down Expand Up @@ -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');
});
});
});

0 comments on commit a2ded4e

Please sign in to comment.