Skip to content

Commit

Permalink
feat: reduce timeout and monkeypatch this.timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Jul 9, 2017
1 parent 489fbb3 commit 13894a4
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ As we are no longer using `gulp` the previous setup using a custom `gulpfile` wi

`aegir` is now a single binary with subcommands. While something like `aegir-test` still works, we recommend to switch to the new `aegir test` syntax.

### Switch from Mocha to Jest

Because the mocha binary was the source of many pains tests in node are now run using [Jest](https://facebook.github.io/jest/). All important features should work as before, but if you were relying on a mocha specific feature it might break now.

## Project Structure

Expand Down
2 changes: 1 addition & 1 deletion src/config/custom.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'

module.exports = {
timeout: 40 * 1000
timeout: 5 * 1000
}
26 changes: 26 additions & 0 deletions src/config/jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,29 @@ global.before = beforeAll
global.after = afterAll

jasmine.DEFAULT_TIMEOUT_INTERVAL = custom.timeout

function timeout (duration) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = duration
}

(function patchJasmine (jasmine) {
jasmine.Suite.prototype.timeout = timeout

const original = jasmine.Spec
jasmine.Spec = function Spec (attr) {
original.call(this, attr)

const originalUserContext = this.userContext
this.userContext = () => {
const ctx = originalUserContext.call(this)
ctx.timeout = timeout
return ctx
}
}
jasmine.Spec.prototype = original.prototype
for (const statics in original) {
if (Object.prototype.hasOwnProperty.call(original, statics)) {
jasmine.Spec[statics] = original[statics]
}
}
})(global.jasmine)
3 changes: 2 additions & 1 deletion src/test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const path = require('path')
function testNode (ctx) {
const args = [
'--colors',
'--config', require.resolve('../config/jest')
'--config', require.resolve('../config/jest'),
'--env', 'node'
]

let files = [
Expand Down
16 changes: 16 additions & 0 deletions test/test.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-env jest */
'use strict'

describe('test', () => {
describe('node', () => {
it('patches this.timeout', function (done) {
this.timeout(6 * 1000)
setTimeout(done, 5500)
})

it('adds aliases for before and after', () => {
expect(global.before).toEqual(beforeAll)
expect(global.after).toEqual(afterAll)
})
})
})
2 changes: 1 addition & 1 deletion test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const sinon = require('sinon')

const utils = require('../src/utils')

describe('utils', () => {
describe('utils', function () {
it('getBasePath', () => {
expect(utils.getBasePath()).toEqual(process.cwd())
})
Expand Down

0 comments on commit 13894a4

Please sign in to comment.