spec: convert smaller specs to expect
This commit is contained in:
parent
003a92e099
commit
9489401e7d
3 changed files with 65 additions and 61 deletions
|
@ -1,4 +1,5 @@
|
|||
const assert = require('assert')
|
||||
const chai = require('chai')
|
||||
const dirtyChai = require('dirty-chai')
|
||||
const http = require('http')
|
||||
const fs = require('fs')
|
||||
const os = require('os')
|
||||
|
@ -10,13 +11,15 @@ const appPath = path.join(__dirname, 'fixtures', 'api', 'net-log')
|
|||
const dumpFile = path.join(os.tmpdir(), 'net_log.json')
|
||||
const dumpFileDynamic = path.join(os.tmpdir(), 'net_log_dynamic.json')
|
||||
|
||||
const {expect} = chai
|
||||
chai.use(dirtyChai)
|
||||
const isCI = remote.getGlobal('isCi')
|
||||
|
||||
describe('netLog module', () => {
|
||||
let server
|
||||
const connections = new Set()
|
||||
|
||||
before((done) => {
|
||||
before(done => {
|
||||
server = http.createServer()
|
||||
server.listen(0, '127.0.0.1', () => {
|
||||
server.url = `http://127.0.0.1:${server.address().port}`
|
||||
|
@ -33,7 +36,7 @@ describe('netLog module', () => {
|
|||
})
|
||||
})
|
||||
|
||||
after((done) => {
|
||||
after(done => {
|
||||
for (const connection of connections) {
|
||||
connection.destroy()
|
||||
}
|
||||
|
@ -52,36 +55,35 @@ describe('netLog module', () => {
|
|||
}
|
||||
})
|
||||
|
||||
it('should begin and end logging to file when .startLogging() and .stopLogging() is called', (done) => {
|
||||
assert(!netLog.currentlyLogging)
|
||||
assert.equal(netLog.currentlyLoggingPath, '')
|
||||
it('should begin and end logging to file when .startLogging() and .stopLogging() is called', done => {
|
||||
expect(netLog.currentlyLogging).to.be.false()
|
||||
expect(netLog.currentlyLoggingPath).to.equal('')
|
||||
|
||||
netLog.startLogging(dumpFileDynamic)
|
||||
|
||||
assert(netLog.currentlyLogging)
|
||||
assert.equal(netLog.currentlyLoggingPath, dumpFileDynamic)
|
||||
expect(netLog.currentlyLogging).to.be.true()
|
||||
expect(netLog.currentlyLoggingPath).to.equal(dumpFileDynamic)
|
||||
|
||||
netLog.stopLogging((path) => {
|
||||
assert(!netLog.currentlyLogging)
|
||||
assert.equal(netLog.currentlyLoggingPath, '')
|
||||
expect(netLog.currentlyLogging).to.be.false()
|
||||
expect(netLog.currentlyLoggingPath).to.equal('')
|
||||
|
||||
assert.equal(path, dumpFileDynamic)
|
||||
|
||||
assert(fs.existsSync(dumpFileDynamic))
|
||||
expect(path).to.equal(dumpFileDynamic)
|
||||
expect(fs.existsSync(dumpFileDynamic)).to.be.true()
|
||||
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should silence when .stopLogging() is called without calling .startLogging()', (done) => {
|
||||
assert(!netLog.currentlyLogging)
|
||||
assert.equal(netLog.currentlyLoggingPath, '')
|
||||
it('should silence when .stopLogging() is called without calling .startLogging()', done => {
|
||||
expect(netLog.currentlyLogging).to.be.false()
|
||||
expect(netLog.currentlyLoggingPath).to.equal('')
|
||||
|
||||
netLog.stopLogging((path) => {
|
||||
assert(!netLog.currentlyLogging)
|
||||
assert.equal(netLog.currentlyLoggingPath, '')
|
||||
netLog.stopLogging(path => {
|
||||
expect(netLog.currentlyLogging).to.be.false()
|
||||
expect(netLog.currentlyLoggingPath).to.equal('')
|
||||
|
||||
assert.equal(path, '')
|
||||
expect(path).to.equal('')
|
||||
|
||||
done()
|
||||
})
|
||||
|
@ -89,7 +91,7 @@ describe('netLog module', () => {
|
|||
|
||||
// The following tests are skipped on Linux CI
|
||||
|
||||
it('should begin and end logging automatically when --log-net-log is passed', (done) => {
|
||||
it('should begin and end logging automatically when --log-net-log is passed', done => {
|
||||
if (isCI && process.platform === 'linux') {
|
||||
done()
|
||||
return
|
||||
|
@ -103,12 +105,12 @@ describe('netLog module', () => {
|
|||
})
|
||||
|
||||
appProcess.once('exit', () => {
|
||||
assert(fs.existsSync(dumpFile))
|
||||
expect(fs.existsSync(dumpFile)).to.be.true()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should begin and end logging automtically when --log-net-log is passed, and behave correctly when .startLogging() and .stopLogging() is called', (done) => {
|
||||
it('should begin and end logging automtically when --log-net-log is passed, and behave correctly when .startLogging() and .stopLogging() is called', done => {
|
||||
if (isCI && process.platform === 'linux') {
|
||||
done()
|
||||
return
|
||||
|
@ -123,18 +125,18 @@ describe('netLog module', () => {
|
|||
}
|
||||
})
|
||||
|
||||
appProcess.stdout.on('data', (data) => {
|
||||
appProcess.stdout.on('data', data => {
|
||||
console.log(data.toString())
|
||||
})
|
||||
|
||||
appProcess.once('exit', () => {
|
||||
assert(fs.existsSync(dumpFile))
|
||||
assert(fs.existsSync(dumpFileDynamic))
|
||||
expect(fs.existsSync(dumpFile)).to.be.true()
|
||||
expect(fs.existsSync(dumpFileDynamic)).to.be.true()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should end logging automatically when only .startLogging() is called', (done) => {
|
||||
it('should end logging automatically when only .startLogging() is called', done => {
|
||||
if (isCI && process.platform === 'linux') {
|
||||
done()
|
||||
return
|
||||
|
@ -149,7 +151,7 @@ describe('netLog module', () => {
|
|||
})
|
||||
|
||||
appProcess.once('exit', () => {
|
||||
assert(fs.existsSync(dumpFileDynamic))
|
||||
expect(fs.existsSync(dumpFileDynamic)).to.be.true()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue