From 2814c76e23edc2279bf960f5ecaf2060d402a83a Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Fri, 27 Sep 2019 13:32:45 +0200 Subject: [PATCH] fix: add async support to setup (#11) --- README.md | 4 ++-- src/index.js | 6 ++++-- test/compliance.spec.js | 6 +++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7e29b93..265cf45 100644 --- a/README.md +++ b/README.md @@ -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 () { diff --git a/src/index.js b/src/index.js index 5b00fbd..343a7db 100644 --- a/src/index.js +++ b/src/index.js @@ -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() }) diff --git a/test/compliance.spec.js b/test/compliance.spec.js index 1eadba9..5b54fba 100644 --- a/test/compliance.spec.js +++ b/test/compliance.spec.js @@ -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)) } }) })