Pass in the current distribution when running node specs

- npm package spec can use beforeAll/afterAll now
- also depend on github repo directly instead of the tarball

[finish #80505862]
This commit is contained in:
slackersoft
2014-10-11 14:54:08 -07:00
parent 916dc03d9c
commit a76d6d1cd4
3 changed files with 25 additions and 18 deletions

View File

@@ -37,13 +37,19 @@ module.exports = function(grunt) {
grunt.registerTask("execSpecsInNode",
"Run Jasmine core specs in Node.js",
function() {
var done = this.async();
require("shelljs").exec("node_modules/.bin/jasmine", function(exitCode) {
if (exitCode !== 0) {
grunt.fail.fatal("Specs Failed", exitCode);
var done = this.async(),
Jasmine = require('jasmine'),
jasmineCore = require('./lib/jasmine-core.js'),
jasmine = new Jasmine({jasmineCore: jasmineCore});
jasmine.loadConfigFile('./spec/support/jasmine.json');
jasmine.configureDefaultReporter({
onComplete: function(passed) {
done(passed);
}
done();
});
jasmine.execute();
}
);

View File

@@ -17,7 +17,7 @@
"grunt-contrib-compress": "~0.5.2",
"shelljs": "~0.1.4",
"glob": "~3.2.9",
"jasmine": "https://github.com/pivotal/jasmine-npm/archive/master.tar.gz",
"jasmine": "pivotal/jasmine",
"load-grunt-tasks": "^0.4.0"
}
}

View File

@@ -1,21 +1,23 @@
describe('npm package', function() {
beforeEach(function() {
var path = require('path'),
fs = require('fs');
beforeAll(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);
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'));
this.packagedCore = require(path.join(this.tmpDir, 'package/lib/jasmine-core.js'));
});
beforeEach(function() {
jasmine.addMatchers({
toExistInPath: function(util, customEquality) {
return {
@@ -30,8 +32,7 @@ describe('npm package', function() {
});
});
afterEach(function() {
var path = this.path, fs = this.fs;
afterAll(function() {
var cleanup = function (parent, fileOrFolder) {
var fullPath = path.join(parent, fileOrFolder);
if (fs.statSync(fullPath).isFile()) {
@@ -48,11 +49,11 @@ describe('npm package', function() {
});
it('has a root path', function() {
expect(this.packagedCore.files.path).toEqual(this.fs.realpathSync(this.path.resolve(this.tmpDir, 'package/lib/jasmine-core')));
expect(this.packagedCore.files.path).toEqual(fs.realpathSync(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')));
expect(this.packagedCore.files.bootDir).toEqual(fs.realpathSync(path.resolve(this.tmpDir, 'package/lib/jasmine-core')));
});
it('has jsFiles', function() {
@@ -93,8 +94,8 @@ describe('npm package', function() {
});
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(this.packagedCore.files.imagesDir).toEqual(fs.realpathSync(path.resolve(this.tmpDir, 'package/images')));
var images = fs.readdirSync(path.resolve(this.tmpDir, 'package/images'));
expect(images).toContain('jasmine-horizontal.png');
expect(images).toContain('jasmine-horizontal.svg');