Skip to content

Commit

Permalink
fix(test): handle various test states
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Jul 9, 2017
1 parent ea6f53d commit adbfa41
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/config/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ const path = require('path')

module.exports = {
testMatch: [
'**/test/**/?(*.)spec.js?(x)',
'**/test/(browser|node).js?(x)'
'**/test/**/*.js'
],
testPathIgnorePatterns: [
'/node_modules/',
Expand Down
30 changes: 18 additions & 12 deletions src/test/browser-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,34 @@ const defaultClient = {
}
}

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

return defaultClient
}

function getConfig (isWebworker, ctx) {
return _.defaultsDeep({}, user().karma, {
configFile: CONFIG_FILE,
singleRun: !ctx.watch,
watch: ctx.watch,
frameworks: isWebworker ? ['mocha-webworker'] : ['mocha'],
logLevel: ctx.verbose ? 'debug' : 'error',
client: isWebworker ? webworkerClient : defaultClient,
client: getClient(isWebworker, ctx),
mochaOwnReporter: {
reporter: ctx.verbose ? 'spec' : 'progress'
},
files: [
getPatterns(ctx).map((pattern) => ({
pattern: pattern,
included: !isWebworker
})), {
pattern: 'test/fixtures/**/*',
watched: false,
served: true,
included: false
}
]
files: getPatterns(ctx).map((pattern) => ({
pattern: pattern,
included: !isWebworker
})).concat([{
pattern: 'test/fixtures/**/*',
watched: false,
served: true,
included: false
}])
})
}

Expand Down
26 changes: 21 additions & 5 deletions src/test/node.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
'use strict'

const execa = require('execa')
const path = require('path')

function testNode (ctx) {
const args = [
'--colors',
'--config', require.resolve('../config/jest')
]

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

if (ctx.verbose) {
args.push('--verbose')
}
Expand All @@ -24,15 +30,25 @@ function testNode (ctx) {
args.push('--updateSnapshot')
}

const res = execa('jest', args.concat(ctx.files), {
cwd: process.cwd()
if (ctx.files && ctx.files.length > 0) {
files = ctx.files
}

const res = execa('jest', args.concat(files), {
cwd: process.cwd(),
preferLocal: true,
localDir: path.join(__dirname, '../..')
})
res.stdout.pipe(process.stdout)
res.stderr.pipe(process.stderr)

// catch and rethrow custom to avoid double printing failed tests
return res.catch(() => {
throw new Error('Tests failed')
return res.catch((err) => {
// catch and rethrow custom to avoid double printing failed tests
if (err.code === 1 && err.stderr) {
throw new Error('Tests failed')
} else {
throw err
}
})
}

Expand Down

0 comments on commit adbfa41

Please # to comment.