updated mocha and sinon, fixed tests

This commit is contained in:
mserranom
2020-03-12 10:35:11 +01:00
parent ffb33ddb40
commit 3ff9c18dcb
8 changed files with 442 additions and 119 deletions

View File

@@ -347,10 +347,10 @@ describe('CompileManager', function() {
.should.equal(true)
})
return it('should call the callback with an error from the stderr', function() {
this.callback.calledWith(new Error()).should.equal(true)
it('should call the callback with an error from the stderr', function() {
this.callback.calledWithExactly(sinon.match(Error)).should.equal(true)
return this.callback.args[0][0].message.should.equal(
this.callback.args[0][0].message.should.equal(
`rm -r ${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id} failed: ${this.error}`
)
})

View File

@@ -464,8 +464,8 @@ describe('DockerRunner', function() {
return this.createContainer.called.should.equal(false)
})
return it('should call the callback with an error', function() {
return this.callback.calledWith(new Error()).should.equal(true)
it('should call the callback with an error', function() {
this.callback.calledWith(sinon.match(Error)).should.equal(true)
})
})
@@ -488,8 +488,8 @@ describe('DockerRunner', function() {
return this.createContainer.called.should.equal(false)
})
return it('should call the callback with an error', function() {
return this.callback.calledWith(new Error()).should.equal(true)
it('should call the callback with an error', function() {
this.callback.calledWith(sinon.match(Error)).should.equal(true)
})
})
@@ -582,10 +582,12 @@ describe('DockerRunner', function() {
return this.container.kill.called.should.equal(true)
})
return it('should call the callback with an error', function() {
const error = new Error('container timed out')
error.timedout = true
return this.callback.calledWith(error).should.equal(true)
it('should call the callback with an error', function() {
this.callback.calledWith(sinon.match(Error)).should.equal(true)
const errorObj = this.callback.args[0][0]
expect(errorObj.message).to.include('container timed out')
expect(errorObj.timedout).equal(true)
})
})
})

View File

@@ -84,9 +84,10 @@ describe('DockerLockManager', function() {
return this.runner.called.should.equal(false)
})
return it('should return an error', function() {
const error = new Errors.AlreadyCompilingError()
return this.callback.calledWithExactly(error).should.equal(true)
it('should return an error', function() {
this.callback
.calledWithExactly(sinon.match(Errors.AlreadyCompilingError))
.should.equal(true)
})
})
})

View File

@@ -11,6 +11,7 @@
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
const { expect } = require('chai')
const should = require('chai').should()
const modulePath = require('path').join(
__dirname,
@@ -132,11 +133,13 @@ describe('ResourceStateManager', function() {
)
})
return it('should call the callback with an error', function() {
const error = new Errors.FilesOutOfSyncError(
'invalid state for incremental update'
)
return this.callback.calledWith(error).should.equal(true)
it('should call the callback with an error', function() {
this.callback
.calledWith(sinon.match(Errors.FilesOutOfSyncError))
.should.equal(true)
const message = this.callback.args[0][0].message
expect(message).to.include('invalid state for incremental update')
})
})
})
@@ -174,11 +177,15 @@ describe('ResourceStateManager', function() {
)
})
return it('should call the callback with an error', function() {
const error = new Errors.FilesOutOfSyncError(
it('should call the callback with an error', function() {
this.callback
.calledWith(sinon.match(Errors.FilesOutOfSyncError))
.should.equal(true)
const message = this.callback.args[0][0].message
expect(message).to.include(
'resource files missing in incremental update'
)
return this.callback.calledWith(error).should.equal(true)
})
})
@@ -198,10 +205,11 @@ describe('ResourceStateManager', function() {
)
})
return it('should call the callback with an error', function() {
return this.callback
.calledWith(new Error('relative path in resource file list'))
.should.equal(true)
it('should call the callback with an error', function() {
this.callback.calledWith(sinon.match(Error)).should.equal(true)
const message = this.callback.args[0][0].message
expect(message).to.include('relative path in resource file list')
})
})
})

View File

@@ -12,6 +12,7 @@
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
const { expect } = require('chai')
const should = require('chai').should()
const modulePath = require('path').join(
__dirname,
@@ -447,10 +448,11 @@ describe('ResourceWriter', function() {
return this.fs.writeFile.called.should.equal(false)
})
return it('should return an error', function() {
return this.callback
.calledWith(new Error('resource path is outside root directory'))
.should.equal(true)
it('should return an error', function() {
this.callback.calledWith(sinon.match(Error)).should.equal(true)
const message = this.callback.args[0][0].message
expect(message).to.include('resource path is outside root directory')
})
})
})
@@ -468,21 +470,18 @@ describe('ResourceWriter', function() {
describe('with an invalid path', function() {
beforeEach(function() {
return this.ResourceWriter.checkPath(
'foo',
'baz/../../bar',
this.callback
)
this.ResourceWriter.checkPath('foo', 'baz/../../bar', this.callback)
})
return it('should return an error', function() {
return this.callback
.calledWith(new Error('resource path is outside root directory'))
.should.equal(true)
it('should return an error', function() {
this.callback.calledWith(sinon.match(Error)).should.equal(true)
const message = this.callback.args[0][0].message
expect(message).to.include('resource path is outside root directory')
})
})
return describe('with another invalid path matching on a prefix', function() {
describe('with another invalid path matching on a prefix', function() {
beforeEach(function() {
return this.ResourceWriter.checkPath(
'foo',
@@ -491,10 +490,11 @@ describe('ResourceWriter', function() {
)
})
return it('should return an error', function() {
return this.callback
.calledWith(new Error('resource path is outside root directory'))
.should.equal(true)
it('should return an error', function() {
this.callback.calledWith(sinon.match(Error)).should.equal(true)
const message = this.callback.args[0][0].message
expect(message).to.include('resource path is outside root directory')
})
})
})

View File

@@ -10,6 +10,7 @@
*/
const SandboxedModule = require('sandboxed-module')
const sinon = require('sinon')
const { expect } = require('chai')
require('chai').should()
const modulePath = require('path').join(__dirname, '../../../app/js/UrlFetcher')
const { EventEmitter } = require('events')
@@ -140,10 +141,11 @@ describe('UrlFetcher', function() {
return this.urlStream.emit('end')
})
return it('should call the callback with an error', function() {
return this.callback
.calledWith(new Error('URL returned non-success status code: 404'))
.should.equal(true)
it('should call the callback with an error', function() {
this.callback.calledWith(sinon.match(Error)).should.equal(true)
const message = this.callback.args[0][0].message
expect(message).to.include('URL returned non-success status code: 404')
})
})