-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for running from command line #492
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "missing-translations" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "no-issues" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "remove-unused-translations" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "unused-translations" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This dependency actually came with |
||
"jest": "27.5.1", | ||
"lerna-changelog": "2.2.0", | ||
"prettier": "2.6.2", | ||
|
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'); | ||
|
||
|
@@ -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, | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The auto-fix option actually changes the files, so this makes sure those changes are undone. It does feel a bit specific though, so any other ideas are welcome :) |
||
}); | ||
|
||
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'); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When running the
bin/cli
script from a fixture, thelet rootDir = pkgDir.sync();
line would return the root of this whole repo, because there is nopackage.json
in fixtures. Adding it with just a name fixed this.