Skip to content
This repository has been archived by the owner on Mar 11, 2020. It is now read-only.

fix: add async support to setup #11

Merged
merged 2 commits into from
Sep 27, 2019
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ Include this badge in your readme if you make a new module that uses interface-p

### Node.js

Install `interface-peer-discovery` as one of the dependencies of your project and as a test file. Then, using `mocha` (for JavaScript) or a test runner with compatible API, do:
Install `interface-discovery` as one of the dependencies of your project and as a test file. Then, using `mocha` (for JavaScript) or a test runner with compatible API, do:

```js
const test = require('interface-peer-discovery')
const test = require('interface-discovery')

const common = {
setup () {
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ module.exports = (common) => {
describe('interface-peer-discovery', () => {
let discovery

before(() => {
discovery = common.setup()
before(async () => {
discovery = await common.setup()
})

after(() => common.teardown && common.teardown())

afterEach('ensure discovery was stopped', () => discovery.stop())

it('can start the service', async () => {
await discovery.start()
})
Expand Down
6 changes: 5 additions & 1 deletion test/compliance.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ const MockDiscovery = require('./mock-discovery')

describe('compliance tests', () => {
tests({
setup () {
async setup () {
await new Promise(resolve => setTimeout(resolve, 10))
return new MockDiscovery()
},
async teardown () {
await new Promise(resolve => setTimeout(resolve, 10))
}
})
})