Skip to content

Commit

Permalink
feat(test): better interop and --files option
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Jul 8, 2017
1 parent 36d231d commit 5468940
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 27 deletions.
6 changes: 6 additions & 0 deletions cmds/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ module.exports = {
updateSnapshot: {
alias: 'u',
describe: 'Use this flag to re-record every snapshot that fails during this test run. (node only)'
},
files: {
alias: 'f',
describe: 'Custom globs for files to test',
type: 'array',
default: []
}
},
handler (argv) {
Expand Down
6 changes: 6 additions & 0 deletions src/config/jest-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-env jest */
'use strict'

// Setup aliases to keep api consistent with mocha
global.before = beforeAll
global.after = afterAll
3 changes: 3 additions & 0 deletions src/config/jest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const path = require('path')

module.exports = {
testMatch: [
'**/test/**/?(*.)spec.js?(x)',
Expand All @@ -9,6 +11,7 @@ module.exports = {
'/node_modules/',
'/src/'
],
setupTestFrameworkScriptFile: path.join(__dirname, 'jest-setup.js'),
rootDir: process.cwd(),
collectCoverageFrom: [
'**/src/**/*.js',
Expand Down
57 changes: 33 additions & 24 deletions src/test/browser-config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
'use strict'

const path = require('path')
const _ = require('lodash')

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

const CONFIG_FILE = path.join(__dirname, '..', 'config', 'karma.conf.js')

const userFiles = user.files != null ? user.files : []
function getPatterns (ctx) {
if (ctx.files && ctx.files.length > 0) {
return ctx.files
}

return [
'test/browser.js',
'test/**/*.spec.js'
]
}

const webworkerClient = {
mochaWebWorker: {
pattern: [
'test/browser.js',
'test/**/*.spec.js'
],
mocha: {
timeout: timeout
function webworkerClient (ctx) {
return {
mochaWebWorker: {
pattern: getPatterns(ctx),
mocha: {
timeout: timeout
}
}
}
}
Expand All @@ -27,7 +37,7 @@ const defaultClient = {
}

function getConfig (isWebworker, ctx) {
return {
return _.defaultsDeep({}, user().karma, {
configFile: CONFIG_FILE,
singleRun: !ctx.watch,
watch: ctx.watch,
Expand All @@ -37,19 +47,18 @@ function getConfig (isWebworker, ctx) {
mochaOwnReporter: {
reporter: ctx.verbose ? 'spec' : 'progress'
},
files: [{
pattern: 'test/browser.js',
included: !isWebworker
}, {
pattern: 'test/**/*.spec.js',
included: !isWebworker
}, {
pattern: 'test/fixtures/**/*',
watched: false,
served: true,
included: false
}].concat(userFiles)
}
files: [
getPatterns(ctx).map((pattern) => ({
pattern: pattern,
included: !isWebworker
})), {
pattern: 'test/fixtures/**/*',
watched: false,
served: true,
included: false
}
]
})
}

module.exports = getConfig
2 changes: 1 addition & 1 deletion src/test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function testNode (ctx) {
args.push('--updateSnapshot')
}

const res = execa('jest', args, {
const res = execa('jest', args.concat(ctx.files), {
cwd: process.cwd()
})
res.stdout.pipe(process.stdout)
Expand Down
5 changes: 3 additions & 2 deletions test/config/user.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-env mocha */
/* eslint-env jest */
'use strict'

describe('config - user', () => {
let config
beforeAll(() => {
before(() => {
jest.mock('../../src/utils', () => ({
getPkg () {
return Promise.resolve({
Expand Down Expand Up @@ -31,7 +32,7 @@ describe('config - user', () => {
config = require('../../src/config/user')()
})

afterAll(() => {
after(() => {
jest.resetAllMocks()
})

Expand Down

0 comments on commit 5468940

Please # to comment.