wdio-eslinter-service
Advanced tools
Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "wdio-eslinter-service", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha test/**.spec.js" | ||
}, | ||
@@ -25,4 +25,11 @@ "keywords": [ | ||
"@wdio/logger": "^7.5.3", | ||
"chai": "^4.3.6", | ||
"mocha": "^9.2.1", | ||
"webdriverio": "^7.5.7" | ||
}, | ||
"dependencies": { | ||
"eslint": "^8.11.0", | ||
"eslint-import-resolver-custom-alias": "^1.3.0", | ||
"eslint-plugin-import": "^2.25.4" | ||
} | ||
} |
114
README.md
@@ -9,2 +9,3 @@ # wdio-eslinter-service | ||
The recommended configuration is to use the unresolved runner to just check missing imports, but if desired, you can also configure the service to run the eslinter in your project using the npm or yarn runner, or by passing in a flag that tells the system to use your .eslintrc configuration as well. | ||
@@ -19,15 +20,107 @@ ## Installation | ||
If you don't already have eslint installed and configured, you'll need to install it and configure it in your project: | ||
### Quick Start - Check for missing or unresolved imports only | ||
By default, this minimal configuration, the "unresolved" runner, checks for unresolved require imports and throws an error if unresolved imports are found. The service then stops execution. You can customize .eslintrc.js to perform more checks using the "npm" or "yarn" runners, if desired. See [eslint](https://www.npmjs.com/package/eslint) for more details. | ||
If you don't have an `.eslintrc.js` configuration in your project, then wdio-eslinter-service can be configured to use a default one which just checks for missing imports before running the tests. This is handy so that you find out about incorrect imports sooner rather than later. To configure this, add the following eslinter configuration to your services array (assuming you already are using the chromedriver service; otherwise, leave that part out): | ||
**wdio.conf.js:** | ||
``` | ||
services: ['chromedriver', [ | ||
'eslinter', | ||
{ | ||
runnerType: 'unresolved' | ||
} | ||
]], | ||
``` | ||
At this point, start running the tests, and if there is a missing or incorrect import, WebdriverIO will log it and immediately terminate the test run: | ||
``` | ||
$ npx wdio | ||
``` | ||
#### Optional - if using module-alias | ||
If you're using the [module-alias](https://www.npmjs.com/package/module-alias) module, which lets you configure aliases to replace relative paths, you'll need to pass that into the eslinter configuration using the eslint-import-resolver-custom-alias plugin. Below is an example: | ||
``` | ||
services: ['chromedriver', [ | ||
'eslinter', | ||
{ | ||
runnerType: 'unresolved', | ||
eslintOverride: { | ||
"settings": { | ||
"import/resolver": { | ||
"eslint-import-resolver-custom-alias": { | ||
"alias": { | ||
"@utils": "./utils", | ||
"@specs": "./test-sync/specs", | ||
"@pageobjects": "./test-sync/pageobjects", | ||
"@": "./" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
]], | ||
``` | ||
Install the plugin in your project: | ||
``` | ||
$ npm i eslint-import-resolver-custom-alias | ||
``` | ||
Run the tests and verify the system will find incorrect imports that use module aliases: | ||
``` | ||
$ npx wdio | ||
``` | ||
#### Experimental - Use along with an existing eslintrc configuration in your project | ||
To also have the eslinter service use an existing eslintrc configuration in your project, set `includeProjectEslintrc` to true in the wdio.conf.js configuration services array. | ||
I've experienced problems with conflicting plugins. If your project eslint setup is also looking for unresolved imports, then this may not work and may require adjustments to your .eslintrc.js. This is not recommended at this time. | ||
### Advanced Alternatives - Using the npm and yarn runners | ||
The npm and yarn runners help give you additional control over running an existing eslinter setup in your project. With this configuration, you can define extra commands to run in the run-scripts section in your package.json: | ||
Inside your `package.json`, add this entry to your run scripts: | ||
```json | ||
{ | ||
"scripts": { | ||
"eslint": "eslint ." | ||
} | ||
} | ||
``` | ||
**NOTE: Adding eslint to the package.json is required for the service to function when using the npm or yarn runners.** | ||
If you don't already have eslint installed and configured, you'll need to install it and configure it in your project, as well as any plugins you're using, such as eslint-plugin-import: | ||
``` | ||
$ npm i eslint eslint-plugin-import | ||
``` | ||
Put `.eslintrc.js` in the root of your Node.js project: | ||
If you're using eslint-import-resolver-custom-alias plugin to map module aliases to their real paths, then you'll need to install it as well: | ||
``` | ||
$ npm i eslint-import-resolver-custom-alias | ||
``` | ||
You'll also need to create an `.eslintrc.js` file, if you don't already have one of the eslintrc configuration files in your project. Here is a basic setup to just look for unresolved imports, and you can expand this configuration to validate other code quality checks before running tests: | ||
``` | ||
// .eslintrc.js | ||
module.exports = { | ||
"parserOptions": { | ||
"ecmaVersion": 2018 | ||
"ecmaVersion": 2022 | ||
}, | ||
@@ -50,17 +143,2 @@ "plugins": [ | ||
By default, this minimal configuration checks for unresolved require imports and throws an error if unresolved imports are found. The service then stops execution. You can customize .eslintrc.js to perform more checks, if desired. See [eslint](https://www.npmjs.com/package/eslint) for more details. | ||
Inside your `package.json`, add this entry to your run scripts: | ||
```json | ||
{ | ||
"scripts": { | ||
"eslint": "eslint ." | ||
} | ||
} | ||
``` | ||
**NOTE: Adding eslint to the package.json is required for the service to function.** | ||
Lastly, add the `eslinter` service to the services array in `wdio.conf.js`: | ||
@@ -67,0 +145,0 @@ |
@@ -5,6 +5,6 @@ // eslint-npm-runner.js | ||
module.exports = function (scriptName) { | ||
module.exports = function (opts) { | ||
return new Promise((resolve, reject) => { | ||
const npmCmd = process.platform.match('^win') !== null ? 'npm.cmd' : 'npm'; | ||
const eslint = spawn(npmCmd, ['run', scriptName, '--silent'], { stdio: "inherit" }); | ||
const eslint = spawn(npmCmd, ['run', opts.scriptName, '--silent'], { stdio: "inherit" }); | ||
@@ -11,0 +11,0 @@ eslint.on('close', (code) => { |
@@ -5,6 +5,6 @@ // eslint-yarn-runner.js | ||
module.exports = function (scriptName) { | ||
module.exports = function (opts) { | ||
return new Promise((resolve, reject) => { | ||
const yarnCmd = process.platform.match('^win') !== null ? 'yarn.cmd' : 'yarn'; | ||
const eslint = spawn(yarnCmd, ['run', '--silent', scriptName], { stdio: "inherit" }); | ||
const eslint = spawn(yarnCmd, ['run', '--silent', opts.scriptName], { stdio: "inherit" }); | ||
@@ -11,0 +11,0 @@ eslint.on('close', (code) => { |
@@ -12,2 +12,4 @@ const wdioLogger = require('@wdio/logger').default | ||
this.options.scriptName = 'eslint'; | ||
if(!this.options.includeProjectEslintrc) | ||
this.options.includeProjectEslintrc = false; | ||
logger.warn(`initialize wdio-eslinter-service using ${this.options.runnerType} runner.`) | ||
@@ -20,3 +22,3 @@ } | ||
const runEslint = require(`./eslint-${this.options.runnerType}-runner`) | ||
return runEslint(this.options.scriptName).then((code) => { | ||
return runEslint(this.options).then((code) => { | ||
logger.info('eslint checks passed...') | ||
@@ -28,3 +30,7 @@ resolve() | ||
}).catch((err) => { | ||
logger.error('SEVERE: Code contains eslint errors or eslint not installed. Exiting...') | ||
const type = this.options.runnerType | ||
if(customErrorHandlerExists(type)) | ||
handleErrorsWithErrorHandler(type, err) | ||
else | ||
logger.error('SEVERE: Code contains eslint errors or eslint not installed. Exiting...') | ||
process.exit(1) | ||
@@ -35,2 +41,15 @@ }) | ||
const fs = require('fs') | ||
function customErrorHandlerExists(type) { | ||
const eslintErrorHandlerFile = `eslint-${type}-error-handler.js` | ||
return fs.existsSync(`node_modules/wdio-eslinter-service/src/${eslintErrorHandlerFile}`) | ||
} | ||
function handleErrorsWithErrorHandler(type, err) { | ||
const eslintErrorHandlerFile = `eslint-${type}-error-handler.js` | ||
const eslintErrorHandler = require(`./${eslintErrorHandlerFile}`) | ||
eslintErrorHandler.handleError(err) | ||
} | ||
module.exports = EslintLauncherService; |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
14995
12
189
1
193
3
4
3
3
+ Addedeslint@^8.11.0
+ Addedeslint-plugin-import@^2.25.4
+ Added@eslint-community/eslint-utils@4.4.1(transitive)
+ Added@eslint-community/regexpp@4.12.1(transitive)
+ Added@eslint/eslintrc@2.1.4(transitive)
+ Added@eslint/js@8.57.1(transitive)
+ Added@humanwhocodes/config-array@0.13.0(transitive)
+ Added@humanwhocodes/module-importer@1.0.1(transitive)
+ Added@humanwhocodes/object-schema@2.0.3(transitive)
+ Added@nodelib/fs.scandir@2.1.5(transitive)
+ Added@nodelib/fs.stat@2.0.5(transitive)
+ Added@nodelib/fs.walk@1.2.8(transitive)
+ Added@rtsao/scc@1.1.0(transitive)
+ Added@types/json5@0.0.29(transitive)
+ Added@ungap/structured-clone@1.3.0(transitive)
+ Addedacorn@8.14.0(transitive)
+ Addedacorn-jsx@5.3.2(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedargparse@2.0.1(transitive)
+ Addedarray-buffer-byte-length@1.0.2(transitive)
+ Addedarray-includes@3.1.8(transitive)
+ Addedarray.prototype.findlastindex@1.2.5(transitive)
+ Addedarray.prototype.flat@1.3.3(transitive)
+ Addedarray.prototype.flatmap@1.3.3(transitive)
+ Addedarraybuffer.prototype.slice@1.0.4(transitive)
+ Addedasync-function@1.0.0(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcall-bind@1.0.8(transitive)
+ Addedcall-bind-apply-helpers@1.0.2(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addedcallsites@3.1.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedcross-spawn@7.0.6(transitive)
+ Addeddata-view-buffer@1.0.2(transitive)
+ Addeddata-view-byte-length@1.0.2(transitive)
+ Addeddata-view-byte-offset@1.0.1(transitive)
+ Addeddebug@3.2.74.4.0(transitive)
+ Addeddeep-is@0.1.4(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addeddoctrine@2.1.03.0.0(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-abstract@1.23.9(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedes-set-tostringtag@2.1.0(transitive)
+ Addedes-shim-unscopables@1.1.0(transitive)
+ Addedes-to-primitive@1.3.0(transitive)
+ Addedescape-string-regexp@4.0.0(transitive)
+ Addedeslint@8.57.1(transitive)
+ Addedeslint-import-resolver-custom-alias@1.3.2(transitive)
+ Addedeslint-import-resolver-node@0.3.9(transitive)
+ Addedeslint-module-utils@2.12.0(transitive)
+ Addedeslint-plugin-import@2.31.0(transitive)
+ Addedeslint-scope@7.2.2(transitive)
+ Addedeslint-visitor-keys@3.4.3(transitive)
+ Addedespree@9.6.1(transitive)
+ Addedesquery@1.6.0(transitive)
+ Addedesrecurse@4.3.0(transitive)
+ Addedestraverse@5.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedfastq@1.19.0(transitive)
+ Addedfile-entry-cache@6.0.1(transitive)
+ Addedfind-up@5.0.0(transitive)
+ Addedflat-cache@3.2.0(transitive)
+ Addedflatted@3.3.2(transitive)
+ Addedfor-each@0.3.5(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedfunction.prototype.name@1.1.8(transitive)
+ Addedfunctions-have-names@1.2.3(transitive)
+ Addedget-intrinsic@1.2.7(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedget-symbol-description@1.1.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedglob-parent@6.0.2(transitive)
+ Addedglobals@13.24.0(transitive)
+ Addedglobalthis@1.0.4(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedgraphemer@1.4.0(transitive)
+ Addedhas-bigints@1.1.0(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.2.0(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedignore@5.3.2(transitive)
+ Addedimport-fresh@3.3.1(transitive)
+ Addedimurmurhash@0.1.4(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedinternal-slot@1.1.0(transitive)
+ Addedis-array-buffer@3.0.5(transitive)
+ Addedis-async-function@2.1.1(transitive)
+ Addedis-bigint@1.1.0(transitive)
+ Addedis-boolean-object@1.2.2(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-core-module@2.16.1(transitive)
+ Addedis-data-view@1.0.2(transitive)
+ Addedis-date-object@1.1.0(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-finalizationregistry@1.1.1(transitive)
+ Addedis-generator-function@1.1.0(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-map@2.0.3(transitive)
+ Addedis-number-object@1.1.1(transitive)
+ Addedis-path-inside@3.0.3(transitive)
+ Addedis-regex@1.2.1(transitive)
+ Addedis-set@2.0.3(transitive)
+ Addedis-shared-array-buffer@1.0.4(transitive)
+ Addedis-string@1.1.1(transitive)
+ Addedis-symbol@1.1.1(transitive)
+ Addedis-typed-array@1.1.15(transitive)
+ Addedis-weakmap@2.0.2(transitive)
+ Addedis-weakref@1.1.1(transitive)
+ Addedis-weakset@2.0.4(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjs-yaml@4.1.0(transitive)
+ Addedjson-buffer@3.0.1(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stable-stringify-without-jsonify@1.0.1(transitive)
+ Addedjson5@1.0.2(transitive)
+ Addedkeyv@4.5.4(transitive)
+ Addedlevn@0.4.1(transitive)
+ Addedlocate-path@6.0.0(transitive)
+ Addedlodash.merge@4.6.2(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedms@2.1.3(transitive)
+ Addednatural-compare@1.4.0(transitive)
+ Addedobject-inspect@1.13.4(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedobject.assign@4.1.7(transitive)
+ Addedobject.fromentries@2.0.8(transitive)
+ Addedobject.groupby@1.0.3(transitive)
+ Addedobject.values@1.2.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedoptionator@0.9.4(transitive)
+ Addedown-keys@1.0.1(transitive)
+ Addedp-limit@3.1.0(transitive)
+ Addedp-locate@5.0.0(transitive)
+ Addedparent-module@1.0.1(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpossible-typed-array-names@1.1.0(transitive)
+ Addedprelude-ls@1.2.1(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedreflect.getprototypeof@1.0.10(transitive)
+ Addedregexp.prototype.flags@1.5.4(transitive)
+ Addedresolve@1.22.10(transitive)
+ Addedresolve-from@4.0.0(transitive)
+ Addedreusify@1.0.4(transitive)
+ Addedrimraf@3.0.2(transitive)
+ Addedrun-parallel@1.2.0(transitive)
+ Addedsafe-array-concat@1.1.3(transitive)
+ Addedsafe-push-apply@1.0.0(transitive)
+ Addedsafe-regex-test@1.1.0(transitive)
+ Addedsemver@6.3.1(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedset-function-name@2.0.2(transitive)
+ Addedset-proto@1.0.0(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedside-channel@1.1.0(transitive)
+ Addedside-channel-list@1.0.0(transitive)
+ Addedside-channel-map@1.0.1(transitive)
+ Addedside-channel-weakmap@1.0.2(transitive)
+ Addedstring.prototype.trim@1.2.10(transitive)
+ Addedstring.prototype.trimend@1.0.9(transitive)
+ Addedstring.prototype.trimstart@1.0.8(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedstrip-bom@3.0.0(transitive)
+ Addedstrip-json-comments@3.1.1(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtext-table@0.2.0(transitive)
+ Addedtsconfig-paths@3.15.0(transitive)
+ Addedtype-check@0.4.0(transitive)
+ Addedtype-fest@0.20.2(transitive)
+ Addedtyped-array-buffer@1.0.3(transitive)
+ Addedtyped-array-byte-length@1.0.3(transitive)
+ Addedtyped-array-byte-offset@1.0.4(transitive)
+ Addedtyped-array-length@1.0.7(transitive)
+ Addedunbox-primitive@1.1.0(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedwhich-boxed-primitive@1.1.1(transitive)
+ Addedwhich-builtin-type@1.2.1(transitive)
+ Addedwhich-collection@1.0.2(transitive)
+ Addedwhich-typed-array@1.1.18(transitive)
+ Addedword-wrap@1.2.5(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedyocto-queue@0.1.0(transitive)