Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Add a main entry point for the jasmine-core npm

- jasmine-core can now self test with the jasmine-npm
- Add node examples files
- Add node_boot.js for node environment
- Move jasmine-core npm packaging to .npmignore
- removing src_dir and src_files from jasmine.json b/c jasmine-npm does not support requiring source files automatically.
  • Loading branch information...
commit e53b4870171ec272d08d2fe6e99c4aec224889c5 1 parent ed5cd6b
Christopher Amavisca and Davis W Frank authored
View
23 .npmignore
@@ -0,0 +1,23 @@
+dist/
+grunt/
+images/
+node_modules
+release_notes/
+spec/
+src/
+Gemfile
+Gemfile.lock
+Rakefile
+jasmine-core.gemspec
+.rspec
+.travis.yml
+.jshintrc
+.gitignore
+*.sh
+Gruntfile.js
+lib/jasmine-core/boot/
+lib/jasmine-core/boot.js
+lib/jasmine-core/spec
+lib/jasmine-core/*.css
+lib/jasmine-core/jasmine-html.js
+lib/jasmine-core/version.rb
View
17 Gruntfile.js
@@ -34,11 +34,20 @@ module.exports = function(grunt) {
]
);
- var spec = require('./grunt/tasks/spec.js');
-
grunt.registerTask("execSpecsInNode",
- "Run Jasmine core specs in Node.js",
- spec.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);
+ }
+ }
);
+ grunt.registerTask("execSpecsInNode:performance",
+ "Run Jasmine performance specs in Node.js",
+ function() {
+ require("shelljs").exec("node_modules/.bin/jasmine JASMINE_CONFIG_PATH=spec/support/jasmine-performance.json");
+ }
+ );
};
View
4 grunt/config/concat.js
@@ -39,6 +39,10 @@ module.exports = {
src: ['lib/jasmine-core/boot/boot.js'],
dest: 'lib/jasmine-core/boot.js'
},
+ nodeBoot: {
+ src: ['lib/jasmine-core/boot/node_boot.js'],
+ dest: 'lib/jasmine-core/node_boot.js'
+ },
console: {
src: [
'src/console/requireConsole.js',
View
11 grunt/tasks/spec.js
@@ -1,11 +0,0 @@
-var shell = require('shelljs');
-var grunt = require('grunt');
-
-module.exports = {
- execSpecsInNode: function() {
- var exit_code = shell.exec("node spec/node_suite.js --color=true").code;
- if (exit_code !== 0) {
- grunt.fail.fatal("Specs Failed", exit_code);
- }
- }
-};
View
2  lib/jasmine-core.js
@@ -0,0 +1,2 @@
+module.exports = require("./jasmine-core/jasmine.js");
+module.exports.boot = require('./jasmine-core/node_boot.js');
View
8 lib/jasmine-core.rb
@@ -6,7 +6,7 @@ def path
end
def js_files
- (["jasmine.js"] + Dir.glob(File.join(path, "*.js"))).map { |f| File.basename(f) }.uniq - boot_files
+ (["jasmine.js"] + Dir.glob(File.join(path, "*.js"))).map { |f| File.basename(f) }.uniq - boot_files - node_boot_files
end
SPEC_TYPES = ["core", "html", "node"]
@@ -27,8 +27,12 @@ def boot_files
["boot.js"]
end
+ def node_boot_files
+ ["node_boot.js"]
+ end
+
def boot_dir
- File.join(path, 'boot')
+ path
end
def spec_files(type)
View
71 lib/jasmine-core/boot/node_boot.js
@@ -0,0 +1,71 @@
+module.exports = function(jasmineRequire) {
+ var jasmine = jasmineRequire.core(jasmineRequire);
+
+ var consoleFns = require('../console/console.js');
+ consoleFns.console(consoleFns, jasmine);
+
+ var env = jasmine.getEnv();
+
+ var jasmineInterface = {
+ describe: function(description, specDefinitions) {
+ return env.describe(description, specDefinitions);
+ },
+
+ xdescribe: function(description, specDefinitions) {
+ return env.xdescribe(description, specDefinitions);
+ },
+
+ it: function(desc, func) {
+ return env.it(desc, func);
+ },
+
+ xit: function(desc, func) {
+ return env.xit(desc, func);
+ },
+
+ beforeEach: function(beforeEachFunction) {
+ return env.beforeEach(beforeEachFunction);
+ },
+
+ afterEach: function(afterEachFunction) {
+ return env.afterEach(afterEachFunction);
+ },
+
+ expect: function(actual) {
+ return env.expect(actual);
+ },
+
+ spyOn: function(obj, methodName) {
+ return env.spyOn(obj, methodName);
+ },
+
+ jsApiReporter: new jasmine.JsApiReporter({
+ timer: new jasmine.Timer()
+ }),
+
+
+ jasmine: jasmine
+ };
+
+ extend(global, jasmineInterface);
+
+ jasmine.addCustomEqualityTester = function(tester) {
+ env.addCustomEqualityTester(tester);
+ };
+
+ jasmine.addMatchers = function(matchers) {
+ return env.addMatchers(matchers);
+ };
+
+ jasmine.clock = function() {
+ return env.clock;
+ };
+
+ function extend(destination, source) {
+ for (var property in source) destination[property] = source[property];
+ return destination;
+ }
+
+
+ return jasmine;
+};
View
60 lib/jasmine-core/example/node_example/spec/PlayerSpec.js
@@ -0,0 +1,60 @@
+describe("Player", function() {
+ var Player = require('../../jasmine_examples/Player.js');
+ var Song = require('../../jasmine_examples/Song.js');
+ var player;
+ var song;
+
+ beforeEach(function() {
+ player = new Player();
+ song = new Song();
+ });
+
+ it("should be able to play a Song", function() {
+ player.play(song);
+ expect(player.currentlyPlayingSong).toEqual(song);
+
+ //demonstrates use of custom matcher
+ expect(player).toBePlaying(song);
+ });
+
+ describe("when song has been paused", function() {
+ beforeEach(function() {
+ player.play(song);
+ player.pause();
+ });
+
+ it("should indicate that the song is currently paused", function() {
+ expect(player.isPlaying).toBeFalsy();
+
+ // demonstrates use of 'not' with a custom matcher
+ expect(player).not.toBePlaying(song);
+ });
+
+ it("should be possible to resume", function() {
+ player.resume();
+ expect(player.isPlaying).toBeTruthy();
+ expect(player.currentlyPlayingSong).toEqual(song);
+ });
+ });
+
+ // demonstrates use of spies to intercept and test method calls
+ it("tells the current song if the user has made it a favorite", function() {
+ spyOn(song, 'persistFavoriteStatus');
+
+ player.play(song);
+ player.makeFavorite();
+
+ expect(song.persistFavoriteStatus).toHaveBeenCalledWith(true);
+ });
+
+ //demonstrates use of expected exceptions
+ describe("#resume", function() {
+ it("should throw an exception if song is already playing", function() {
+ player.play(song);
+
+ expect(function() {
+ player.resume();
+ }).toThrowError("song is already playing");
+ });
+ });
+});
View
15 lib/jasmine-core/example/node_example/spec/SpecHelper.js
@@ -0,0 +1,15 @@
+beforeEach(function () {
+ jasmine.addMatchers({
+ toBePlaying: function () {
+ return {
+ compare: function (actual, expected) {
+ var player = actual;
+
+ return {
+ pass: player.currentlyPlayingSong === expected && player.isPlaying
+ }
+ }
+ };
+ }
+ });
+});
View
24 lib/jasmine-core/example/node_example/src/Player.js
@@ -0,0 +1,24 @@
+function Player() {
+}
+Player.prototype.play = function(song) {
+ this.currentlyPlayingSong = song;
+ this.isPlaying = true;
+};
+
+Player.prototype.pause = function() {
+ this.isPlaying = false;
+};
+
+Player.prototype.resume = function() {
+ if (this.isPlaying) {
+ throw new Error("song is already playing");
+ }
+
+ this.isPlaying = true;
+};
+
+Player.prototype.makeFavorite = function() {
+ this.currentlyPlayingSong.persistFavoriteStatus(true);
+};
+
+module.exports = Player;
View
9 lib/jasmine-core/example/node_example/src/Song.js
@@ -0,0 +1,9 @@
+function Song() {
+}
+
+Song.prototype.persistFavoriteStatus = function(value) {
+ // something complicated
+ throw new Error("not yet implemented");
+};
+
+module.exports = Song;
View
93 lib/jasmine-core/node_boot.js
@@ -0,0 +1,93 @@
+/*
+Copyright (c) 2008-2014 Pivotal Labs
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+module.exports = function(jasmineRequire) {
+ var jasmine = jasmineRequire.core(jasmineRequire);
+
+ var consoleFns = require('../console/console.js');
+ consoleFns.console(consoleFns, jasmine);
+
+ var env = jasmine.getEnv();
+
+ var jasmineInterface = {
+ describe: function(description, specDefinitions) {
+ return env.describe(description, specDefinitions);
+ },
+
+ xdescribe: function(description, specDefinitions) {
+ return env.xdescribe(description, specDefinitions);
+ },
+
+ it: function(desc, func) {
+ return env.it(desc, func);
+ },
+
+ xit: function(desc, func) {
+ return env.xit(desc, func);
+ },
+
+ beforeEach: function(beforeEachFunction) {
+ return env.beforeEach(beforeEachFunction);
+ },
+
+ afterEach: function(afterEachFunction) {
+ return env.afterEach(afterEachFunction);
+ },
+
+ expect: function(actual) {
+ return env.expect(actual);
+ },
+
+ spyOn: function(obj, methodName) {
+ return env.spyOn(obj, methodName);
+ },
+
+ jsApiReporter: new jasmine.JsApiReporter({
+ timer: new jasmine.Timer()
+ }),
+
+
+ jasmine: jasmine
+ };
+
+ extend(global, jasmineInterface);
+
+ jasmine.addCustomEqualityTester = function(tester) {
+ env.addCustomEqualityTester(tester);
+ };
+
+ jasmine.addMatchers = function(matchers) {
+ return env.addMatchers(matchers);
+ };
+
+ jasmine.clock = function() {
+ return env.clock;
+ };
+
+ function extend(destination, source) {
+ for (var property in source) destination[property] = source[property];
+ return destination;
+ }
+
+
+ return jasmine;
+};
View
11 package.json
@@ -8,17 +8,16 @@
},
"description": "Official packaging of Jasmine's core files for use by Node.js projects.",
"homepage": "http://jasmine.github.io",
- "files": [
- "lib/console",
- "lib/jasmine-core"
- ],
+ "main": "./lib/jasmine-core.js",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.7.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-compass": "~0.6.0",
"grunt-contrib-compress": "~0.5.2",
- "load-grunt-tasks": "0.3.0",
- "shelljs": "~0.1.4"
+ "shelljs": "~0.1.4",
+ "glob": "~3.2.9",
+ "jasmine": "https://github.com/pivotal/jasmine-npm/archive/master.tar.gz",
+ "load-grunt-tasks": "^0.4.0"
}
}
View
33 spec/helpers/nodeDefineJasmineUnderTest.js
@@ -0,0 +1,33 @@
+(function() {
+ var path = require("path"),
+ fs = require("fs");
+
+ var glob = require("glob");
+
+ var j$Require = require(path.join(__dirname, "../../src/core/requireCore.js"));
+
+ global.getJasmineRequireObj = function () {
+ return j$Require;
+ };
+
+ function extend(destination, source) {
+ for (var property in source) destination[property] = source[property];
+ return destination;
+ }
+
+ function getSourceFiles() {
+ var src_files = ['core/**/*.js', 'console/**/*.js', 'version.js'];
+ src_files.forEach(function(file) {
+ var filePath = path.join(__dirname, "../../", 'src/', file);
+ glob.sync(filePath).forEach(function(resolvedFile) {
+ require(resolvedFile);
+ });
+ });
+ }
+
+ extend(j$Require, require(path.join(__dirname,"../../src/console/requireConsole.js")));
+ getSourceFiles();
+ global.j$ = j$Require.core(j$Require);
+
+ j$Require.console(j$Require, j$);
+})();
View
187 spec/node_suite.js
@@ -1,187 +0,0 @@
-var fs = require('fs');
-var util = require('util');
-var path = require('path');
-
-// boot code for jasmine
-var jasmineRequire = require('../lib/jasmine-core/jasmine.js');
-var jasmine = jasmineRequire.core(jasmineRequire);
-
-var consoleFns = require('../lib/console/console.js');
-extend(jasmineRequire, consoleFns);
-jasmineRequire.console(jasmineRequire, jasmine);
-
-var env = jasmine.getEnv();
-
-var jasmineInterface = {
- describe: function(description, specDefinitions) {
- return env.describe(description, specDefinitions);
- },
-
- xdescribe: function(description, specDefinitions) {
- return env.xdescribe(description, specDefinitions);
- },
-
- it: function(desc, func) {
- return env.it(desc, func);
- },
-
- xit: function(desc, func) {
- return env.xit(desc, func);
- },
-
- beforeEach: function(beforeEachFunction) {
- return env.beforeEach(beforeEachFunction);
- },
-
- afterEach: function(afterEachFunction) {
- return env.afterEach(afterEachFunction);
- },
-
- expect: function(actual) {
- return env.expect(actual);
- },
-
- spyOn: function(obj, methodName) {
- return env.spyOn(obj, methodName);
- },
-
- jsApiReporter: new jasmine.JsApiReporter({
- timer: new jasmine.Timer()
- })
-};
-
-extend(global, jasmineInterface);
-
-function extend(destination, source) {
- for (var property in source) destination[property] = source[property];
- return destination;
-}
-
-jasmine.addCustomEqualityTester = function(tester) {
- env.addCustomEqualityTester(tester);
-};
-
-jasmine.addMatchers = function(matchers) {
- return env.addMatchers(matchers);
-};
-
-jasmine.clock = function() {
- return env.clock;
-};
-
-// Jasmine "runner"
-function executeSpecs(specs, done, isVerbose, showColors) {
- global.jasmine = jasmine;
-
- for (var i = 0; i < specs.length; i++) {
- var filename = specs[i];
- require(filename.replace(/\.\w+$/, ""));
- }
-
- var env = jasmine.getEnv();
- var consoleReporter = new jasmine.ConsoleReporter({
- print: util.print,
- onComplete: done,
- showColors: showColors,
- timer: new jasmine.Timer()
- });
-
- env.addReporter(consoleReporter);
- env.execute();
-}
-
-function getFiles(dir, matcher) {
- var allFiles = [];
-
- if (fs.statSync(dir).isFile() && dir.match(matcher)) {
- allFiles.push(dir);
- } else {
- var files = fs.readdirSync(dir);
- for (var i = 0, len = files.length; i < len; ++i) {
- var filename = dir + '/' + files[i];
- if (fs.statSync(filename).isFile() && filename.match(matcher)) {
- allFiles.push(filename);
- } else if (fs.statSync(filename).isDirectory()) {
- var subfiles = getFiles(filename);
- subfiles.forEach(function(result) {
- allFiles.push(result);
- });
- }
- }
- }
- return allFiles;
-}
-
-function getSpecFiles(dir) {
- return getFiles(dir, new RegExp("Spec.js$"));
-}
-
-var j$require = (function() {
- var exported = {},
- j$req;
-
- global.getJasmineRequireObj = getJasmineRequireObj;
-
- j$req = require(__dirname + "/../src/core/requireCore.js");
- extend(j$req, require(__dirname + "/../src/console/requireConsole.js"));
-
- var srcFiles = getFiles(__dirname + "/../src/core");
- srcFiles.push(__dirname + "/../src/version.js");
- srcFiles.push(__dirname + "/../src/console/ConsoleReporter.js");
-
- for (var i = 0; i < srcFiles.length; i++) {
- require(srcFiles[i]);
- }
- extend(j$req, exported);
-
- delete global.getJasmineRequireObj;
-
- return j$req;
-
- function getJasmineRequireObj() {
- return exported;
- }
-}());
-
-j$ = j$require.core(j$require);
-j$require.console(j$require, j$);
-
-// options from command line
-var isVerbose = false;
-var showColors = true;
-var perfSuite = false;
-
-process.argv.forEach(function(arg) {
- switch (arg) {
- case '--color':
- showColors = true;
- break;
- case '--noColor':
- showColors = false;
- break;
- case '--verbose':
- isVerbose = true;
- break;
- case '--perf':
- perfSuite = true;
- break;
- }
-});
-
-specs = [];
-
-if (perfSuite) {
- specs = getFiles(__dirname + '/performance', new RegExp("test.js$"));
-} else {
- var consoleSpecs = getSpecFiles(__dirname + "/console"),
- coreSpecs = getSpecFiles(__dirname + "/core"),
- specs = consoleSpecs.concat(coreSpecs);
-}
-
-executeSpecs(specs, function(passed) {
- if (passed) {
- process.exit(0);
- } else {
- process.exit(1);
- }
-}, isVerbose, showColors);
View
9 spec/support/jasmine-performance.json
@@ -0,0 +1,9 @@
+{
+ "spec_dir": "spec",
+ "spec_files": [
+ "performance/performance_test.js"
+ ],
+ "helper_files": [
+ "helpers/nodeDefineJasmineUnderTest.js"
+ ]
+}
View
10 spec/support/jasmine.json
@@ -0,0 +1,10 @@
+{
+ "spec_dir": "spec",
+ "spec_files": [
+ "core/**/*.js",
+ "console/**/*.js"
+ ],
+ "helpers": [
+ "helpers/nodeDefineJasmineUnderTest.js"
+ ]
+}
View
3  spec/support/jasmine.yml
@@ -16,7 +16,8 @@ src_files:
- '**/*.js'
stylesheets:
helpers:
- - 'helpers/**/*.js'
+ - 'helpers/BrowserFlags.js'
+ - 'helpers/defineJasmineUnderTest.js'
spec_files:
- '**/*[Ss]pec.js'
spec_dir: spec
Please sign in to comment.
Something went wrong with that request. Please try again.