-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the parallel functionality
- Loading branch information
wood
authored and
Gregg Van Hove
committed
Sep 24, 2019
1 parent
c2e0f30
commit b78c149
Showing
16 changed files
with
444 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ build | |
node_modules | ||
package-lock.json | ||
yarn.lock | ||
.DS_Store |
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 |
---|---|---|
@@ -1,11 +1,20 @@ | ||
#!/usr/bin/env node | ||
|
||
var path = require('path'), | ||
Command = require('../lib/command.js'), | ||
Jasmine = require('../lib/jasmine.js'); | ||
var cluster = require('cluster'), | ||
path = require('path'), | ||
Jasmine = require("../lib/jasmine"); | ||
|
||
var jasmine = new Jasmine({ projectBaseDir: path.resolve() }); | ||
var examplesDir = path.join(path.dirname(require.resolve('jasmine-core')), 'jasmine-core', 'example', 'node_example'); | ||
var command = new Command(path.resolve(), examplesDir, console.log); | ||
|
||
command.run(jasmine, process.argv.slice(2)); | ||
if (cluster.isMaster) { | ||
var Command = require('../lib/command.js'); | ||
|
||
var examplesDir = path.join(path.dirname(require.resolve('jasmine-core')), 'jasmine-core', 'example', 'node_example'); | ||
var command = new Command(path.resolve(), examplesDir, console.log); | ||
|
||
command.run(jasmine, process.argv.slice(2)); | ||
} else if (cluster.isWorker) { | ||
var loadConfig = require('../lib/loadConfig'); | ||
var runWorkerJasmine = require('../lib/worker'); | ||
runWorkerJasmine(jasmine, loadConfig); | ||
} |
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,34 @@ | ||
module.exports = exports = function(jasmine, env, print) { | ||
jasmine.loadConfigFile(env.configPath || process.env.JASMINE_CONFIG_PATH); | ||
if (env.stopOnFailure !== undefined) { | ||
jasmine.stopSpecOnExpectationFailure(env.stopOnFailure); | ||
} | ||
if (env.failFast !== undefined) { | ||
jasmine.stopOnSpecFailure(env.failFast); | ||
} | ||
if (env.seed !== undefined) { | ||
jasmine.seed(env.seed); | ||
} | ||
if (env.random !== undefined) { | ||
jasmine.randomizeTests(env.random); | ||
} | ||
if (env.helpers !== undefined && env.helpers.length) { | ||
jasmine.addHelperFiles(env.helpers); | ||
} | ||
if (env.requires !== undefined && env.requires.length) { | ||
jasmine.addRequires(env.requires); | ||
} | ||
if (env.reporter !== undefined) { | ||
try { | ||
var Report = require(env.reporter); | ||
var reporter = new Report(); | ||
jasmine.clearReporters(); | ||
jasmine.addReporter(reporter); | ||
} catch(e) { | ||
print('failed to register reporter "' + env.reporter + '"'); | ||
print(e.message); | ||
print(e.stack); | ||
} | ||
} | ||
jasmine.showColors(env.color); | ||
}; |
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,59 @@ | ||
var cluster = require('cluster'); | ||
|
||
module.exports = exports = function(jasmine, env, print, loadConfig) { | ||
loadConfig(jasmine, env, print); | ||
|
||
if (env.files && env.files.length > 0) { | ||
jasmine.specDir = ''; | ||
jasmine.specFiles = []; | ||
jasmine.addSpecFiles(env.files); | ||
} | ||
|
||
env.seed = env.seed || String(Math.random()).slice(-5); | ||
|
||
var files = jasmine.specFiles.slice(0).reverse(); | ||
jasmine.configureDefaultReporter({ showColors: env.color }); | ||
clusterReporter(jasmine.reporter); | ||
|
||
cluster.on('message', function(worker, message) { | ||
if (message.kind === 'jasmineDone') { | ||
if (files.length) { | ||
worker.send(clusterEnv(env, files.pop())); | ||
} else { | ||
worker.kill(); | ||
} | ||
} | ||
}); | ||
|
||
for (var i = 0; i < env.workerCount; i++) { | ||
cluster.fork().send(clusterEnv(env, files.pop())); | ||
} | ||
}; | ||
|
||
function clusterEnv(env, file) { | ||
var clusterEnv = Object.assign({}, env); | ||
clusterEnv.reporter = './reporters/worker_reporter.js'; | ||
clusterEnv.files = [file]; | ||
return clusterEnv; | ||
} | ||
|
||
function clusterReporter(reporter) { | ||
var results = []; | ||
|
||
cluster.on('message', function(worker, message) { | ||
if (message.kind === 'jasmineDone') { | ||
results.push(message.result); | ||
} else if (reporter[message.kind]) { | ||
reporter[message.kind](message.result); | ||
if (message.kind === 'jasmineStarted') { | ||
reporter[message.kind] = function(){}; | ||
} | ||
} | ||
}); | ||
|
||
cluster.on('exit', function() { | ||
if (!Object.keys(cluster.workers).length) { | ||
reporter.jasmineDone(results); | ||
} | ||
}); | ||
} |
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,6 @@ | ||
var path = require('path'), | ||
Jasmine = require('./jasmine'); | ||
|
||
module.exports = exports = function() { | ||
return new Jasmine({ projectBaseDir: path.resolve() }); | ||
}; |
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 @@ | ||
var kinds = ['jasmineStarted', 'jasmineDone', 'specStarted', 'specDone', 'suiteStarted', 'suiteDone']; | ||
|
||
function WorkerReporter() { | ||
var self = this; | ||
kinds.forEach(function(kind) { | ||
self[kind] = function(result) { | ||
process.send({ | ||
kind: kind, | ||
result: result | ||
}); | ||
}; | ||
}); | ||
} | ||
|
||
module.exports = exports = WorkerReporter; |
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 @@ | ||
module.exports = exports = function(jasmine, loadConfig) { | ||
process.on('message', function(env) { | ||
jasmine.onComplete(function(){}); | ||
loadConfig(jasmine, env, console.log); | ||
jasmine.execute(env.files, env.filter); | ||
}); | ||
}; |
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
Oops, something went wrong.