Skip to content

Commit

Permalink
Remove ora loading indicator and small style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeliog committed Oct 1, 2018
1 parent dc8ff6e commit 8ba5cb6
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 87 deletions.
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,20 @@ yarn jest

## Toggle `--fix` in watch mode

`jest-eslint-runner` comes with a watch plugin that allows you to toggle the `--fix` value
while in watch mode without having to update your configuration.
`jest-eslint-runner` comes with a watch plugin that allows you to toggle the `--fix` value while in watch mode without having to update your configuration.

![fix](https://user-images.githubusercontent.com/574806/46181271-93205080-c279-11e8-8d73-b4c5e11086c4.gif)


To use this watch plugin simply add this to your Jest configuration.

```js
{
watchPlugins: ['jest-runner-eslint/watch-fix'],
}
```

After this run Jest in watch mode and you will see the following line in your watch usage menu

```
› Press F to override ESLint --fix.
```
Expand Down Expand Up @@ -194,12 +194,6 @@ module.exports = {
};
```

<<<<<<< HEAD
###


=======
>>>>>>> master
### cliOptions

jest-runner-eslint maps a lot of ESLint CLI arguments to config options. For example `--fix` is `cliOptions.fix`
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"cosmiconfig": "^5.0.0",
"create-jest-runner": "^0.4.1",
"eslint": "^5.6.0",
"find-up": "^3.0.0",
"ora": "^3.0.0"
"find-up": "^3.0.0"
},
"devDependencies": {
"@babel/cli": "^7.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/runner/__tests__/runESLint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const runESLintRunnerWithMockedEngine = options => {
});
const runESLint = require('../runESLint');

return runESLint(Object.assign({ extraOptions: {} }, options.runESLint));
return runESLint({ extraOptions: {}, ...options.runESLint });
};

it('Requires the config setupTestFrameworkScriptFile when specified', () => {
Expand Down
16 changes: 6 additions & 10 deletions src/runner/runESLint.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ const runESLint = ({ testPath, config, extraOptions }) => {

const { CLIEngine } = getLocalESLint(config);
const { cliOptions: baseCliOptions } = getESLintOptions(config);
const cliOptions = Object.assign(
{},
baseCliOptions,
{
fix: getComputedFixValue(baseCliOptions),
},
{
fix: extraOptions.fix,
},
);
const cliOptions = {
...baseCliOptions,
fix: getComputedFixValue(baseCliOptions),
...extraOptions,
};

const cli = new CLIEngine(cliOptions);

if (cli.isPathIgnored(testPath)) {
Expand Down
15 changes: 4 additions & 11 deletions src/watchFixPlugin/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ jest.useFakeTimers();
let WatchFixPlugin;
let configOverrides;

const runAndAwait = async plugin => {
const runPromise = plugin.run();
await jest.runTimersToTime(700);
await jest.runTimersToTime(500);
return runPromise;
};

describe('watchFixPlugin', () => {
beforeEach(() => {
jest.resetModules();
Expand All @@ -31,14 +24,14 @@ describe('watchFixPlugin', () => {
prompt: 'override ESLint --fix',
});

await runAndAwait(plugin);
await plugin.run(plugin);

expect(plugin.getUsageInfo()).toEqual({
key: 'F',
prompt: 'toggle ESLint --fix (enabled)',
});

await runAndAwait(plugin);
await plugin.run(plugin);

expect(plugin.getUsageInfo()).toEqual({
key: 'F',
Expand All @@ -52,11 +45,11 @@ describe('watchFixPlugin', () => {
const plugin = new WatchFixPlugin({ stdout, config });
expect(configOverrides.getFix()).toBeUndefined();

await runAndAwait(plugin);
await plugin.run(plugin);

expect(configOverrides.getFix()).toBe(true);

await runAndAwait(plugin);
await plugin.run(plugin);

expect(configOverrides.getFix()).toBe(false);
});
Expand Down
16 changes: 0 additions & 16 deletions src/watchFixPlugin/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
const chalk = require('chalk');
const ora = require('ora');
const configOverrides = require('../utils/configOverrides');

const wait = time => new Promise(res => setTimeout(res, time));

class ESLintWatchFixPlugin {
constructor({ stdout, config }) {
this._stdout = stdout;
Expand All @@ -14,7 +11,6 @@ class ESLintWatchFixPlugin {
async run() {
const fix = configOverrides.getFix();
configOverrides.setFix(!fix);
await this._showLoading(fix);
return true;
}

Expand All @@ -25,18 +21,6 @@ class ESLintWatchFixPlugin {
};
}

async _showLoading(fix) {
this._stdout.write('\n');
const spinner = ora({
text: chalk.italic.dim(`${fix ? 'Disabling' : 'Enabling'} ESLint --fix`),
stream: this._stdout,
}).start();

await wait(700);
spinner.succeed();
await wait(500);
}

// eslint-disable-next-line class-methods-use-this
_getPrompt() {
const fix = configOverrides.getFix();
Expand Down
39 changes: 1 addition & 38 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ chalk@^1.1.3:
strip-ansi "^3.0.0"
supports-color "^2.0.0"

chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.1, chalk@^2.4.1:
chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e"
dependencies:
Expand Down Expand Up @@ -1128,10 +1128,6 @@ cli-cursor@^2.1.0:
dependencies:
restore-cursor "^2.0.0"

cli-spinners@^1.1.0:
version "1.3.1"
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-1.3.1.tgz#002c1990912d0d59580c93bd36c056de99e4259a"

cli-width@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.2.0.tgz#ff19ede8a9a5e579324147b0c11f0fbcbabed639"
Expand All @@ -1152,10 +1148,6 @@ cliui@^4.0.0:
strip-ansi "^4.0.0"
wrap-ansi "^2.0.0"

clone@^1.0.2:
version "1.0.4"
resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e"

co@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"
Expand Down Expand Up @@ -1325,12 +1317,6 @@ default-require-extensions@^1.0.0:
dependencies:
strip-bom "^2.0.0"

defaults@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"
dependencies:
clone "^1.0.2"

define-properties@^1.1.2:
version "1.1.3"
resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1"
Expand Down Expand Up @@ -3077,12 +3063,6 @@ lodash@^4.13.1, lodash@^4.14.0, lodash@^4.17.10, lodash@^4.17.4, lodash@^4.17.5,
version "4.17.11"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"

log-symbols@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-2.2.0.tgz#5740e1c5d6f0dfda4ad9323b5332107ef6b4c40a"
dependencies:
chalk "^2.0.1"

longest@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
Expand Down Expand Up @@ -3454,17 +3434,6 @@ optionator@^0.8.1, optionator@^0.8.2:
type-check "~0.3.2"
wordwrap "~1.0.0"

ora@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/ora/-/ora-3.0.0.tgz#8179e3525b9aafd99242d63cc206fd64732741d0"
dependencies:
chalk "^2.3.1"
cli-cursor "^2.1.0"
cli-spinners "^1.1.0"
log-symbols "^2.2.0"
strip-ansi "^4.0.0"
wcwidth "^1.0.1"

os-homedir@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3"
Expand Down Expand Up @@ -4529,12 +4498,6 @@ watch@~0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/watch/-/watch-0.10.0.tgz#77798b2da0f9910d595f1ace5b0c2258521f21dc"

wcwidth@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8"
dependencies:
defaults "^1.0.3"

webidl-conversions@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
Expand Down

0 comments on commit 8ba5cb6

Please sign in to comment.