Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initial release #1

Merged
merged 5 commits into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ workflows:
- node9
- node8
- release:
filters:
branches:
only: master
requires:
- node-latest
- node9
Expand All @@ -24,11 +27,14 @@ jobs:
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: npm install
- run: npm install --no-save jest-junit
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
- run: npm run verify
- run: npm run verify-ci
- store_test_results:
path: reports/junit
node9:
docker:
- image: 'circleci/node:9'
Expand All @@ -41,11 +47,14 @@ jobs:
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: npm install
- run: npm install --no-save jest-junit
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
- run: npm run verify
- run: npm run verify-ci
- store_test_results:
path: reports/junit
node8:
docker:
- image: 'circleci/node:8'
Expand All @@ -58,11 +67,14 @@ jobs:
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: npm install
- run: npm install --no-save jest-junit
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
- run: npm run verify
- run: npm run verify-ci
- store_test_results:
path: reports/junit
release:
docker:
- image: 'circleci/node:10'
Expand Down
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

[![NPM version][npm-image]][npm-url]
[![NPM downloads][downloads-image]][downloads-url]
[![Build status][travis-image]][travis-url]
[![Build status][circleci-image]][circleci-url]
[![Codecov][codecov-image]][codecov-url]
[![Coverage Status][coveralls-image]][coveralls-url]

[![Greenkeeper badge][green-keeper-image]][green-keeper-url]
[![semantic-release][semantic-release-image]][semantic-release-url]
Expand All @@ -14,14 +13,14 @@ Pausing watch mode of [`jest`](https://jestjs.io/) when you want it to.
## Usage

To use `jest-watch-suspend`,
add it to the `reporters` section of the Jest configuration:
add it to the `watchPlugins` section of the Jest configuration:

```js
{
"jest": {
"watchPlugins": [
"jest-watch-suspend",
["jest-watch-suspend", { "key": "s", "prompt": "Suspend watch" }]
["jest-watch-suspend", { "key": "s", "prompt": "suspend watch mode" }]
["jest-watch-suspend", { "suspend-on-start": true }]
]
}
Expand All @@ -32,12 +31,10 @@ add it to the `reporters` section of the Jest configuration:
[npm-url]: https://npmjs.org/package/jest-watch-suspend
[downloads-image]: https://img.shields.io/npm/dm/jest-watch-suspend.svg?style=flat
[downloads-url]: https://npmjs.org/package/jest-watch-suspend
[travis-image]: https://img.shields.io/travis/unional/jest-watch-suspend/master.svg?style=flat
[travis-url]: https://travis-ci.org/unional/jest-watch-suspend?branch=master
[circleci-image]: https://circleci.com/gh/unional/jest-watch-suspend/tree/master.svg?style=shield
[circleci-url]: https://circleci.com/gh/unional/jest-watch-suspend/tree/master
[codecov-image]: https://codecov.io/gh/unional/jest-watch-suspend/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/unional/jest-watch-suspend
[coveralls-image]: https://coveralls.io/repos/github/unional/jest-watch-suspend/badge.svg
[coveralls-url]: https://coveralls.io/github/unional/jest-watch-suspend
[green-keeper-image]:
https://badges.greenkeeper.io/unional/jest-watch-suspend.svg
[green-keeper-url]:https://greenkeeper.io/
Expand Down
16 changes: 16 additions & 0 deletions jest.config.ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"preset": "ts-jest",
"roots": [
"<rootDir>/src"
],
"testEnvironment": "node",
"reporters": [
"default",
[
"jest-junit",
{
"output": "reports/junit/js-test-results.xml"
}
]
]
}
27 changes: 27 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"preset": "ts-jest",
"roots": [
"<rootDir>/src"
],
"testEnvironment": "node",
"watchPlugins": [
[
"<rootDir>/dist/index.js",
{
"suspend-on-start": true
}
],
[
"jest-watch-toggle-config",
{
"setting": "verbose"
}
],
[
"jest-watch-toggle-config",
{
"setting": "collectCoverage"
}
]
]
}
22 changes: 12 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 8 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
"name": "jest-watch-suspend",
"description": "Suspend watch mode",
"version": "0.0.0-development",
"main": "dist-es5/index.js",
"typings": "dist-es5/index.d.ts",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
"dist-es5"
"dist"
],
"scripts": {
"build": "tsc -p tsconfig.base.json",
"coverage": "jest --coverage",
"dependency-check": "dependency-check . --unused --no-dev && dependency-check . --missing --no-dev",
"lint": "tslint -p tsconfig.json 'src/**/*.ts'",
"test": "jest",
"verify-ci": "npm run lint && npm run build && jest --coverage --config jest.config.ci.json && npm run dependency-check",
"verify": "npm run lint && npm run build && npm run coverage && npm run dependency-check",
"watch": "tsc && jest --watch"
},
Expand All @@ -25,37 +26,18 @@
"url": "https://github.com/unional/jest-watch-suspend/issues"
},
"homepage": "https://github.com/unional/jest-watch-suspend",
"jest": {
"moduleFileExtensions": [
"ts",
"js"
],
"roots": [
"<rootDir>/src"
],
"testEnvironment": "node",
"testRegex": ".*.spec.ts$",
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"watchPlugins": [
[
"<rootDir>/dist/index.js",
{
"suspend-on-start": true
}
]
]
},
"devDependencies": {
"@types/jest": "^23.3.2",
"@types/node": "^10.10.3",
"dependency-check": "^3.2.1",
"jest": "^23.6.0",
"jest-watch-toggle-config": "^1.0.2",
"ts-jest": "^23.10.1",
"tslint": "^5.11.0",
"tslint-config-unional": "^0.9.6",
"typescript": "^3.0.3"
},
"dependencies": {}
"dependencies": {
"chalk": "^2.4.1"
}
}
21 changes: 15 additions & 6 deletions src/WatchSuspendPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import chalk from 'chalk'
let firstRun = true
export class WatchSuspendPlugin {
firstRun = true
globalConfig: jest.GlobalConfig = {} as any
firstRun = firstRun
log = console.info
config: { 'suspend-on-start': boolean, key: string, prompt: string }
suspend: boolean
constructor({ config }) {
Expand All @@ -10,14 +14,18 @@ export class WatchSuspendPlugin {
apply(jestHooks) {
jestHooks.shouldRunTestSuite(() => {
if (this.firstRun) {
this.firstRun = false
return !this.config['suspend-on-start']
firstRun = this.firstRun = false
if (this.config['suspend-on-start']) {
this.log(chalk.bold('\nTest is suspended on start.'))
return false
}
return true
}
return !this.suspend
})
jestHooks.onTestRunComplete(() => {
if (this.suspend) {
console.info(`Test is suspended.`)
this.log(this.globalConfig.verbose ? chalk.bold(`Test is suspended.`) : chalk.gray(`Test is suspended.`))
}
})
}
Expand All @@ -31,10 +39,11 @@ export class WatchSuspendPlugin {
}

// Executed when the key from `getUsageInfo` is input
run() {
run(globalConfig) {
this.globalConfig = globalConfig
this.suspend = !this.suspend
if (this.suspend) {
console.info('\nTest is suspended.')
this.log(chalk.bold('\nTest is suspended.'))
}
return Promise.resolve(!this.suspend)
}
Expand Down
Loading