diff --git a/Gruntfile.js b/Gruntfile.js index f4319b7e..fa07b363 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -37,10 +37,13 @@ module.exports = function(grunt) { grunt.registerTask("execSpecsInNode", "Run Jasmine core specs in Node.js", function() { - var exitInfo = require("shelljs").exec("node_modules/.bin/jasmine"); - if (exitInfo.code !== 0) { - grunt.fail.fatal("Specs Failed", exitInfo.code); - } + var done = this.async(); + require("shelljs").exec("node_modules/.bin/jasmine", function(exitCode) { + if (exitCode !== 0) { + grunt.fail.fatal("Specs Failed", exitCode); + } + done(); + }); } ); diff --git a/lib/jasmine-core.js b/lib/jasmine-core.js index cb977db9..fe0ecd8d 100644 --- a/lib/jasmine-core.js +++ b/lib/jasmine-core.js @@ -1,39 +1,37 @@ module.exports = require("./jasmine-core/jasmine.js"); module.exports.boot = require('./jasmine-core/node_boot.js'); -module.exports.files = (function() { - var path = require('path'), - fs = require('fs'); +var path = require('path'), + fs = require('fs'); - var rootPath = path.join(__dirname, "jasmine-core"), - bootFiles = ['boot.js'], - nodeBootFiles = ['node_boot.js'], - cssFiles = [], - jsFiles = [], - jsFilesToSkip = ['jasmine.js'].concat(bootFiles, nodeBootFiles); +var rootPath = path.join(__dirname, "jasmine-core"), + bootFiles = ['boot.js'], + nodeBootFiles = ['node_boot.js'], + cssFiles = [], + jsFiles = [], + jsFilesToSkip = ['jasmine.js'].concat(bootFiles, nodeBootFiles); - fs.readdirSync(rootPath).forEach(function(file) { - if(fs.statSync(path.join(rootPath, file)).isFile()) { - switch(path.extname(file)) { - case '.css': - cssFiles.push(file); - break; - case '.js': - if (jsFilesToSkip.indexOf(file) < 0) { - jsFiles.push(file); - } - break; +fs.readdirSync(rootPath).forEach(function(file) { + if(fs.statSync(path.join(rootPath, file)).isFile()) { + switch(path.extname(file)) { + case '.css': + cssFiles.push(file); + break; + case '.js': + if (jsFilesToSkip.indexOf(file) < 0) { + jsFiles.push(file); } + break; } - }); + } +}); - return { - path: rootPath, - bootDir: rootPath, - bootFiles: bootFiles, - nodeBootFiles: nodeBootFiles, - cssFiles: cssFiles, - jsFiles: ['jasmine.js'].concat(jsFiles), - imagesDir: path.join(__dirname, '../images') - }; -}()); +module.exports.files = { + path: rootPath, + bootDir: rootPath, + bootFiles: bootFiles, + nodeBootFiles: nodeBootFiles, + cssFiles: cssFiles, + jsFiles: ['jasmine.js'].concat(jsFiles), + imagesDir: path.join(__dirname, '../images') +}; diff --git a/spec/npmPackage/npmPackageSpec.js b/spec/npmPackage/npmPackageSpec.js new file mode 100644 index 00000000..aac47b40 --- /dev/null +++ b/spec/npmPackage/npmPackageSpec.js @@ -0,0 +1,103 @@ +describe('npm package', function() { + beforeEach(function() { + var shell = require('shelljs'), + pack = shell.exec('npm pack', { silent: true }); + + this.tarball = pack.output.split('\n')[0]; + this.tmpDir = '/tmp/jasmine-core'; + + var path = this.path = require('path'); + var fs = this.fs = require('fs'); + + this.fs.mkdirSync(this.tmpDir); + + var untar = shell.exec('tar -xzf ' + this.tarball + ' -C ' + this.tmpDir, { silent: true }); + expect(untar.code).toBe(0); + + this.packagedCore = require(this.path.join(this.tmpDir, 'package/lib/jasmine-core.js')); + + jasmine.addMatchers({ + toExistInPath: function(util, customEquality) { + return { + compare: function(actual, expected) { + var fullPath = path.resolve(expected, actual); + return { + pass: fs.existsSync(fullPath) + }; + } + }; + } + }); + }); + + afterEach(function() { + var path = this.path, fs = this.fs; + var cleanup = function (parent, fileOrFolder) { + var fullPath = path.join(parent, fileOrFolder); + if (fs.statSync(fullPath).isFile()) { + fs.unlinkSync(fullPath); + } else { + fs.readdirSync(fullPath).forEach(cleanup.bind(null, fullPath)); + fs.rmdirSync(fullPath); + } + }; + + fs.unlink(this.tarball); + fs.readdirSync(this.tmpDir).forEach(cleanup.bind(null, this.tmpDir)); + fs.rmdirSync(this.tmpDir); + }); + + it('has a root path', function() { + expect(this.packagedCore.files.path).toEqual(this.fs.realpathSync(this.path.resolve(this.tmpDir, 'package/lib/jasmine-core'))); + }); + + it('has a bootDir', function() { + expect(this.packagedCore.files.bootDir).toEqual(this.fs.realpathSync(this.path.resolve(this.tmpDir, 'package/lib/jasmine-core'))); + }); + + it('has jsFiles', function() { + expect(this.packagedCore.files.jsFiles).toEqual([ + 'jasmine.js', + 'jasmine-html.js', + 'json2.js' + ]); + + var packagedCore = this.packagedCore; + this.packagedCore.files.jsFiles.forEach(function(fileName) { + expect(fileName).toExistInPath(packagedCore.files.path); + }); + }); + + it('has cssFiles', function() { + expect(this.packagedCore.files.cssFiles).toEqual(['jasmine.css']); + + var packagedCore = this.packagedCore; + this.packagedCore.files.cssFiles.forEach(function(fileName) { + expect(fileName).toExistInPath(packagedCore.files.path); + }); + }); + + it('has bootFiles', function() { + expect(this.packagedCore.files.bootFiles).toEqual(['boot.js']); + expect(this.packagedCore.files.nodeBootFiles).toEqual(['node_boot.js']); + + var packagedCore = this.packagedCore; + this.packagedCore.files.bootFiles.forEach(function(fileName) { + expect(fileName).toExistInPath(packagedCore.files.bootDir); + }); + + var packagedCore = this.packagedCore; + this.packagedCore.files.nodeBootFiles.forEach(function(fileName) { + expect(fileName).toExistInPath(packagedCore.files.bootDir); + }); + }); + + it('has an imagesDir', function() { + expect(this.packagedCore.files.imagesDir).toEqual(this.fs.realpathSync(this.path.resolve(this.tmpDir, 'package/images'))); + var images = this.fs.readdirSync(this.path.resolve(this.tmpDir, 'package/images')); + + expect(images).toContain('jasmine-horizontal.png'); + expect(images).toContain('jasmine-horizontal.svg'); + expect(images).toContain('jasmine_favicon.png'); + }); +}); diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json index 8583679e..564302d4 100644 --- a/spec/support/jasmine.json +++ b/spec/support/jasmine.json @@ -2,7 +2,8 @@ "spec_dir": "spec", "spec_files": [ "core/**/*.js", - "console/**/*.js" + "console/**/*.js", + "npmPackage/**/*.js" ], "helpers": [ "helpers/nodeDefineJasmineUnderTest.js"