-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23dde2e
commit 00c1ddc
Showing
14 changed files
with
228 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict' | ||
|
||
const test = require('../src/test') | ||
const onError = require('../src/error-handler') | ||
|
||
module.exports = { | ||
command: 'test', | ||
desc: 'Test your code in different environments', | ||
builder: { | ||
target: { | ||
alias: 't', | ||
describe: 'In which target environment to execute the tests', | ||
type: 'array', | ||
choices: ['node', 'browser', 'webworker'], | ||
default: ['node', 'browser', 'webworker'] | ||
}, | ||
verbose: { | ||
alias: 'v', | ||
describe: 'Print verbose test output', | ||
default: false | ||
}, | ||
watch: { | ||
describe: 'Watch files for changes and rerun tests (only available for browser based tests)', | ||
default: false | ||
} | ||
}, | ||
handler (argv) { | ||
test(argv).catch(onError) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict' | ||
|
||
const chalk = require('chalk') | ||
|
||
function onError (err) { | ||
if (!err) { | ||
return | ||
} | ||
|
||
chalk.red(err.message) | ||
chalk.gray(err.stack) | ||
process.exit(1) | ||
} | ||
|
||
module.exports = onError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
const timeout = require('../../config/custom').timeout | ||
const user = require('../../config/user').customConfig | ||
|
||
const CONFIG_FILE = path.join(__dirname, '..', '..', 'config', 'karma.conf.js') | ||
|
||
let userFiles = [] | ||
if (user.karma && user.karma.files) { | ||
userFiles = user.karma.files | ||
} | ||
|
||
const webworkerClient = { | ||
mochaWebWorker: { | ||
pattern: [ | ||
'test/browser.js', | ||
'test/**/*.spec.js' | ||
], | ||
mocha: { | ||
timeout: timeout | ||
} | ||
} | ||
} | ||
|
||
const defaultClient = { | ||
mocha: { | ||
timeout: timeout | ||
} | ||
} | ||
|
||
function getConfig (isWebworker, ctx) { | ||
return { | ||
configFile: CONFIG_FILE, | ||
singleRun: !ctx.watch, | ||
watch: ctx.watch, | ||
frameworks: isWebworker ? ['mocha-webworker'] : ['mocha'], | ||
logLevel: ctx.verbose ? 'debug' : 'error', | ||
client: isWebworker ? webworkerClient : defaultClient, | ||
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) | ||
} | ||
} | ||
|
||
module.exports = getConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict' | ||
|
||
const Server = require('karma').Server | ||
const getConfig = require('./browser-config') | ||
|
||
const IS_SAUCE = process.env.SAUCE_USERNAME && process.env.TRAVIS | ||
|
||
function testBrowser (isWebworker) { | ||
return (ctx) => new Promise((resolve, reject) => { | ||
const config = getConfig(isWebworker, ctx) | ||
|
||
const server = new Server(config, (exitCode) => { | ||
if (exitCode > 0 && !IS_SAUCE) { | ||
reject(new Error('Some tests are failing')) | ||
} | ||
resolve() | ||
}) | ||
|
||
server.start() | ||
}) | ||
} | ||
|
||
module.exports = { | ||
default: testBrowser(false), | ||
webworker: testBrowser(true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict' | ||
|
||
const Listr = require('listr') | ||
const _ = require('lodash') | ||
|
||
const node = require('./node') | ||
const browser = require('./browser') | ||
|
||
const TASKS = new Listr([{ | ||
title: 'Test Node.js', | ||
task: node, | ||
enabled: (ctx) => _.includes(ctx.target, 'node') | ||
}, { | ||
title: 'Test Browser', | ||
task: browser.default, | ||
enabled: (ctx) => _.includes(ctx.target, 'browser') | ||
}, { | ||
title: 'Test Webworker', | ||
task: browser.webworker, | ||
enabled: (ctx) => _.includes(ctx.target, 'webworker') | ||
}]) | ||
|
||
function test (opts) { | ||
return TASKS.run(opts) | ||
} | ||
|
||
module.exports = test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict' | ||
|
||
const Mocha = require('mocha') | ||
const glob = require('glob') | ||
const _ = require('lodash') | ||
|
||
const CONFIG = require('../../config/custom').timeout | ||
|
||
const FILES = [ | ||
'test/node.js', | ||
'test/**/*.spec.js' | ||
] | ||
|
||
function testNode (ctx) { | ||
const mocha = new Mocha({ | ||
ui: 'bdd', | ||
reporter: ctx.verbose ? 'spec' : 'progress', | ||
useColors: true, | ||
timeout: CONFIG.timeout | ||
}) | ||
|
||
const files = _.flatten(FILES.map((pattern) => glob.sync(pattern))) | ||
files.forEach((file) => mocha.addFile(file)) | ||
|
||
return new Promise((resolve, reject) => { | ||
mocha.run((failure) => { | ||
if (failure) { | ||
reject(new Error(`Failed ${failure} tests`)) | ||
} | ||
resolve() | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = testNode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict' | ||
|
||
function testWebworker () { | ||
console.log('webworker') | ||
} | ||
|
||
module.exports = testWebworker |
Oops, something went wrong.