├── .dependabot └── config.yml ├── .gitignore ├── .travis.yml ├── README.md ├── commitlint.config.js ├── jest-preset.js ├── package-lock.json ├── package.json ├── src ├── __fixtures__ │ ├── bad.css │ ├── good.css │ ├── jest-runner-stylelint.config.js │ └── stylelint.config.js ├── __snapshots__ │ └── run.test.js.snap ├── configOverrides.js ├── index.js ├── run.js ├── run.test.js ├── utils │ ├── __tests__ │ │ ├── getCliOptions.test.js │ │ └── normalizeConfig.test.js │ ├── getCliOptions.js │ └── normalizeConfig.js ├── watchFixPlugin.js └── watchFixPlugin.test.js └── watch-fix.js /.dependabot/config.yml: -------------------------------------------------------------------------------- 1 | version: 1 2 | update_configs: 3 | - package_manager: "javascript" 4 | directory: "/" 5 | update_schedule: "live" 6 | commit_message: 7 | prefix: "fix" 8 | prefix_development: "chore" 9 | include_scope: true 10 | automerged_updates: 11 | - match: 12 | dependency_type: "all" 13 | update_type: "all" 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/node 3 | 4 | ### Node ### 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | yarn-debug.log* 10 | yarn-error.log* 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | 24 | # nyc test coverage 25 | .nyc_output 26 | 27 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 28 | .grunt 29 | 30 | # Bower dependency directory (https://bower.io/) 31 | bower_components 32 | 33 | # node-waf configuration 34 | .lock-wscript 35 | 36 | # Compiled binary addons (http://nodejs.org/api/addons.html) 37 | build/Release 38 | 39 | # Dependency directories 40 | node_modules/ 41 | jspm_packages/ 42 | 43 | # Typescript v1 declaration files 44 | typings/ 45 | 46 | # Optional npm cache directory 47 | .npm 48 | 49 | # Optional eslint cache 50 | .eslintcache 51 | 52 | # Optional REPL history 53 | .node_repl_history 54 | 55 | # Output of 'npm pack' 56 | *.tgz 57 | 58 | # Yarn Integrity file 59 | .yarn-integrity 60 | 61 | # dotenv environment variables file 62 | .env 63 | 64 | 65 | # End of https://www.gitignore.io/api/node 66 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | env: 4 | global: 5 | - FORCE_COLOR=1 6 | 7 | node_js: 8 | - "node" 9 | - "lts/*" 10 | 11 | jobs: 12 | include: 13 | - stage: test 14 | script: 15 | - npm test 16 | after_success: 17 | - bash <(curl -s https://codecov.io/bash) 18 | - stage: release 19 | script: 20 | - npx semantic-release 21 | after_sucess: skip 22 | 23 | stages: 24 | - test 25 | - name: release 26 | if: branch = master AND type = push AND fork = false 27 | 28 | branches: 29 | except: 30 | - /^v\d+\.\d+\.\d+$/ 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/keplersj/jest-runner-stylelint.svg?branch=master)](https://travis-ci.org/keplersj/jest-runner-stylelint) 2 | [![npm version](https://badge.fury.io/js/jest-runner-stylelint.svg)](https://badge.fury.io/js/jest-runner-stylelint) 3 | [![codecov](https://codecov.io/gh/keplersj/jest-runner-stylelint/branch/master/graph/badge.svg)](https://codecov.io/gh/keplersj/jest-runner-stylelint) 4 | [![Mentioned in Awesome Jest](https://awesome.re/mentioned-badge.svg)](https://github.com/jest-community/awesome-jest) 5 | 6 |
7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |

jest-runner-stylelint

15 |

Stylelint runner for Jest

16 |
17 | 18 |
19 | 20 | 21 |
22 | 23 | ## Usage 24 | 25 | ### Install 26 | 27 | Install `jest`, `jest-runner-stylelint`, and `stylelint` 28 | 29 | ```bash 30 | npm install --save-dev jest jest-runner-stylelint stylelint 31 | 32 | # or with yarn 33 | 34 | yarn add --dev jest jest-runner-stylelint stylelint 35 | ``` 36 | 37 | ### Configure stylelint 38 | 39 | You must have stylelint configured before it'll lint any of your files. Please follow the [stylelint documentation on configuration](https://stylelint.io/user-guide/configuration) to create your config. 40 | 41 | ### Add it to your Jest config 42 | 43 | #### Using Built-in Preset 44 | 45 | This package includes a [Jest preset](https://jestjs.io/docs/en/configuration#preset-string) which configures Jest to run stylelint on all files supported by styleint. To use it set the following in your package.json: 46 | 47 | ```json 48 | { 49 | "jest": { 50 | "preset": "jest-runner-stylelint" 51 | } 52 | } 53 | ``` 54 | 55 | or jest.config.js: 56 | 57 | ```js 58 | module.exports = { 59 | preset: "jest-runner-stylelint", 60 | }; 61 | ``` 62 | 63 | #### Manually 64 | 65 | In your `package.json` 66 | 67 | ```json 68 | { 69 | "jest": { 70 | "runner": "stylelint", 71 | "moduleFileExtensions": [ 72 | "css", 73 | "sass", 74 | "scss", 75 | "less", 76 | "sss", 77 | "htm", 78 | "html", 79 | "md", 80 | "markdown", 81 | "mdx", 82 | "js", 83 | "jsx", 84 | "ts", 85 | "tsx", 86 | "vue" 87 | ], 88 | "testMatch": [ 89 | "**/*.css", 90 | "**/*.sass", 91 | "**/*.scss", 92 | "**/*.less", 93 | "**/*.sss", 94 | "**/*.htm", 95 | "**/*.html", 96 | "**/*.md", 97 | "**/*.markdown", 98 | "**/*.mdx", 99 | "**/*.js", 100 | "**/*.jsx", 101 | "**/*.ts", 102 | "**/*.tsx", 103 | "**/*.vue" 104 | ] 105 | } 106 | } 107 | ``` 108 | 109 | Or in `jest.config.js` 110 | 111 | ```js 112 | module.exports = { 113 | runner: "stylelint", 114 | moduleFileExtensions: [ 115 | "css", 116 | "sass", 117 | "scss", 118 | "less", 119 | "sss", 120 | "htm", 121 | "html", 122 | "md", 123 | "markdown", 124 | "mdx", 125 | "js", 126 | "jsx", 127 | "ts", 128 | "tsx", 129 | "vue", 130 | ], 131 | testMatch: [ 132 | "**/*.css", 133 | "**/*.sass", 134 | "**/*.scss", 135 | "**/*.less", 136 | "**/*.sss", 137 | "**/*.htm", 138 | "**/*.html", 139 | "**/*.md", 140 | "**/*.markdown", 141 | "**/*.mdx", 142 | "**/*.js", 143 | "**/*.jsx", 144 | "**/*.ts", 145 | "**/*.tsx", 146 | "**/*.vue", 147 | ], 148 | }; 149 | ``` 150 | 151 | ### Run Jest 152 | 153 | ```bash 154 | npx jest 155 | 156 | # or with yarn 157 | 158 | yarn jest 159 | ``` 160 | 161 | ## Toggle `--fix` in watch mode 162 | 163 | `jest-stylelint-runner` comes with a watch plugin that allows you to toggle the `--fix` value while in watch mode without having to update your configuration. 164 | 165 | To use this watch plugin simply add this to your Jest configuration. 166 | 167 | ```js 168 | { 169 | watchPlugins: ['jest-runner-stylelint/watch-fix'], 170 | } 171 | ``` 172 | 173 | After this run Jest in watch mode and you will see the following line in your watch usage menu. 174 | 175 | ``` 176 | › Press F to override Stylelint --fix. 177 | ``` 178 | 179 | ## Options 180 | 181 | This project uses [cosmiconfig](https://github.com/davidtheclark/cosmiconfig), so you can provide config via: 182 | 183 | - a `jest-runner-stylelint` property in your `package.json` 184 | - a `jest-runner-stylelint.config.js` JS file 185 | - a `.jest-runner-stylelintrc` JSON file 186 | 187 | In `package.json` 188 | 189 | ```json 190 | { 191 | "jest-runner-stylelint": { 192 | "cliOptions": { 193 | // Options here 194 | } 195 | } 196 | } 197 | ``` 198 | 199 | or in `jest-runner-stylelint.config.js` 200 | 201 | ```js 202 | module.exports = { 203 | cliOptions: { 204 | // Options here 205 | }, 206 | }; 207 | ``` 208 | 209 | ### cliOptions 210 | 211 | Follow the [stylelint documentation on configuration](https://stylelint.io/user-guide/cli#options) to create your cli options. 212 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { extends: ["@commitlint/config-conventional"] }; 2 | -------------------------------------------------------------------------------- /jest-preset.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | runner: "stylelint", 3 | moduleFileExtensions: [ 4 | "css", 5 | "sass", 6 | "scss", 7 | "less", 8 | "sss", 9 | "htm", 10 | "html", 11 | "md", 12 | "markdown", 13 | "mdx", 14 | "js", 15 | "jsx", 16 | "ts", 17 | "tsx", 18 | "vue", 19 | ], 20 | testMatch: [ 21 | "**/*.css", 22 | "**/*.sass", 23 | "**/*.scss", 24 | "**/*.less", 25 | "**/*.sss", 26 | "**/*.htm", 27 | "**/*.html", 28 | "**/*.md", 29 | "**/*.markdown", 30 | "**/*.mdx", 31 | "**/*.js", 32 | "**/*.jsx", 33 | "**/*.ts", 34 | "**/*.tsx", 35 | "**/*.vue", 36 | ], 37 | }; 38 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jest-runner-stylelint", 3 | "version": "0.0.0-development", 4 | "description": "Stylelint runner for Jest", 5 | "main": "src/index.js", 6 | "repository": "https://github.com/keplersj/jest-runner-stylelint", 7 | "author": "Kepler Sticka-Jones ", 8 | "license": "MIT", 9 | "private": false, 10 | "scripts": { 11 | "test": "jest" 12 | }, 13 | "husky": { 14 | "hooks": { 15 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS", 16 | "pre-commit": "lint-staged" 17 | } 18 | }, 19 | "lint-staged": { 20 | "*": [ 21 | "jest --bail --findRelatedTests" 22 | ] 23 | }, 24 | "release": { 25 | "verifyConditions": "@semantic-release/github" 26 | }, 27 | "jest": { 28 | "collectCoverage": true, 29 | "projects": [ 30 | { 31 | "displayName": "test", 32 | "collectCoverage": true 33 | }, 34 | { 35 | "displayName": "lint:prettier", 36 | "preset": "jest-runner-prettier", 37 | "testPathIgnorePatterns": [ 38 | "/node_modules/", 39 | "/coverage/" 40 | ] 41 | }, 42 | { 43 | "runner": "eslint", 44 | "displayName": "lint:eslint", 45 | "testMatch": [ 46 | "/**/*.js" 47 | ], 48 | "testPathIgnorePatterns": [ 49 | "/node_modules/", 50 | "/coverage/" 51 | ] 52 | } 53 | ] 54 | }, 55 | "dependencies": { 56 | "cosmiconfig": "^7.0.0", 57 | "create-jest-runner": "^0.7.0" 58 | }, 59 | "devDependencies": { 60 | "@commitlint/cli": "^13.1.0", 61 | "@commitlint/config-conventional": "^13.1.0", 62 | "eslint": "^6.8.0", 63 | "eslint-config-starstuff": "^1.4.42", 64 | "husky": "^7.0.0", 65 | "jest": "^27.0.4", 66 | "jest-runner-eslint": "^0.10.0", 67 | "jest-runner-prettier": "^0.3.6", 68 | "lint-staged": "^11.0.0", 69 | "prettier": "^2.0.5", 70 | "semantic-release": "^17.0.7", 71 | "stylelint": "^13.0.0", 72 | "stylelint-config-standard": "^22.0.0" 73 | }, 74 | "peerDependencies": { 75 | "stylelint": "*" 76 | }, 77 | "eslintConfig": { 78 | "extends": "starstuff/auto", 79 | "env": { 80 | "node": true 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/__fixtures__/bad.css: -------------------------------------------------------------------------------- 1 | img { 2 | width: 0px; 3 | height: 0px; 4 | } 5 | -------------------------------------------------------------------------------- /src/__fixtures__/good.css: -------------------------------------------------------------------------------- 1 | img { 2 | width: 0; 3 | height: 0; 4 | } 5 | -------------------------------------------------------------------------------- /src/__fixtures__/jest-runner-stylelint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | cliOptions: { 3 | allowEmptyInput: true, 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /src/__fixtures__/stylelint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: "stylelint-config-standard", 3 | }; 4 | -------------------------------------------------------------------------------- /src/__snapshots__/run.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`jest-runner-stylelint failing fixture matches snapshot 1`] = ` 4 | Object { 5 | "console": null, 6 | "failureMessage": " 7 | src/__fixtures__/bad.css 8 | 2:11 ✖ Unexpected unit length-zero-no-unit 9 | 3:12 ✖ Unexpected unit length-zero-no-unit 10 | 11 | ", 12 | "numFailingTests": 1, 13 | "numPassingTests": 0, 14 | "numPendingTests": 0, 15 | "numTodoTests": 0, 16 | "skipped": undefined, 17 | "snapshot": Object { 18 | "added": 0, 19 | "fileDeleted": false, 20 | "matched": 0, 21 | "unchecked": 0, 22 | "unmatched": 0, 23 | "updated": 0, 24 | }, 25 | "sourceMaps": Object {}, 26 | "testExecError": null, 27 | "testResults": Array [ 28 | Object { 29 | "ancestorTitles": Array [], 30 | "failureMessages": Array [ 31 | " 32 | src/__fixtures__/bad.css 33 | 2:11 ✖ Unexpected unit length-zero-no-unit 34 | 3:12 ✖ Unexpected unit length-zero-no-unit 35 | 36 | ", 37 | ], 38 | "fullName": undefined, 39 | "numPassingAsserts": 1, 40 | "status": "failed", 41 | "title": "", 42 | }, 43 | ], 44 | } 45 | `; 46 | 47 | exports[`jest-runner-stylelint passing fixture matches snapshot 1`] = ` 48 | Object { 49 | "console": null, 50 | "failureMessage": undefined, 51 | "numFailingTests": 0, 52 | "numPassingTests": 1, 53 | "numPendingTests": 0, 54 | "numTodoTests": 0, 55 | "skipped": undefined, 56 | "snapshot": Object { 57 | "added": 0, 58 | "fileDeleted": false, 59 | "matched": 0, 60 | "unchecked": 0, 61 | "unmatched": 0, 62 | "updated": 0, 63 | }, 64 | "sourceMaps": Object {}, 65 | "testExecError": null, 66 | "testResults": Array [ 67 | Object { 68 | "ancestorTitles": Array [], 69 | "failureMessages": Array [ 70 | undefined, 71 | ], 72 | "fullName": undefined, 73 | "numPassingAsserts": 0, 74 | "status": "passed", 75 | "title": "", 76 | }, 77 | ], 78 | } 79 | `; 80 | -------------------------------------------------------------------------------- /src/configOverrides.js: -------------------------------------------------------------------------------- 1 | class ConfigOverrides { 2 | setFix(fix) { 3 | this.fix = fix; 4 | } 5 | 6 | getFix() { 7 | return this.fix; 8 | } 9 | } 10 | 11 | const configOverrides = new ConfigOverrides(); 12 | 13 | module.exports = configOverrides; 14 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const { createJestRunner } = require("create-jest-runner"); 2 | module.exports = createJestRunner(require.resolve("./run")); 3 | -------------------------------------------------------------------------------- /src/run.js: -------------------------------------------------------------------------------- 1 | const { pass, fail } = require("create-jest-runner"); 2 | const stylelint = require("stylelint"); 3 | const configOverrides = require("./configOverrides"); 4 | const getCliOptions = require("./utils/getCliOptions"); 5 | 6 | module.exports = ({ testPath, config }) => { 7 | const start = new Date(); 8 | 9 | const defaultConfig = { 10 | files: testPath, 11 | formatter: "string", 12 | fix: configOverrides.getFix(), 13 | }; 14 | const { cliOptions = {} } = getCliOptions(config); 15 | 16 | return stylelint 17 | .lint(Object.assign({}, cliOptions, defaultConfig)) 18 | .then((data) => { 19 | if (data.errored) { 20 | return fail({ 21 | start, 22 | end: new Date(), 23 | test: { 24 | path: testPath, 25 | errorMessage: data.output, 26 | }, 27 | }); 28 | } 29 | 30 | return pass({ 31 | start, 32 | end: new Date(), 33 | test: { path: testPath }, 34 | }); 35 | }) 36 | .catch((error) => { 37 | throw error; 38 | }); 39 | }; 40 | -------------------------------------------------------------------------------- /src/run.test.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const run = require("./run"); 3 | 4 | // Remove undeterministic data from test reports 5 | expect.addSnapshotSerializer({ 6 | print: (value, serialize) => { 7 | delete value.perfStats; 8 | delete value.testFilePath; 9 | value.testResults.forEach((result) => { 10 | delete result.duration; 11 | }); 12 | return serialize(value); 13 | }, 14 | test: (value) => 15 | value && value.perfStats && value.testFilePath && value.testResults, 16 | }); 17 | 18 | describe("jest-runner-stylelint", () => { 19 | describe("failing fixture", () => { 20 | it("matches snapshot", () => 21 | run({ 22 | testPath: path.join(__dirname, "__fixtures__", "bad.css"), 23 | config: {}, 24 | globalConfig: {}, 25 | }).then((result) => expect(result).toMatchSnapshot())); 26 | }); 27 | 28 | describe("passing fixture", () => { 29 | it("matches snapshot", () => 30 | run({ 31 | testPath: path.join(__dirname, "__fixtures__", "good.css"), 32 | config: {}, 33 | globalConfig: {}, 34 | }).then((result) => expect(result).toMatchSnapshot())); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /src/utils/__tests__/getCliOptions.test.js: -------------------------------------------------------------------------------- 1 | const getCliOptions = require("../getCliOptions"); 2 | const path = require("path"); 3 | 4 | describe("getCliOptions", () => { 5 | it("check cli options in jest-runner-stylelint.config", () => { 6 | const rootDir = path.resolve(__dirname, "../../__fixtures__"); 7 | const config = getCliOptions({ rootDir }); 8 | 9 | expect(config).toEqual({ cliOptions: { allowEmptyInput: true } }); 10 | }); 11 | 12 | it("check cli options without config", () => { 13 | const rootDir = path.resolve(__dirname, "./"); 14 | const config = getCliOptions({ rootDir }); 15 | 16 | expect(config).toEqual({ cliOptions: {} }); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /src/utils/__tests__/normalizeConfig.test.js: -------------------------------------------------------------------------------- 1 | const normalizeConfig = require("../normalizeConfig"); 2 | 3 | describe("normalizeConfig", () => { 4 | it("check cliOptions", () => { 5 | const config = normalizeConfig({ cliOptions: { arg: "test arg" } }); 6 | expect(config).toEqual({ cliOptions: { arg: "test arg" } }); 7 | }); 8 | 9 | it("check default cliOptions", () => { 10 | const config = normalizeConfig({}); 11 | 12 | expect(config).toEqual({ cliOptions: {} }); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /src/utils/getCliOptions.js: -------------------------------------------------------------------------------- 1 | const { cosmiconfigSync } = require("cosmiconfig"); 2 | const normalizeConfig = require("./normalizeConfig"); 3 | 4 | const explorerSync = cosmiconfigSync("jest-runner-stylelint"); 5 | 6 | const getCliOptions = ({ rootDir }) => { 7 | const result = explorerSync.search(rootDir); 8 | const config = result === null ? {} : result.config; 9 | 10 | return normalizeConfig(config); 11 | }; 12 | 13 | module.exports = getCliOptions; 14 | -------------------------------------------------------------------------------- /src/utils/normalizeConfig.js: -------------------------------------------------------------------------------- 1 | const normalizeConfig = (config) => { 2 | return Object.assign({}, config, { 3 | cliOptions: config.cliOptions || {}, 4 | }); 5 | }; 6 | 7 | module.exports = normalizeConfig; 8 | -------------------------------------------------------------------------------- /src/watchFixPlugin.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line jest/no-jest-import 2 | const { getVersion: getJestVersion } = require("jest"); 3 | const configOverrides = require("./configOverrides"); 4 | 5 | const majorJestVersion = parseInt(getJestVersion().split(".")[0], 10); 6 | 7 | /* istanbul ignore if */ 8 | if (majorJestVersion < 23) { 9 | throw new Error(`Insufficient Jest version for jest-runner-stylelint watch plugin 10 | 11 | Watch plugins are only available in Jest 23.0.0 and above. 12 | Upgrade your version of Jest in order to use it. 13 | `); 14 | } 15 | 16 | function getPrompt() { 17 | const fix = configOverrides.getFix(); 18 | if (fix === undefined) { 19 | return "override Stylelint --fix"; 20 | } 21 | if (!fix) { 22 | return "toggle Stylelint --fix (disabled)"; 23 | } 24 | return "toggle Stylelint --fix (enabled)"; 25 | } 26 | 27 | class StylelintWatchFixPlugin { 28 | constructor({ stdout, config }) { 29 | this._stdout = stdout; 30 | this._key = config.key || "F"; 31 | } 32 | 33 | async run() { 34 | const fix = configOverrides.getFix(); 35 | configOverrides.setFix(!fix); 36 | return true; 37 | } 38 | 39 | getUsageInfo() { 40 | return { 41 | key: this._key, 42 | prompt: getPrompt(), 43 | }; 44 | } 45 | } 46 | 47 | module.exports = StylelintWatchFixPlugin; 48 | -------------------------------------------------------------------------------- /src/watchFixPlugin.test.js: -------------------------------------------------------------------------------- 1 | jest.useFakeTimers(); 2 | 3 | let WatchFixPlugin; 4 | let configOverrides; 5 | 6 | describe("watchFixPlugin", () => { 7 | beforeEach(() => { 8 | jest.resetModules(); 9 | configOverrides = require("./configOverrides"); 10 | WatchFixPlugin = require("./watchFixPlugin"); 11 | }); 12 | 13 | it("shows the correct prompt", async () => { 14 | const stdout = { write: jest.fn() }; 15 | const config = {}; 16 | const plugin = new WatchFixPlugin({ stdout, config }); 17 | expect(plugin.getUsageInfo()).toEqual({ 18 | key: "F", 19 | prompt: "override Stylelint --fix", 20 | }); 21 | 22 | await plugin.run(plugin); 23 | 24 | expect(plugin.getUsageInfo()).toEqual({ 25 | key: "F", 26 | prompt: "toggle Stylelint --fix (enabled)", 27 | }); 28 | 29 | await plugin.run(plugin); 30 | 31 | expect(plugin.getUsageInfo()).toEqual({ 32 | key: "F", 33 | prompt: "toggle Stylelint --fix (disabled)", 34 | }); 35 | }); 36 | 37 | it("overrides the setting in configOverrides after each invocation", async () => { 38 | const stdout = { write: jest.fn() }; 39 | const config = {}; 40 | const plugin = new WatchFixPlugin({ stdout, config }); 41 | expect(configOverrides.getFix()).toBeUndefined(); 42 | 43 | await plugin.run(plugin); 44 | 45 | expect(configOverrides.getFix()).toBe(true); 46 | 47 | await plugin.run(plugin); 48 | 49 | expect(configOverrides.getFix()).toBe(false); 50 | }); 51 | 52 | it("can customize the key", () => { 53 | const stdout = { write: jest.fn() }; 54 | const config = { key: "z" }; 55 | const plugin = new WatchFixPlugin({ stdout, config }); 56 | expect(plugin.getUsageInfo()).toEqual({ 57 | key: "z", 58 | prompt: "override Stylelint --fix", 59 | }); 60 | }); 61 | }); 62 | -------------------------------------------------------------------------------- /watch-fix.js: -------------------------------------------------------------------------------- 1 | const StylelintWatchFixPlugin = require("./src/watchFixPlugin"); 2 | 3 | module.exports = StylelintWatchFixPlugin; 4 | --------------------------------------------------------------------------------