Skip to content

Commit

Permalink
feat: make parallel and timeout customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Aug 16, 2017
1 parent b61e7be commit 4ae78ac
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 21 deletions.
10 changes: 10 additions & 0 deletions cmds/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ module.exports = {
describe: 'Custom globs for files to test',
type: 'array',
default: []
},
parallel: {
alias: 'p',
describe: 'Run tests in parallel (only available in node)',
default: true
},
timeout: {
describe: 'The default time a single test has to run',
type: 'number',
default: 5000
}
},
handler (argv) {
Expand Down
10 changes: 10 additions & 0 deletions cmds/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ module.exports = {
describe: 'Custom globs for files to test',
type: 'array',
default: []
},
parallel: {
alias: 'p',
describe: 'Run tests in parallel (only available in node)',
default: true
},
timeout: {
describe: 'The default time a single test has to run',
type: 'number',
default: 5000
}
},
handler (argv) {
Expand Down
5 changes: 0 additions & 5 deletions src/config/custom.js

This file was deleted.

4 changes: 1 addition & 3 deletions src/config/jest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
/* eslint-env jasmine */
'use strict'

const custom = require('./custom')

// Setup aliases to keep api consistent with mocha
global.before = beforeAll
global.after = afterAll

jasmine.DEFAULT_TIMEOUT_INTERVAL = custom.timeout
jasmine.DEFAULT_TIMEOUT_INTERVAL = global.DEFAULT_TIMEOUT

function timeout (duration) {
let done = false
Expand Down
2 changes: 0 additions & 2 deletions src/config/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const webpackConfig = require('./webpack')
const timeout = require('./custom').timeout

let concurrency = 1
let reporters = ['mocha-own']
Expand Down Expand Up @@ -36,7 +35,6 @@ module.exports = function (config) {
browsers: browsers,
singleRun: true,
concurrency: concurrency,
browserNoActivityTimeout: timeout,
failOnEmptyTestSuite: true
})
}
18 changes: 8 additions & 10 deletions src/test/browser-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const path = require('path')
const _ = require('lodash')

const timeout = require('../config/custom').timeout
const user = require('../config/user')

const CONFIG_FILE = path.join(__dirname, '..', 'config', 'karma.conf.js')
Expand All @@ -24,24 +23,22 @@ function webworkerClient (ctx) {
mochaWebWorker: {
pattern: getPatterns(ctx),
mocha: {
timeout: timeout
timeout: ctx.timeout
}
}
}
}

const defaultClient = {
mocha: {
timeout: timeout
}
}

function getClient (isWebworker, ctx) {
if (isWebworker) {
return webworkerClient(ctx)
}

return defaultClient
return {
mocha: {
timeout: ctx.timeout
}
}
}

function getConfig (isWebworker, ctx) {
Expand Down Expand Up @@ -70,7 +67,8 @@ function getConfig (isWebworker, ctx) {
client: getClient(isWebworker, ctx),
mochaOwnReporter: {
reporter: ctx.verbose ? 'spec' : 'progress'
}
},
browserNoActivityTimeout: ctx.timeout
})
}

Expand Down
7 changes: 6 additions & 1 deletion src/test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ function testNode (ctx) {
const args = [
'--colors',
'--config', require.resolve('../config/jest'),
'--env', 'node'
'--env', 'node',
'--globals', JSON.stringify({ DEFAULT_TIMEOUT: ctx.timeout })
]

let files = [
'test/node.js$',
'test/.*\\.spec\\.js$'
]

if (!ctx.parallel) {
args.push('--runInBand')
}

if (ctx.verbose) {
args.push('--verbose')
}
Expand Down

0 comments on commit 4ae78ac

Please # to comment.