Permalink
Browse files

Added tests for running with requirejs and fixed some bugs found in t…

…esting.
  • Loading branch information...
1 parent e5702f5 commit cd084580fc74341b7e32b6f561b1d37f41d055f6 Matthew Smith committed Apr 3, 2012
@@ -5,20 +5,30 @@ exports.executeJsRunner = function(specCollection, done, jasmineEnv) {
vm = require('vm'),
fs = require('fs'),
template = fs.readFileSync(__dirname + '/requirejs-wrapper-template.js', 'utf8'),
- buildNewContext = function(){
- return {
+ buildNewContext = function(spec){
+ var context = {
describe: describe,
it: it,
xdescribe: xdescribe,
xit: xit,
+ beforeEach: beforeEach,
+ spyOn: spyOn,
+ waitsFor: waitsFor,
+ runs: runs,
jasmine: jasmine,
expect: expect,
require: require,
console: console,
process: process,
module: module,
- specLoader: specLoader
+ specLoader: specLoader,
+ __dirname: spec.directory(),
+ __filename: spec.path()
};
+
+ context.global = context;
+
+ return context;
},
buildRelativeDirName = function(dir){
var retVal = "",
@@ -63,7 +73,7 @@ exports.executeJsRunner = function(specCollection, done, jasmineEnv) {
wrappedScript = template.replace(/#REPLACE URL#/, buildRelativeDirName(dir))
.replace(/#REPLACE TEST SCRIPT#/, script);
- vm.runInNewContext(wrappedScript, buildNewContext(), s.path());
+ vm.runInNewContext(wrappedScript, buildNewContext(s), s.path());
});
specLoader.executeWhenAllSpecsAreComplete(jasmineEnv);
View
@@ -1,8 +1,30 @@
#!/bin/bash
+entry="node lib/jasmine-node/cli.js "
+
if [ $# -ne 0 ]; then
- command="node lib/jasmine-node/cli.js $1 spec"
+ command=$entry"$1 spec"
+ echo $command
$command
else
- time node lib/jasmine-node/cli.js spec #/nested/uber-nested
+ echo "Running all tests located in the spec directory"
+ command=$entry"spec"
+ echo $command
+ time $command #/nested/uber-nested
+ echo -e "\033[1;35m--- Should have 39 tests and 71 assertions and 1 Failure. ---\033[0m"
+ echo ""
+
+ echo "Running all tests located in the spec directory with requirejs"
+ #command=$entry"--nohelpers --runWithRequireJs spec-requirejs"
+ command=$entry"--runWithRequireJs spec"
+ echo $command
+ time $command
+ echo -e "\033[1;35m--- Should have 39 tests and 71 assertions and 1 Failure. ---\033[0m"
+
+ echo "Running all tests located in the spec-requirejs directory with requirejs"
+ #command=$entry"--nohelpers --runWithRequireJs spec-requirejs"
+ command=$entry"--runWithRequireJs spec-requirejs"
+ echo $command
+ time $command
+ echo -e "\033[1;35m--- Should have 1 test and 2 assertions and 0 Failures. ---\033[0m"
fi
@@ -0,0 +1,8 @@
+require(['requirejs.sut'], function(sut){
+ describe('RequireJs basic tests', function(){
+ it('should load sut', function(){
+ expect(sut.name).toBe('Subject To Test');
+ expect(sut.method(2)).toBe(3);
+ });
+ });
+});
@@ -0,0 +1,8 @@
+define(function(){
+ return {
+ name: 'Subject To Test',
+ method: function(input){
+ return 1+input;
+ }
+ };
+});
@@ -9,7 +9,7 @@ describe('async-callback', function() {
it("should time out if callback is not called", function() {
env.describe("it", function() {
env.it("doesn't wait", function(done) {
- this.expect(1+2).toEqual(3);
+ expect(1+2).toEqual(3);
});
});

0 comments on commit cd08458

Please sign in to comment.