Skip to content

Loading…

Fixes for use with requirejs #135

Merged
merged 6 commits into from

2 participants

@mtscout6

Here are some fixes so that tests loaded with requirejs will work.I am planning to get some tests for this use case in the next week or two.

@mhevery
Owner

Sorry, this is not merging it cleanly, and there are no tests, Could you add some tests and fix the merge conflicts?

@mtscout6

Here are the much desired tests for the requirejs stuff. There is currently only one test that is failing, and I don't know why yet. For some reason a test for object instanceof Date doesn't work. The value is being set, it's just that the instanceof isn't working. I'm looking into it, but for now I feel that is a minor bug in comparison to requirejs not working at all with what's currently on master. I will be looking into that bug again here in the near future when I have more time to investigate it in more detail.

@mhevery
Owner

When I merge your code I get this:

/usr/local/bin/node /Users/misko/work/jasmine-node/lib/jasmine-node/cli.js --coffee .

node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object requirejs.sut has no method 'substring'
at Function._resolveLookupPaths (module.js:235:23)
at Function._resolveFilename (module.js:322:31)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at Object. (/Users/misko/work/jasmine-node/spec-requirejs/requirejs.spec.js:1:63)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)

Process finished with exit code 1

@mtscout6

I believe that this is happening because I have not taken coffee script into account at all with the requirejs implementation. If you specify the spec directory specifically, then your tests will run. I was running the scripts/specs bash file to run the tests, which executes the tests separately from each other.

@mtscout6

Have you had a chance to look at this yet. I've got a lot of people pinging me with questions regarding this.

@mtscout6

Here are the people that have pinged me about this issue, @jmortensen, @MattClevenger, and @saip106. I'm mentioning them here so they get updates regarding this request.

@mhevery
Owner

Sorry about the delay, Lets get this thing merged in today.

but when I run my tests "./specs.sh ." which is my sanity i get this error

dhcp-172-19-43-205:jasmine-node misko$ ./specs.sh .

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
TypeError: Object requirejs.sut has no method 'substring'
    at Function._resolveLookupPaths (module.js:235:23)
    at Function._resolveFilename (module.js:322:31)
    at Function._load (module.js:279:25)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at Object.<anonymous> (/Users/misko/work/jasmine-node/spec-requirejs/requirejs.spec.js:1:63)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
dhcp-172-19-43-205:jasmine-node misko$ 

the expected output is:

dhcp-172-19-43-205:jasmine-node misko$ ./specs.sh .
......F.....F..............................

Failures:

  1) should be timed out
   Message:
     timeout: timed out after 500 msec waiting for MIRACLE
   Stacktrace:
     undefined

  2) should report failure (THIS IS EXPECTED)
   Message:
     Expected true to be falsy.
   Stacktrace:
     Error: Expected true to be falsy.
    at new <anonymous> (/Users/misko/work/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:102:32)
    at [object Object].toBeFalsy (/Users/misko/work/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1171:29)
    at [object Object].<anonymous> (/Users/misko/work/jasmine-node/spec/nested/uber-nested/UberNestedSpec.js:8:20)
    at [object Object].execute (/Users/misko/work/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1001:15)
    at [object Object].next_ (/Users/misko/work/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31)
    at [object Object].start (/Users/misko/work/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1743:8)
    at [object Object].execute (/Users/misko/work/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2070:14)
    at [object Object].next_ (/Users/misko/work/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31)
    at [object Object].start (/Users/misko/work/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1743:8)
    at [object Object].execute (/Users/misko/work/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2215:14)

Finished in 6 seconds
43 tests, 77 assertions, 2 failures
@mtscout6

I had updated the scripts/specs bash file before not the root specs.sh file which I believe was part of the confusion. I updated the specs.sh bash file. It doesn't take arguments anymore as it runs the tests multiple times with different options. I believe this is a more exhaustive test of the runner itself as the parameters to jasmine-node provides various different routes through the utility. The problem with the old script and the reason you were getting the error above is because the requirejs option does not yet support coffeescript. Although this will be a goal going forward, and to avoid confusion, I don't believe that the lack of coffeescript support should be a deal-breaker right now.

Also, I would like to propose we remove the scripts/specs bash file to avoid confusion for others regarding how everyone should run the tests.

@mhevery mhevery merged commit a35f9a8 into mhevery:master
@mhevery
Owner

Thanks

@mtscout6

No, thank you. I apologize for that not being very streamlined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 3, 2012
  1. Fixes for use with requirejs

    Matthew Smith committed
  2. Temporary hot fix for compatability with linux systems.

    Matthew Smith committed
  3. Added tests for running with requirejs and fixed some bugs found in t…

    Matthew Smith committed
    …esting.
  4. Removed this keyword, as it was causing a test failure. Added coffee …

    Matthew Smith committed
    …option to scripts/specs bash test runner
Commits on Apr 10, 2012
  1. Updated root specs.sh to be virtually the same as the scripts/specs b…

    Matthew Smith committed
    …ash file.
  2. Fixed expected assertion count on the requirejs test run

    Matthew Smith committed
View
6 lib/jasmine-node/cli.js
@@ -140,12 +140,6 @@ if(useHelpers){
var regExpSpec = new RegExp(match + (matchall ? "" : "spec\\.") + "(" + extentions + ")$", 'i')
-helperCollection.load(specFolder, regExpSpec);
-
-if(helperCollection.getSpecs().length === 0) {
- match = "";
-}
-
jasmine.executeSpecsInFolder(specFolder,
onComplete,
isVerbose,
View
26 lib/jasmine-node/requirejs-runner.js
@@ -5,37 +5,47 @@ 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 = "",
- thisDir = process.cwd();//.replace(/.:/, '\\c').split('\\'),
+ thisDir = process.cwd(),
toDir = dir.split('/'),
index = 0,
- colonMatches = __dirname.match(/.:/);
+ colonMatches = __dirname.match(/^.:/);
for(var i = 0; i < (colonMatches && colonMatches.length) || 0; i++){
thisDir = thisDir.replace(colonMatches[i], '\\' + colonMatches[i].substring(0,1));
}
- thisDir = thisDir.split('\\');
+ thisDir = thisDir.replace(/\\/g, '/').split('/');
for(; index < thisDir.length || index < toDir.length; index++) {
if(thisDir[index] != toDir[index]){
- for(var i = index; i < thisDir.length; i++){
+ for(var i = index; i < thisDir.length-1; i++){
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
37 lib/jasmine-node/spec-collection.js
@@ -4,31 +4,30 @@ var fs = require('fs');
var specs = [];
var createSpecObj = function(path, root) {
- return {
- path: function() { return path; },
- relativePath: function() { return path.replace(root, '').replace(/^[\/\\]/, ''); },
- directory: function() { return path.replace(/[\/\\][\s\w\.-]*$/, ""); },
- relativeDirectory: function() { return relativePath().replace(/[\/\\][\s\w\.-]*$/, ""); },
- filename: function() { return path.replace(/^.*[\\\/]/, ''); }
- };
+ return {
+ path: function() { return path; },
+ relativePath: function() { return path.replace(root, '').replace(/^[\/\\]/, '').replace(/\\/g, '/'); },
+ directory: function() { return path.replace(/[\/\\][\s\w\.-]*$/, "").replace(/\\/g, '/'); },
+ relativeDirectory: function() { return relativePath().replace(/[\/\\][\s\w\.-]*$/, "").replace(/\\/g, '/'); },
+ filename: function() { return path.replace(/^.*[\\\/]/, ''); }
+ };
};
exports.load = function(loadpath, matcher) {
+ var wannaBeSpecs = walkdir.sync(loadpath)
- var wannaBeSpecs = walkdir.sync(loadpath)
-
- for (var i = 0; i < wannaBeSpecs.length; i++) {
- var file = wannaBeSpecs[i];
- try {
- if (fs.statSync(file).isFile()) {
- if (!/.*node_modules.*/.test(file) && matcher.test(path.basename(file))) {
- specs.push(createSpecObj(file));
- }
- }
- } catch(e) {
- // nothing to do here
+ for (var i = 0; i < wannaBeSpecs.length; i++) {
+ var file = wannaBeSpecs[i];
+ try {
+ if (fs.statSync(file).isFile()) {
+ if (!/.*node_modules.*/.test(file) && matcher.test(path.basename(file))) {
+ specs.push(createSpecObj(file));
}
+ }
+ } catch(e) {
+ // nothing to do here
}
+ }
};
exports.getSpecs = function() {
View
33 scripts/specs
@@ -1,8 +1,37 @@
#!/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 40 tests and 71 assertions and 1 Failure. ---\033[0m"
+ echo ""
+
+ echo "Running all tests located in the spec directory with coffee option"
+ command=$entry"--coffee spec"
+ echo $command
+ time $command #/nested/uber-nested
+ echo -e "\033[1;35m--- Should have 40 tests and 71 assertions and 1 Failure. ---\033[0m"
+ echo ""
+
+ echo "Running all tests located in the spec directory with requirejs option"
+ #command=$entry"--nohelpers --runWithRequireJs spec-requirejs"
+ command=$entry"--runWithRequireJs spec"
+ echo $command
+ time $command
+ echo -e "\033[1;35m--- Should have 40 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
View
8 spec-requirejs/requirejs.spec.js
@@ -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);
+ });
+ });
+});
View
8 spec-requirejs/requirejs.sut.js
@@ -0,0 +1,8 @@
+define(function(){
+ return {
+ name: 'Subject To Test',
+ method: function(input){
+ return 1+input;
+ }
+ };
+});
View
4 spec/async-callback_spec.js
@@ -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);
});
});
@@ -28,7 +28,7 @@ describe('async-callback', function() {
it("should accept timeout for individual spec", function() {
env.describe("it", function() {
env.it("doesn't wait", function(done) {
- this.expect(1+2).toEqual(3);
+ expect(1+2).toEqual(3);
}, 250);
});
View
23 specs.sh
@@ -1,3 +1,24 @@
#!/usr/bin/env bash
-./bin/jasmine-node --coffee "$@"
+entry="node lib/jasmine-node/cli.js "
+
+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 40 tests and 74 assertions and 1 Failure. ---\033[0m"
+echo ""
+
+echo "Running all tests located in the spec directory with coffee option"
+command=$entry"--coffee spec"
+echo $command
+time $command #/nested/uber-nested
+echo -e "\033[1;35m--- Should have 43 tests and 77 assertions and 2 Failures. ---\033[0m"
+echo ""
+
+echo "Running all tests located in the spec directory with requirejs option"
+#command=$entry"--nohelpers --runWithRequireJs spec-requirejs"
+command=$entry"--runWithRequireJs ./"
+echo $command
+time $command
+echo -e "\033[1;35m--- Should have 41 tests and 76 assertions and 1 Failure. ---\033[0m"
Something went wrong with that request. Please try again.