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: expose servers #166

Merged
merged 2 commits into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 18 additions & 1 deletion packages/jest-dev-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ npm install --save-dev jest-dev-server

## Usage

`jest-dev-server` exports `setup` and `teardown` functions.
`jest-dev-server` exports `setup`,`teardown` and `getServers` functions.

```js
// global-setup.js
Expand Down Expand Up @@ -53,6 +53,23 @@ module.exports = async function globalSetup() {
}
```

```js
// global-setup.js
const { setup: setupDevServer, getServers} = require('jest-dev-server')

module.exports = async function globalSetup() {
await setupDevServer({
command: `node config/start.js --port=3000`,
launchTimeout: 50000,
port: 3000,
})
getServers.then(servers => {
// You can get to the servers and do whatever you want
})
// Your global setup
}
```

```js
// global-teardown.js
const { teardown: teardownDevServer } = require('jest-dev-server')
Expand Down
1 change: 1 addition & 0 deletions packages/jest-dev-server/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports.setup = require('./lib/global').setup
module.exports.getServers = require('./lib/global').getServers
module.exports.teardown = require('./lib/global').teardown
module.exports.ERROR_TIMEOUT = require('./lib/global').ERROR_TIMEOUT
module.exports.ERROR_PORT_USED = require('./lib/global').ERROR_PORT_USED
Expand Down
6 changes: 5 additions & 1 deletion packages/jest-dev-server/src/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export async function setup(providedConfigs) {
)
}

export async function setupJestServer(providedConfig, index) {
async function setupJestServer(providedConfig, index) {
const config = { ...DEFAULT_CONFIG, ...providedConfig }

const usedPortHandlers = {
Expand Down Expand Up @@ -204,6 +204,10 @@ export async function setupJestServer(providedConfig, index) {
}
}

export async function getServers() {
xiaoyuhen marked this conversation as resolved.
Show resolved Hide resolved
return servers
}

export async function teardown() {
if (servers.length) {
await Promise.all(servers.map(server => server.destroy()))
Expand Down