From 13a0d3076be526764910f2db24ce15e034549111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominique=20M=C3=BCller?= Date: Tue, 9 Mar 2021 00:36:04 +0100 Subject: [PATCH] fix(bin): Fix bin execution (#57) - Fix bin name - Fix bin import - Fix bin process exit code - Fix docs Closes #48. --- README.md | 52 +++++++++++++------- bin/no-skipped-tests.js | 17 ++++--- package.json | 105 ++++++++++++++++++---------------------- 3 files changed, 90 insertions(+), 84 deletions(-) diff --git a/README.md b/README.md index e699f5b..26f3fed 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,11 @@ **Analyzes your project for focused or ignored tests.** -[![npm version](https://img.shields.io/npm/v/no-skipped-tests.svg?maxAge=3600&style=flat)](https://www.npmjs.com/package/no-skipped-tests) -[![dependency status](https://img.shields.io/david/dominique-mueller/no-skipped-tests.svg?maxAge=3600&style=flat)](https://david-dm.org/dominique-mueller/no-skipped-tests) -[![travis ci build status](https://img.shields.io/travis/dominique-mueller/no-skipped-tests/master.svg?maxAge=3600&style=flat)](https://travis-ci.org/dominique-mueller/no-skipped-tests) -[![Codecov](https://img.shields.io/codecov/c/github/dominique-mueller/no-skipped-tests.svg?maxAge=3600&style=flat)](https://codecov.io/gh/dominique-mueller/no-skipped-tests) -[![Known Vulnerabilities](https://snyk.io/test/github/dominique-mueller/no-skipped-tests/badge.svg)](https://snyk.io/test/github/dominique-mueller/no-skipped-tests) -[![license](https://img.shields.io/npm/l/no-skipped-tests.svg?maxAge=3600&style=flat)](https://github.com/dominique-mueller/no-skipped-tests/LICENSE) +[![npm version](https://img.shields.io/npm/v/no-skipped-tests?style=flat-square)](https://www.npmjs.com/package/no-skipped-tests) +[![travis ci build status](https://img.shields.io/travis/dominique-mueller/no-skipped-tests/master?style=flat-square)](https://travis-ci.org/dominique-mueller/no-skipped-tests) +[![Codecov](https://img.shields.io/codecov/c/github/dominique-mueller/no-skipped-tests/master?style=flat-square)](https://codecov.io/gh/dominique-mueller/no-skipped-tests) +[![Known Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/github/dominique-mueller/no-skipped-tests?style=flat-square)](https://snyk.io/test/github/dominique-mueller/no-skipped-tests) +[![license](https://img.shields.io/github/license/dominique-mueller/no-skipped-tests?flat-square)](https://github.com/dominique-mueller/no-skipped-tests/LICENSE) @@ -32,23 +31,38 @@ The **no-skipped-tests** is here to help; it is a NodeJS-based command line tool You can get **no-skipped-tests** via **npm** by either adding it as a new devDependency to your `package.json` file and running `npm install`, or running the following command: -``` bash +```bash npm install no-skipped-tests --save-dev ``` -### Requirements +**Requirements** -- **no-skipped-tests** requires at least **NodeJS 7.6** (or higher). *Earlier 7.x versions of NodeJS (7.0 to 7.5) might also work when -executing **no-skipped-tests** using the `--harmony-async-await` flag.* +- **no-skipped-tests** requires at least **NodeJS 7.6** (or higher). _Earlier 7.x versions of NodeJS (7.0 to 7.5) might also work when + executing **no-skipped-tests** using the `--harmony-async-await` flag._

## How to use -Using **no-skipped-tests** is very straightforward: Simply call it within one of the scripts of your `package.json` file. For instance, you -can let it get executed automatically before every test by using the `pretest` script: +The most common way to use **no-skipped-tests** is adding it to the scripts area within your `package.json` file. For example: -``` json +```json +{ + "scripts": { + "no-skipped-tests": "no-skipped-tests" + } +} +``` + +Then, execute it by running: + +```bash +npm run no-skipped-tests +``` + +You can also let npm run **no-skipped-tests** automatically before every test execution by using the `pretest` script: + +```json { "scripts": { "pretest": "no-skipped-tests" @@ -56,18 +70,20 @@ can let it get executed automatically before every test by using the `pretest` s } ``` -Alternatively, you can also run it manually: +Alternatively, if you want to run **no-skipped-tests** from scratch, you can use an `npx` command: -``` bash -npm run pretest +```bash +npx no-skipped-tests ``` +
+ ### Configuration -By default, **no-skipped-tests** will analyue all test files within your source folder: `src/**/*.spec.@(ts|js)`. However, your project +By default, **no-skipped-tests** will analyze all test files within your source folder: `src/**/*.spec.@(ts|js)`. However, your project might have a different naming convention or directory structure. Thus, you might provide a custom file pattern instead. For instance: -``` json +```json { "scripts": { "pretest": "no-skipped-tests src/app/**/*.test.ts" diff --git a/bin/no-skipped-tests.js b/bin/no-skipped-tests.js index 503a1e1..fcf359a 100644 --- a/bin/no-skipped-tests.js +++ b/bin/no-skipped-tests.js @@ -2,9 +2,7 @@ 'use strict'; -const chalk = require( 'chalk' ); - -const analyzeFilesForSkippedTests = require( './../dist/index' ).analyzeFilesForSkippedTests; +const analyzeFilesForSkippedTests = require( './../index' ).analyzeFilesForSkippedTests; // Collect command line parameters (only source pattern for now) const parameters = process.argv.slice( 2 ); @@ -18,11 +16,14 @@ console.log( '' ); analyzeFilesForSkippedTests( options ) .then( ( results ) => { console.log( '' ); - if ( results.length === 0 ) { - process.exit( 0 ); - } else { - process.exit( 1 ); - } + const hasErrors = results + .map((result) => { + return result.errors.length; + }) + .reduce((a, b) => { + return a + b; + }) + process.exit( hasErrors ? 1 : 0 ); } ) .catch( ( error ) => { console.log( '' ); diff --git a/package.json b/package.json index cb16501..9650e06 100644 --- a/package.json +++ b/package.json @@ -1,60 +1,49 @@ { - "name": "no-skipped-tests", - "description": "Analyzes your project for focused or ignored tests.", - "version": "1.0.0", - "author": { - "name": "Dominique Müller", - "email": "dominique.m.mueller@gmail.com", - "url": "https://www.devdom.io/" - }, - "license": "MIT", - "repository": { - "type": "git", - "url": "https://github.com/dominique-mueller/no-skipped-tests.git" - }, - "homepage": "https://github.com/dominique-mueller/no-skipped-tests", - "bugs": { - "url": "https://github.com/dominique-mueller/no-skipped-tests/issues" - }, - "keywords": [ - "test", - "skip", - "fdescribe", - "xdescribe", - "fit", - "xit", - "jasmine", - "karma", - "angular", - "typescript", - "javascript" - ], - "main": "index.js", - "types": "index.d.ts", - "bin": { - "automatic-release": "bin/no-skipped-tests.js" - }, - "scripts": { - "build": "tsc -p tsconfig.json && copyfiles \"bin/**\" dist", - "clean": "rimraf -r dist/*", - "release": "automatic-release && copyfiles \"docs/**\" package.json CHANGELOG.md LICENSE README.md dist", - "test:coverage": "codecov -f coverage/coverage-final.json", - "test": "jest --config jest.config.json --runInBand --no-cache" - }, - "dependencies": { - "chalk": "2.4.x", - "glob": "7.1.x", - "ora": "3.0.x", - "typescript": "3.0.x" - }, - "devDependencies": { - "@types/jest": "23.1.x", - "@types/node": "8.10.x", - "automatic-release": "1.1.x", - "codecov": "3.0.x", - "copyfiles": "2.1.x", - "jest": "23.5.x", - "rimraf": "2.6.x", - "ts-jest": "22.4.x" - } + "name": "no-skipped-tests", + "description": "Analyzes your project for focused or ignored tests", + "version": "1.0.0", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/dominique-mueller/no-skipped-tests.git" + }, + "keywords": [ + "test", + "skip", + "fdescribe", + "xdescribe", + "fit", + "xit", + "jasmine", + "karma", + "angular", + "typescript", + "javascript" + ], + "main": "index.js", + "types": "index.d.ts", + "bin": { + "no-skipped-tests": "bin/no-skipped-tests.js" + }, + "scripts": { + "build": "rimraf -r dist && tsc -p tsconfig.json && copyfiles \"bin/**\" \"docs/**\" package.json CHANGELOG.md LICENSE README.MD dist", + "test:coverage": "codecov -f coverage/coverage-final.json", + "test": "jest --config jest.config.json --runInBand --no-cache" + }, + "dependencies": { + "chalk": "2.4.x", + "glob": "7.1.x", + "ora": "3.0.x", + "typescript": "3.0.x" + }, + "devDependencies": { + "@types/jest": "23.1.x", + "@types/node": "8.10.x", + "automatic-release": "1.1.x", + "codecov": "3.0.x", + "copyfiles": "2.1.x", + "jest": "23.5.x", + "rimraf": "2.6.x", + "ts-jest": "22.4.x" + } }