Add some tests to make sure we're packaging up the npm properly
This commit is contained in:
11
Gruntfile.js
11
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();
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -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')
|
||||
};
|
||||
|
||||
103
spec/npmPackage/npmPackageSpec.js
Normal file
103
spec/npmPackage/npmPackageSpec.js
Normal file
@@ -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');
|
||||
});
|
||||
});
|
||||
@@ -2,7 +2,8 @@
|
||||
"spec_dir": "spec",
|
||||
"spec_files": [
|
||||
"core/**/*.js",
|
||||
"console/**/*.js"
|
||||
"console/**/*.js",
|
||||
"npmPackage/**/*.js"
|
||||
],
|
||||
"helpers": [
|
||||
"helpers/nodeDefineJasmineUnderTest.js"
|
||||
|
||||
Reference in New Issue
Block a user