Skip to content

Commit

Permalink
Refactor cli.test.js (#5266)
Browse files Browse the repository at this point in the history
This refactoring aims to make the code more readable by reducing duplication.

E.g.

```diff
-replaceBackslashes(path.join(fixturesPath, 'config-block-no-empty.json')),
+fixturesPath('config-block-no-empty.json'),
```
  • Loading branch information
ybiquitous committed Apr 30, 2021
1 parent d034cc2 commit 361c070
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/__tests__/cli.test.js
Expand Up @@ -8,7 +8,7 @@ const cli = require('../cli');
const pkg = require('../../package.json');
const replaceBackslashes = require('../testUtils/replaceBackslashes');

const fixturesPath = replaceBackslashes(path.join(__dirname, 'fixtures'));
const fixturesPath = (...elems) => replaceBackslashes(path.join(__dirname, 'fixtures', ...elems));
const { buildCLI } = cli;

jest.mock('get-stdin');
Expand Down Expand Up @@ -203,8 +203,8 @@ describe('CLI', () => {
await cli([
'--print-config',
'--config',
`${fixturesPath}/config-color-no-invalid-hex.json`,
`${fixturesPath}/invalid-hex.css`,
fixturesPath('config-color-no-invalid-hex.json'),
fixturesPath('invalid-hex.css'),
]);

expect(process.exitCode).toBeUndefined();
Expand All @@ -227,8 +227,8 @@ describe('CLI', () => {
await cli([
'--report-needless-disables',
'--config',
replaceBackslashes(path.join(fixturesPath, 'config-block-no-empty.json')),
replaceBackslashes(path.join(fixturesPath, 'empty-block-with-disables.css')),
fixturesPath('config-block-no-empty.json'),
fixturesPath('empty-block-with-disables.css'),
]);

expect(process.exitCode).toBe(2);
Expand All @@ -242,8 +242,8 @@ describe('CLI', () => {
it('reports disallowed disables', async () => {
await cli([
'--config',
replaceBackslashes(path.join(fixturesPath, 'config-block-no-empty-report-disables.json')),
replaceBackslashes(path.join(fixturesPath, 'empty-block-with-relevant-disable.css')),
fixturesPath('config-block-no-empty-report-disables.json'),
fixturesPath('empty-block-with-relevant-disable.css'),
]);

expect(process.exitCode).toBe(2);
Expand All @@ -258,8 +258,8 @@ describe('CLI', () => {
await cli([
'--report-descriptionless-disables',
'--config',
replaceBackslashes(path.join(fixturesPath, 'config-block-no-empty.json')),
replaceBackslashes(path.join(fixturesPath, 'empty-block-with-relevant-disable.css')),
fixturesPath('config-block-no-empty.json'),
fixturesPath('empty-block-with-relevant-disable.css'),
]);

expect(process.exitCode).toBe(2);
Expand All @@ -271,7 +271,7 @@ describe('CLI', () => {
});

it('--stdin', async () => {
await cli(['--stdin', '--config', `${fixturesPath}/config-no-empty-source.json`]);
await cli(['--stdin', '--config', fixturesPath('config-no-empty-source.json')]);

expect(process.exitCode).toBe(2);

Expand All @@ -285,8 +285,8 @@ describe('CLI', () => {
it('exits with non zero on unfound module in config', async () => {
await cli([
'--config',
replaceBackslashes(path.join(fixturesPath, 'config-require-unknown.js')),
replaceBackslashes(path.join(fixturesPath, 'empty-block-with-disables.css')),
fixturesPath('config-require-unknown.js'),
fixturesPath('empty-block-with-disables.css'),
]);

expect(process.exitCode).toEqual(1);
Expand Down

0 comments on commit 361c070

Please sign in to comment.