return promises in before/after each

This commit is contained in:
Tony Brix 2021-04-05 00:25:32 -05:00
parent f525cebb64
commit daf1eb8f43
4 changed files with 327 additions and 321 deletions

4
.taprc
View File

@ -1,6 +1,2 @@
esm: false
jsx: false
ts: false
files: files:
- 'test/**/*.test.js' - 'test/**/*.test.js'

View File

@ -14,7 +14,8 @@ const LDAP_CONNECT_TIMEOUT = process.env.LDAP_CONNECT_TIMEOUT || 0
const BIND_DN = 'cn=root' const BIND_DN = 'cn=root'
const BIND_PW = 'secret' const BIND_PW = 'secret'
tap.beforeEach((done, t) => { tap.beforeEach((t) => {
return new Promise(resolve => {
t.context.socketPath = getSock() t.context.socketPath = getSock()
t.context.server = ldap.createServer() t.context.server = ldap.createServer()
@ -320,14 +321,17 @@ tap.beforeEach((done, t) => {
socketPath: t.context.socketPath socketPath: t.context.socketPath
}) })
t.context.client = client t.context.client = client
client.on('connect', () => done()) client.on('connect', () => resolve())
})
}) })
}) })
tap.afterEach((done, t) => { tap.afterEach((t) => {
return new Promise(resolve => {
t.context.client.unbind((err) => { t.context.client.unbind((err) => {
t.error(err) t.error(err)
t.context.server.close(() => done()) t.context.server.close(() => resolve())
})
}) })
}) })

View File

@ -21,7 +21,8 @@ function search (t, options, callback) {
}) })
} }
tap.beforeEach((done, t) => { tap.beforeEach((t) => {
return new Promise((resolve, reject) => {
const suffix = `dc=${uuid()}` const suffix = `dc=${uuid()}`
const server = ldap.createServer() const server = ldap.createServer()
@ -57,19 +58,25 @@ tap.beforeEach((done, t) => {
}) })
t.context.client.on('connectError', (err) => { t.context.client.on('connectError', (err) => {
t.context.server.close(() => done(err)) t.context.server.close(() => reject(err))
}) })
t.context.client.on('connect', (socket) => { t.context.client.on('connect', (socket) => {
t.context.socket = socket t.context.socket = socket
done() resolve()
})
}) })
}) })
}) })
tap.afterEach((done, t) => { tap.afterEach((t) => {
if (!t.context.client) return done() return new Promise((resolve, reject) => {
if (!t.context.client) return resolve()
t.context.client.unbind(() => { t.context.client.unbind(() => {
t.context.server.close(done) t.context.server.close((err) => {
if (err) return reject(err)
resolve()
})
})
}) })
}) })

View File

@ -8,11 +8,10 @@ const ldap = require('../lib')
const SERVER_PORT = process.env.SERVER_PORT || 1389 const SERVER_PORT = process.env.SERVER_PORT || 1389
const SUFFIX = 'dc=test' const SUFFIX = 'dc=test'
tap.beforeEach(function (done, t) { tap.beforeEach(function (t) {
// We do not need a `.afterEach` to clean up the sock files because that // We do not need a `.afterEach` to clean up the sock files because that
// is done when the server is destroyed. // is done when the server is destroyed.
t.context.sock = getSock() t.context.sock = getSock()
done()
}) })
tap.test('basic create', function (t) { tap.test('basic create', function (t) {