Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-dev-server

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-dev-server - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

5

package.json
{
"name": "jest-dev-server",
"version": "0.1.1",
"version": "0.1.2",
"description": "Creates and tears down a local dev server during Jest tests.",

@@ -27,2 +27,4 @@ "main": "./src/index.js",

"lodash": "^4.17.10",
"mz": "^2.7.0",
"portscanner": "^2.2.0",
"spawnd": "^2.0.0",

@@ -35,4 +37,5 @@ "wait-port": "^0.2.2"

"@types/node": "^10.0.8",
"@types/portscanner": "^2.1.0",
"typescript": "^2.8.3"
}
}

86

README.md

@@ -6,3 +6,3 @@ # jest-dev-server

Starts a server before your Jest tests and tears it down after.
Obeys generally the same settings as as `jest-environment-puppeteer`.
Obeys generally the same settings as `jest-environment-puppeteer`.

@@ -35,9 +35,83 @@ ## Why

module.exports = {
server: {
command: `node config/start.js --port=3000`,
port: 3000,
launchTimeout: 50000,
},
command: `node config/start.js --port=3000`,
launchTimeout: 50000,
port: 3000,
};
```
#### Options
#### `allowExistingServer`
Type: `boolean`.
If true and `port` is specified, `jest-dev-server` will check if the port is in use and skip creating a server if so.
Useful to allow developers and CI machines to have a local server running that was started before tests run.
```javascript
module.exports = {
allowExistingServer: true,
command: "npm run start --port 3000",
port: 3000,
};
```
#### `args`
Type: `string[]`.
Any additional options to pass to `command`.
```javascript
module.exports = {
args: ["--no-sandbox"],
command: "npm run start",
};
```
#### `command`
Type: `string`.
Command to execute to start the port.
Directly passed to [`spawnd`](https://www.npmjs.com/package/spawnd).
```javascript
module.exports = {
command: "npm run start",
};
```
#### `launchTimeout`
Type: `number`.
How many milliseconds to wait for the spawned server to be available before giving up.
Defaults to [`wait-port`](https://www.npmjs.com/package/wait-port)'s default.
```javascript
module.exports = {
command: "npm run start",
launchTimeout: 30000,
};
```
#### `options`
Type: `{}`.
Any other options to pass to [`spawnd`](https://www.npmjs.com/package/spawnd).
#### `port`
Type: `number`.
Port to wait for activity on before considering the server running.
If not provided, the server is assumed to immediately be running.
```javascript
module.exports = {
command: "npm run start --port 3000",
port: 3000,
};
```

@@ -44,9 +44,5 @@ "use strict";

var CONFIG_PATH = path.join(cwd(), "jest-dev-server.config.js");
var DEFAULT_CONFIG = {
launch: {},
};
var DEFAULT_CONFIG = {};
var DEFAULT_CONFIG_CI = {
launch: {
args: ["--no-sandbox", "--disable-setuid-sandbox"],
},
args: ["--no-sandbox", "--disable-setuid-sandbox"],
};

@@ -53,0 +49,0 @@ exports.readConfig = function () { return __awaiter(_this, void 0, void 0, function () {

@@ -6,15 +6,20 @@ import * as cwd from "cwd";

export interface IConfig {
allowExistingServer?: boolean;
args?: string[];
command?: string;
launchTimeout?: number;
port?: number;
options?: {};
}
const CONFIG_PATH = path.join(cwd(), "jest-dev-server.config.js")
const DEFAULT_CONFIG = {
launch: {},
};
const DEFAULT_CONFIG = {};
const DEFAULT_CONFIG_CI = {
launch: {
args: ["--no-sandbox", "--disable-setuid-sandbox"],
},
args: ["--no-sandbox", "--disable-setuid-sandbox"],
};
export const readConfig = async () => {
export const readConfig = async (): Promise<IConfig> => {
const defaultConfig =

@@ -21,0 +26,0 @@ process.env.CI === "true"

@@ -48,2 +48,3 @@ "use strict";

var cwd = require("cwd");
var portscanner = require("portscanner");
var spawnd = require("spawnd");

@@ -54,3 +55,3 @@ var waitPort = require("wait-port");

exports.setupServer = function () { return __awaiter(_this, void 0, void 0, function () {
var config;
var config, status;
return __generator(this, function (_a) {

@@ -61,10 +62,25 @@ switch (_a.label) {

config = _a.sent();
if (config.command === undefined) {
return [2 /*return*/];
}
if (!(config.allowExistingServer && config.port)) return [3 /*break*/, 3];
return [4 /*yield*/, portscanner.checkPortStatus(config.port, "127.0.0.1")];
case 2:
status = _a.sent();
if (status !== "closed") {
return [2 /*return*/];
}
_a.label = 3;
case 3:
server = spawnd(config.command, __assign({ shell: true, env: process.env, cwd: cwd() }, config.options));
if (!config.port) return [3 /*break*/, 5];
return [4 /*yield*/, waitPort({
output: "silent",
port: config.port,
output: "silent",
timeout: config.launchTimeout,
})];
case 2:
case 4:
_a.sent();
return [2 /*return*/];
_a.label = 5;
case 5: return [2 /*return*/];
}

@@ -71,0 +87,0 @@ });

import * as cwd from "cwd";
import * as portscanner from "portscanner";
import * as spawnd from "spawnd";

@@ -12,19 +13,34 @@ import * as waitPort from "wait-port";

server = spawnd(config.command, {
shell: true,
env: process.env,
if (config.command === undefined) {
return;
}
if (config.allowExistingServer && config.port) {
const status = await portscanner.checkPortStatus(config.port, "127.0.0.1");
if (status !== "closed") {
return;
}
}
server = spawnd(config.command, {
shell: true,
env: process.env,
cwd: cwd(),
...config.options,
});
});
await waitPort({
port: config.port,
output: "silent",
});
if (config.port) {
await waitPort({
output: "silent",
port: config.port,
timeout: config.launchTimeout,
});
}
};
export const teardownServer = async () => {
if (server !== undefined) {
await server.destroy();
}
if (server !== undefined) {
await server.destroy();
}
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc