Starts a server before the Jest tests and tears it down after.
Installations
npm install jest-process-manager
Developer
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
18.18.2
NPM Version
9.8.1
Statistics
19 Stars
41 Commits
4 Forks
4 Watching
3 Branches
7 Contributors
Updated on 14 Jun 2024
Languages
TypeScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
56,722,492
Last day
-4.9%
182,624
Compared to previous day
Last week
1.1%
1,009,003
Compared to previous week
Last month
11.7%
4,254,603
Compared to previous month
Last year
139.6%
34,855,063
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
jest-process-manager
This project was forked because the package jest-dev-server
is no longer maintained.
Starts a server before your Jest tests and tears it down after.
Why
jest-playwright-preset
or jest-puppeteer
works great for running tests in Jest using your preferred end-to-end testing library.
It's also useful for starting a local development server during the tests without letting Jest hang.
This package extracts just the local development server spawning without any ties to Puppeteer.
Install
1npm install --save-dev jest-process-manager
Usage
jest-process-manager
exports setup
,teardown
and getServers
functions.
1// global-setup.js
2const { setup: setupDevServer } = require('jest-process-manager')
3
4module.exports = async function globalSetup() {
5 await setupDevServer({
6 command: `node config/start.js --port=3000`,
7 launchTimeout: 50000,
8 port: 3000,
9 })
10 // Your global setup
11}
It is also possible to specify several servers:
1// global-setup.js
2const { setup: setupDevServer } = require('jest-process-manager')
3
4module.exports = async function globalSetup() {
5 await setupDevServer([
6 {
7 command: 'node server.js',
8 port: 4444,
9 },
10 {
11 command: 'node server2.js',
12 port: 4445,
13 },
14 ])
15 // Your global setup
16}
1// global-setup.js
2const { setup: setupDevServer, getServers } = require('jest-process-manager')
3
4module.exports = async function globalSetup() {
5 await setupDevServer({
6 command: `node config/start.js --port=3000`,
7 launchTimeout: 50000,
8 port: 3000,
9 })
10 getServers.then(servers => {
11 // You can get to the servers and do whatever you want
12 })
13 // Your global setup
14}
1// global-teardown.js 2const { teardown: teardownDevServer } = require('jest-process-manager') 3 4module.exports = async function globalTeardown() { 5 await teardownDevServer() 6 // Your global teardown 7}
Options
command
Type: string
, required.
Command to execute to start the port.
Directly passed to spawnd
.
1module.exports = { 2 command: 'npm run start', 3}
debug
Type: boolean
, default to false
.
Log server output, useful if server is crashing at start.
1module.exports = { 2 command: 'npm run start', 3 debug: true, 4}
launchTimeout
Type: number
, default to 5000
.
How many milliseconds to wait for the spawned server to be available before giving up.
Defaults to wait-port
's default.
1module.exports = { 2 command: 'npm run start', 3 launchTimeout: 30000, 4}
Following options are linked to spawnd
.
host
Type: string
, default to localhost
.
Host to wait for activity on before considering the server running.
Must be used in conjunction with port
.
1module.exports = { 2 command: 'npm run start --port 3000', 3 host: 'customhost.com', 4 port: 3000, 5}
protocol
Type: (https
, http
, http-get
, https-get
, tcp
, socket
) default to tcp
.
To wait for an HTTP or TCP endpoint before considering the server running, include http
or tcp
as a protocol.
Must be used in conjunction with port
.
This give you ability to define resource prefix for wait-on
package.
1module.exports = { 2 command: 'npm run start --port 3000', 3 protocol: 'http', 4 port: 3000, 5}
port
Type: number
, default to 3000
.
Port to wait for activity on before considering the server running. If not provided, the server is assumed to immediately be running.
1module.exports = { 2 command: 'npm run start --port 3000', 3 port: 3000, 4}
basePath
Type: string
Option for a basePath where server is running.
1module.exports = { 2 command: 'npm run start', 3 basePath: '/myservice', 4}
usedPortAction
Type: string
(ask
, error
, ignore
, kill
) default to ask
.
It defines the action to take if port is already used:
ask
: a prompt is shown to decide if you want to kill the process or noterror
: an errow is thrownignore
: your test are executed, we assume that the server is already startedkill
: the process is automatically killed without a prompt
1module.exports = { 2 command: 'npm run start --port 3000', 3 port: 3000, 4 usedPortAction: 'kill', 5}
waitOnScheme
jest-dev-server
use the wait-on
npm package to wait for resources to become available before calling callback.
Type: object
, default to {}
.
delay
: optional initial delay in ms, default 0interval
: optional poll resource interval in ms, default 250mslog
: optional flag which outputs to stdout, remaining resources waited on and when complete or erroredreverse
: optional flag to reverse operation so checks are for resources being NOT available, default falsetimeout
: optional timeout in ms, default Infinity. Aborts with errortcpTimeout
: optional tcp timeout in ms, default 300msverbose
: optional flag which outputs debug output, default falsewindow
: optional stabilization time in ms, default 750ms. Waits this amount of time for file sizes to stabilize or other resource availability to remain unchanged
Note: http(s) specific options, see https://github.com/request/request#readme for specific details
1module.exports = { 2 command: 'npm run start --port 3000', 3 port: 3000, 4 usedPortAction: 'kill', 5 waitOnScheme: { 6 delay: 1000, 7 }, 8}
options
Options which will be passed down to the spawn of the process. For example environment variables:
1// global-setup.js
2const { setup: setupDevServer, getServers } = require('jest-process-manager')
3
4module.exports = async function globalSetup() {
5 await setupDevServer({
6 command: `node config/start.js --port=3000`,
7 launchTimeout: 50000,
8 port: 3000,
9 options: {
10 env: {
11 "FOO": "bar",
12 }
13 }
14 })
15 getServers.then(servers => {
16 // You can get to the servers and do whatever you want
17 })
18 // Your global setup
19}
Troubleshooting
- If using
port
makes the terminal to ask for root password although the port is valid and accessible then useusePortAction: 'ignore'
.
License
https://github.com/playwright-community/jest-process-manager/blob/master/LICENSE
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
4 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-8hc4-vh64-cxmj
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
Reason
Found 14/29 approved changesets -- score normalized to 4
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/playwright-community/jest-process-manager/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/playwright-community/jest-process-manager/ci.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 16 are checked with a SAST tool
Score
4
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More