Comparing version 2.0.1 to 2.1.0
#!/usr/bin/env node | ||
var path = require('path'), | ||
program = require('commander'); | ||
Command = require('../lib/command.js'), | ||
command = new Command(path.resolve()), | ||
Jasmine = require('../lib/jasmine.js'), | ||
jasmine = new Jasmine({ projectBaseDir: path.resolve() }); | ||
var Command = require('../lib/command.js'); | ||
var command = new Command(path.resolve(), process.argv); | ||
if(command.execJasmine) { | ||
program | ||
.option('--no-color', 'turns off color in output') | ||
.parse(process.argv); | ||
var Jasmine = require('../lib/jasmine.js'); | ||
var jasmine = new Jasmine(); | ||
jasmine.loadConfigFile(process.env.JASMINE_CONFIG_PATH); | ||
jasmine.configureDefaultReporter({ | ||
showColors: program.color | ||
}); | ||
jasmine.execute(); | ||
} | ||
command.run(jasmine, process.argv.slice(2)); |
module.exports = function(grunt) { | ||
var pkg = require("./package.json"); | ||
global.jasmineVersion = pkg.version; | ||
var versionString = 'v' + pkg.version; | ||
@@ -10,20 +11,35 @@ grunt.initConfig({ | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
var shell = require('shelljs'); | ||
function runCommands(commands, done) { | ||
var command = commands.shift(); | ||
grunt.registerTask('specs', function() { | ||
var Jasmine = require('./lib/jasmine.js'); | ||
var jasmine = new Jasmine(); | ||
var done = this.async(); | ||
if (command) { | ||
shell.exec(command, function(exitCode) { | ||
if (exitCode !== 0) { | ||
grunt.fail.fatal("Command `" + command + "` failed", exitCode); | ||
done(); | ||
} else { | ||
runCommands(commands, done); | ||
} | ||
}); | ||
} else { | ||
done(); | ||
} | ||
} | ||
jasmine.loadConfigFile('./spec/support/jasmine.json'); | ||
jasmine.configureDefaultReporter({ | ||
onComplete: function(passed) { | ||
done(passed); | ||
} | ||
}); | ||
// depend on jshint:all, specs? | ||
grunt.registerTask('release', | ||
'Create tag ' + versionString + ' and push jasmine-' + pkg.version + ' to NPM', | ||
function() { | ||
var done = this.async(), | ||
commands = ['git tag ' + versionString, 'git push origin master --tags', 'npm publish']; | ||
jasmine.execute(); | ||
runCommands(commands, done); | ||
}); | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadTasks('tasks'); | ||
grunt.registerTask('default', ['jshint:all', 'specs']); | ||
}; |
var path = require('path'), | ||
fs = require('fs'); | ||
fs = require('fs'); | ||
exports = module.exports = Command; | ||
function Command(projectBaseDir, commands) { | ||
var execJasmine = true; | ||
var subCommands = { | ||
init: { | ||
description: 'initialize jasmine', | ||
action: initJasmine | ||
}, | ||
examples: { | ||
description: 'install examples', | ||
action: installExamples | ||
}, | ||
help: { | ||
description: 'show help', | ||
action: help | ||
} | ||
}; | ||
var spec = path.join(projectBaseDir, 'spec/'); | ||
var jasmine_core_examples = path.join(__dirname, '../', 'node_modules/', 'jasmine-core/', 'lib/', | ||
'jasmine-core/', 'example/', 'node_example/'); | ||
function Command(projectBaseDir) { | ||
this.projectBaseDir = projectBaseDir; | ||
this.specDir = path.join(projectBaseDir, 'spec'); | ||
setEnvironmentVariables(commands); | ||
var command = this; | ||
if(commands.indexOf('init') !== -1) { | ||
execJasmine = false; | ||
makeDirStructure(path.join(spec, 'support/')); | ||
if(!fs.existsSync(path.join(projectBaseDir, 'spec/support/jasmine.json'))) { | ||
fs.writeFileSync(path.join(projectBaseDir, 'spec/support/jasmine.json'), fs.readFileSync(path.join(__dirname, '../lib/examples/jasmine.json'), 'utf-8')); | ||
this.run = function(jasmine, commands) { | ||
setEnvironmentVariables(commands); | ||
var commandToRun; | ||
Object.keys(subCommands).forEach(function(cmd) { | ||
if (commands.indexOf(cmd) >= 0) { | ||
commandToRun = subCommands[cmd]; | ||
} | ||
}); | ||
if (commandToRun) { | ||
commandToRun.action(command.projectBaseDir, command.specDir); | ||
} else { | ||
runJasmine(jasmine, parseOptions(commands)); | ||
} | ||
else { | ||
console.log('spec/support/jasmine.json already exists in your project.'); | ||
}; | ||
} | ||
function isFileArg(arg) { | ||
return arg.indexOf('--') !== 0 && !isEnvironmentVariable(arg); | ||
} | ||
function parseOptions(argv) { | ||
var files = [], | ||
color = true; | ||
argv.forEach(function(arg) { | ||
if (arg === '--no-color') { | ||
color = false; | ||
} else if (isFileArg(arg)) { | ||
files.push(arg); | ||
} | ||
} | ||
}); | ||
return { | ||
color: color, | ||
files: files | ||
}; | ||
} | ||
else if(commands.indexOf('examples') !== -1) { | ||
execJasmine = false; | ||
makeDirStructure(path.join(spec, 'support/')); | ||
makeDirStructure(path.join(spec, 'jasmine_examples/')); | ||
makeDirStructure(path.join(projectBaseDir, 'jasmine_examples/')); | ||
makeDirStructure(path.join(spec, 'helpers/jasmine_examples/')); | ||
copyFiles(path.join(jasmine_core_examples, 'spec/'), path.join(spec, 'helpers/', | ||
'jasmine_examples/'), new RegExp(/[Hh]elper\.js/)); | ||
copyFiles(path.join(jasmine_core_examples, 'src/'), path.join(projectBaseDir, 'jasmine_examples/'), new RegExp(/\.js/)); | ||
copyFiles(path.join(jasmine_core_examples, 'spec/'), path.join(spec, 'jasmine_examples/'), new RegExp(/[Ss]pec.js/)); | ||
function runJasmine(jasmine, env) { | ||
jasmine.loadConfigFile(process.env.JASMINE_CONFIG_PATH); | ||
jasmine.configureDefaultReporter({ | ||
showColors: env.color | ||
}); | ||
jasmine.execute(env.files); | ||
} | ||
function initJasmine(projectBaseDir, spec) { | ||
makeDirStructure(path.join(spec, 'support/')); | ||
if(!fs.existsSync(path.join(spec, 'support/jasmine.json'))) { | ||
fs.writeFileSync(path.join(spec, 'support/jasmine.json'), fs.readFileSync(path.join(__dirname, '../lib/examples/jasmine.json'), 'utf-8')); | ||
} | ||
else { | ||
console.log('spec/support/jasmine.json already exists in your project.'); | ||
} | ||
} | ||
this.execJasmine = execJasmine; | ||
function installExamples(projectBaseDir, spec) { | ||
var jasmine_core_examples = path.join(__dirname, '../', 'node_modules/', 'jasmine-core/', 'lib/', | ||
'jasmine-core/', 'example/', 'node_example/'); | ||
makeDirStructure(path.join(spec, 'support/')); | ||
makeDirStructure(path.join(spec, 'jasmine_examples/')); | ||
makeDirStructure(path.join(projectBaseDir, 'jasmine_examples/')); | ||
makeDirStructure(path.join(spec, 'helpers/jasmine_examples/')); | ||
copyFiles(path.join(jasmine_core_examples, 'spec/'), path.join(spec, 'helpers/', 'jasmine_examples/'), new RegExp(/[Hh]elper\.js/)); | ||
copyFiles(path.join(jasmine_core_examples, 'src/'), path.join(projectBaseDir, 'jasmine_examples/'), new RegExp(/\.js/)); | ||
copyFiles(path.join(jasmine_core_examples, 'spec/'), path.join(spec, 'jasmine_examples/'), new RegExp(/[Ss]pec.js/)); | ||
} | ||
function help() { | ||
console.log('Usage: jasmine [command] [options] [files]'); | ||
console.log(''); | ||
console.log('Commands:'); | ||
Object.keys(subCommands).forEach(function(cmd) { | ||
console.log('%s\t%s', lPad(cmd, 10), subCommands[cmd].description); | ||
}); | ||
console.log(''); | ||
console.log('Options:'); | ||
console.log('%s\t\tturn off color in spec output', lPad('--no-color', 15)); | ||
console.log(''); | ||
console.log('if no command is given, jasmine specs will be run'); | ||
} | ||
function lPad(str, length) { | ||
if (str.length === length) { | ||
return str; | ||
} else { | ||
return lPad(' ' + str, length); | ||
} | ||
} | ||
function copyFiles(srcDir, destDir, pattern) { | ||
@@ -51,3 +131,3 @@ var srcDirFiles = fs.readdirSync(srcDir); | ||
function makeDirStructure(absolutePath) { | ||
var splitPath = absolutePath.split('/'); | ||
var splitPath = absolutePath.split(path.sep); | ||
splitPath.forEach(function(dir, index) { | ||
@@ -63,6 +143,10 @@ if(index > 1) { | ||
function isEnvironmentVariable(command) { | ||
var envRegExp = /(.*)=(.*)/; | ||
return command.match(envRegExp); | ||
} | ||
function setEnvironmentVariables(commands) { | ||
var envRegExp = /(.*)=(.*)/; | ||
commands.forEach(function (command) { | ||
var regExpMatch = command.match(envRegExp); | ||
var regExpMatch = isEnvironmentVariable(command); | ||
if(regExpMatch) { | ||
@@ -69,0 +153,0 @@ var key = regExpMatch[1]; |
var path = require('path'), | ||
util = require('util'), | ||
glob = require('glob'), | ||
jasmineCore = require('jasmine-core'), | ||
jasmine = jasmineCore.boot(jasmineCore); | ||
glob = require('glob'); | ||
module.exports = exports = Jasmine; | ||
module.exports = Jasmine; | ||
module.exports.ConsoleReporter = require('./console_reporter'); | ||
function Jasmine(options) { | ||
options = options || {}; | ||
var jasmineCore = options.jasmineCore || require('jasmine-core'); | ||
this.jasmine = jasmineCore.boot(jasmineCore); | ||
this.projectBaseDir = options.projectBaseDir || path.resolve(); | ||
this.specFiles = []; | ||
this.env = jasmine.getEnv(); | ||
this.env = this.jasmine.getEnv(); | ||
this.reportersCount = 0; | ||
@@ -36,8 +37,10 @@ } | ||
options.timer = new jasmine.Timer(); | ||
options.print = options.print || util.print; | ||
options.timer = new this.jasmine.Timer(); | ||
options.print = options.print || function() { | ||
process.stdout.write(util.format.apply(this, arguments)); | ||
}; | ||
options.showColors = options.hasOwnProperty('showColors') ? options.showColors : true; | ||
options.onComplete = options.onComplete || defaultOnComplete; | ||
var consoleReporter = new jasmine.ConsoleReporter(options); | ||
var consoleReporter = new module.exports.ConsoleReporter(options); | ||
this.addReporter(consoleReporter); | ||
@@ -47,3 +50,3 @@ }; | ||
Jasmine.prototype.addMatchers = function(matchers) { | ||
jasmine.Expectation.addMatchers(matchers); | ||
this.jasmine.Expectation.addMatchers(matchers); | ||
}; | ||
@@ -60,8 +63,13 @@ | ||
var config = require(absoluteConfigFilePath); | ||
this.loadConfig(config); | ||
}; | ||
Jasmine.prototype.loadConfig = function(config) { | ||
var specDir = config.spec_dir; | ||
var jasmineRunner = this; | ||
jasmineRunner.specDir = config.spec_dir; | ||
if(config.helpers) { | ||
config.helpers.forEach(function(helperFile) { | ||
var filePaths = glob.sync(path.join(jasmineRunner.projectBaseDir, specDir, helperFile)); | ||
var filePaths = glob.sync(path.join(jasmineRunner.projectBaseDir, jasmineRunner.specDir, helperFile)); | ||
filePaths.forEach(function(filePath) { | ||
@@ -76,19 +84,32 @@ if(jasmineRunner.specFiles.indexOf(filePath) === -1) { | ||
if(config.spec_files) { | ||
config.spec_files.forEach(function(specFile) { | ||
var filePaths = glob.sync(path.join(jasmineRunner.projectBaseDir, specDir, specFile)); | ||
filePaths.forEach(function(filePath) { | ||
if(jasmineRunner.specFiles.indexOf(filePath) === -1) { | ||
jasmineRunner.specFiles.push(filePath); | ||
} | ||
}); | ||
}); | ||
jasmineRunner.addSpecFiles(config.spec_files); | ||
} | ||
}; | ||
Jasmine.prototype.execute = function() { | ||
Jasmine.prototype.addSpecFiles = function(files) { | ||
var jasmineRunner = this; | ||
files.forEach(function(specFile) { | ||
var filePaths = glob.sync(path.join(jasmineRunner.projectBaseDir, jasmineRunner.specDir, specFile)); | ||
filePaths.forEach(function(filePath) { | ||
if(jasmineRunner.specFiles.indexOf(filePath) === -1) { | ||
jasmineRunner.specFiles.push(filePath); | ||
} | ||
}); | ||
}); | ||
}; | ||
Jasmine.prototype.execute = function(files) { | ||
if(this.reportersCount === 0) { | ||
this.configureDefaultReporter({}); | ||
} | ||
if (files && files.length > 0) { | ||
this.specDir = ''; | ||
this.specFiles = []; | ||
this.addSpecFiles(files); | ||
} | ||
this.loadSpecs(); | ||
this.env.execute(); | ||
}; |
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"repository": { | ||
@@ -18,5 +18,4 @@ "type": "git", | ||
"dependencies": { | ||
"jasmine-core": "~2.0.1", | ||
"glob": "^3.2.11", | ||
"commander": "~2.1.0" | ||
"jasmine-core": "~2.1.0", | ||
"glob": "^3.2.11" | ||
}, | ||
@@ -23,0 +22,0 @@ "bin": "./bin/jasmine.js", |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
14484
2
11
417
1
+ Addedjasmine-core@2.1.3(transitive)
- Removedcommander@~2.1.0
- Removedcommander@2.1.0(transitive)
- Removedjasmine-core@2.0.4(transitive)
Updatedjasmine-core@~2.1.0