jasmine-contrib / grunt-jasmine-runner Goto Github PK
View Code? Open in Web Editor NEWGrunt task to run jasmine unit tests through phantomjs
License: MIT License
Grunt task to run jasmine unit tests through phantomjs
License: MIT License
Firstly, thanks for this very useful plugin - much cleaner than my previous method of tying Jasmine into my build / CI process :)
A little thing I've noticed is that _SpecRunner.html is copied to the working directory when I run this task and isn't deleted when the task finishes. It would be great if the file was deleted when the task completes...
hi
i just started to write my very first script using jasmine , this is my AddressBookSpec.js file:
describe('Address Book', Function(){
it ('should be able to add a contact', function(){
var addressBook = new addressBook();
thisContact = new contact();
addressBook.addContact(thisContact);
expect(addressBook.getContact(0)).toBe(thisContact);
});
});
im trying to learn jasmine sing udemy courses and want to see the error the instructor got in specrunner in my browser , but after running specrunner on browser i have nothing there but just this:
Can anybody please help with that ?
Thanks
hi i'm jimmy.
i have a question. i'm using grunt-jasmine-runner to make a chrome extension. sometime i have to get data from a different domain via ajax. but server, is launched by grunt with jasmine-server argument, i can't get a any result. as you know, the server is not allowed that according to Access-Control-Allow-Origin.
how can i configure the server to allow to access a different domain via ajax. like as apache.
If I visit my test page through the browser, all the specs pass.
Running 'grunt jasmine' via command line, no tests get executed and I get the error 'Can't find variable require' so I'm wondering if the helpers array is being loaded in the correct order.
My project structure is like this:
/
/src/
/tests/
/tests/SpecRunner.js
/tests/specs/
/grunt.js
I have my main project config for requirejs in grunt.js, but I also have a requirejs config in SpecRunner.js to load the test.
Is my helper supposed to point to the require config for the project or the tests?
Here's the relevant part from grunt.js:
jasmine: {
amd: true,
specs: 'tests/spec/**/*spec.js',
timeout : 10000,
helpers: [
"../node_modules/requirejs/require.js",
"tests/SpecRunner.js"
],
junit: {
output: 'target/junit/'
}
}
In my package.json dependencies I've linked directly to this repo to try the most recent version.
This is a placeholder for ongoing work to support AMD testing.
Post here to bring up details about personal testing process that you might want accounted for.
Running
$ ./node_modules/.bin/grunt jasmine-server
produces the following error.
$ ./node_modules/.bin/grunt jasmine-server
path.existsSync is now called `fs.existsSync`.
Running "jasmine-server" task
TypeError: undefined is not a function
at Object.module.exports.grunt.registerHelper.jasmineCss (/Users/cburgmer/projekte/csscritic/node_modules/grunt-jasmine-runner/tasks/jasmine.js:96:5)
at Task.helper (/Users/cburgmer/projekte/csscritic/node_modules/grunt/lib/util/task.js:117:19)
at Object.<anonymous> (/Users/cburgmer/projekte/csscritic/node_modules/grunt-jasmine-runner/tasks/jasmine.js:52:11)
at Object.task.registerTask.thisTask.fn (/Users/cburgmer/projekte/csscritic/node_modules/grunt/lib/grunt/task.js:56:16)
at Task.<anonymous> (/Users/cburgmer/projekte/csscritic/node_modules/grunt/lib/util/task.js:341:36)
at Task.start (/Users/cburgmer/projekte/csscritic/node_modules/grunt/lib/util/task.js:357:5)
at Object.grunt.tasks (/Users/cburgmer/projekte/csscritic/node_modules/grunt/lib/grunt.js:143:8)
at Object.module.exports [as cli] (/Users/cburgmer/projekte/csscritic/node_modules/grunt/lib/grunt/cli.js:36:9)
at Object.<anonymous> (/Users/cburgmer/projekte/csscritic/node_modules/grunt/bin/grunt:16:14)
at Module._compile (module.js:449:26)
Installed via
$ npm install grunt-jasmine-runner
I'm posting this issue to let you know that we will be publishing Grunt 0.4 on Monday, February 18th.
If your plugin is not already Grunt 0.4 compatible, would you please consider updating it? For an overview of what's changed, please see our migration guide.
If you'd like to develop against the final version of Grunt before Monday, please specify "grunt": "0.4.0rc8"
as a devDependency in your project. After Monday's release, you'll be able to use "grunt": "~0.4.0"
to actually publish your plugin. If you depend on any plugins from the grunt-contrib series, please see our list of release candidates for compatible versions. All of these will be updated to final status when Grunt 0.4 is published.
Also, in an effort to reduce duplication of effort and fragmentation in the developer community, could you review the grunt-contrib series of plugins to see if any of your functionality overlaps significantly with them? Grunt-contrib is community maintained with 40+ contributors—we'd love to discuss any additions you'd like to make.
Finally, we're working on a new task format that doesn't depend on Grunt: it's called node-task. Once this is complete, there will be one more conversion, and then we'll never ask you to upgrade your plugins to support our changes again. Until that happens, thanks for bearing with us!
If you have any questions about how to proceed, please respond here, or join us in #grunt on irc.freenode.net.
Thanks, we really appreciate your work!
Hi, I'm having a bit of a problem trying to get my specs to run from a different folder than the one containing my _SpecRunner.
My grunt.js configuration looks like this:
jasmine: {
src: ['../..app/js/main.js'],
specs: ['../../test/tests1.js', '../../test/other/tests2.js'],
helpers: ["../../app/lib/jquery.js", "../../app/lib/require.js", "../../test/requireConfig.js"],
amd: true
}
This is what the require comes out to on my _SpecRunner.html:
require([
'C:/foo/bar/test/tests1.js' ,
'C:/foo/bar/test/other/tests2.js'
]);
tests1.js is a very simple file:
define(["../../app/js/main.js"], function (main) {
describe("Main", function () {
it("Should expect correct logic.", function () {
expect(true).toBeTruthy();
});
});
});
tests2.js is more complicated but I get the same type of response if I only include/use tests1.js
This is what I'm getting in the console:
C:\foo\bar\build\grunt>grunt.cmd jasmine
Running "jasmine" task
Testing jasmine specs via phantom
0 specs, 0 failures in 0.001s.
Done, without errors.
This is my folder structure:
foo/
-->bar/
------->app/
----------->js/
-------------->main.js
------->build/
----------->grunt/
-------------->grunt.js
-------------->_SpecRunnet.html
-------------->node_modules/ -> grunt-jasmine-runner
-------->test/
----------->tests1.js
----------->other/
-------------->tests2.js
Worst case scenario I should be getting at least 1 passed test, shouldn't I?
Specifying sources above the directory that grunt-jasmine-runner is run from will fail to include them:
jasmine:{
src: '../someScript.js',
specs: '*Spec.js'
}
My first guess is that as the _SpecRunner.html is loaded via a webserver, those paths cannot be resolved.
In general those paths are rather bad, as they most probably point outside of the project's folder, but a short hint could help the developer to find what's going wrong.
Hi,
I am using this plugin as part of the h5bp/node-build-script and am having an issue running the jasmine tests from a folder call intermediate.
When the src is copied to the folder intermediate ( this is my staging area for build tasks ) the plugin is no longer able to locate the describe variable.
Testing jasmine specs via phantom
ReferenceError: Can't find variable: describe at...
Is this because paths to helper files are hard coded? im not sure, also, can the base path be configurable?
Thanks
Ian
I've realized that grunt-jasmine-runner uses the plain output of the jasmine console runner.
I've written a TerminalReporter to add color and better structuring on the console and created a pull request with jasmine-reporters: cburgmer/jasmine-reporters@9c2175c - However the code would be a much better fit here.
There's quite probably a bit more work to put into to adapt it to the way grunt works, but it's still pretty close to the console runner, so the system is the same.
If I find some time I will look into adapting that code, but in the meantime there might be somebody to take over.
Hi
I have been trying grunt for a couple of weeks and I am very excited about that project.
However it looks like I am having issues using jasmine with phantomjs.
Here is the error message I have each time the unit test task is triggered:
PhantomJS timed out, possibly due to an unfinished async spec. Use --force to continue.
It looks like it happens each time my network is behind a proxy.
Is there any way I can solve that?
Thanks.
I've found #14, it seems to be the same error.
When running my spec on the command line via Grunt it returns with:
Testing jasmine specs via phantom
0 specs, 0 failures in 0.004s.
Done, without errors.
I ran the _SpecRunner.html
in my browser, it didn't find the files due to the leading slash.
I've patched the resulting _SpecRunner.html
to reference files relative (remove leading slash) manually and ran the test again. It worked fine: I had to click away some alerts, finally that page rendered:
Passing 1 spec
Test
Test
So, I don't think my config or directory layout is bad.
I've tried patching the jasmine.js as suggested in #14, but it didn't help Grunt and PhantomJs making Jasmine work.
grunt.js Jasmine config:
...
jasmine: {
src: "chrome/content/**/*.js",
specs: "specs/**/*_spec.js",
amd: true,
helpers: [
"node_modules/requirejs/require.js",
"specs/mocks/*.js",
"specs/requirejs-config.js"
],
timeout: 1000,
phantomjs: {
"ignore-ssl-errors": true
}
}
...
Directory-Layout (some files skipped):
|-- chrome
| |-- content
| | |-- [...].js
|-- grunt.js
|-- _SpecRunner.html
`-- specs
|-- firecompass_spec.js
|-- mocks
| |-- [...].js
`-- requirejs-config.js
Running grunt -v jasmine
does not print more errors.
Environment:
Hi
Sorry but I still have that issue happening.
From the documentation, I'd assume that I could just use the phantomjs settings:
phantomjs:{
'proxy':'IP:80',
'proxy-type':'http'
}
Following that documentation:
https://github.com/ariya/phantomjs/wiki/API-Reference
But it does not seem to work.
Vytch
At the moment the task fails only if Jasmine tests failed, but reports success if all tests passed but some JS errors were present. It would be great to have an option to fail the build on any script errors as well.
This should help with catching errors not yet covered by jasmine tests.
Example:
Running "jasmine" task
Testing jasmine specs via phantom
Error: Script error
http://requirejs.org/docs/errors.html#scripterror
Error: Script error
http://requirejs.org/docs/errors.html#scripterror
31 specs, 0 failures in 0.305s.
Done, without errors.
ERRORLEVEL=0
Hello,
Sorry for bothering and stupid question, but could anyone show me example browser application that can be tested in headless mode with grunt-jasmine-runner? And gruntjs config as well?
Thanks!
Bartek
I get this error when i run grunt jasmine --stack
:
$ grunt jasmine --stack
Loading "jasmine.js" tasks...ERROR
>> TypeError: Cannot read property '_' of undefined
Loading "Gruntfile.js" tasks...ERROR
>> TypeError: Cannot read property '_' of undefined
Warning: Cannot read property 'namespace' of undefined Use --force to continue.
TypeError: Cannot read property 'namespace' of undefined
at Function.config.getRaw (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\grunt\config.js:33:22)
at Function.config.get (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\grunt\config.js:46:32)
at Object.module.exports [as config] (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\grunt\config.js:12:19)
at Object.<anonymous> (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt-jasmine-runner\tasks\jasmine.js:46:21)
at Object.<anonymous> (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\util\task.js:294:30)
at Task.runTaskFn (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\util\task.js:244:24)
at Task.<anonymous> (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\util\task.js:293:12)
at Task.start (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\util\task.js:302:5)
at Object.grunt.tasks (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\grunt.js:155:8)
at Object.module.exports [as cli] (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\grunt\cli.js:27:9)
at Object.<anonymous> (C:\Users\myUsername\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt:44:20)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3
Aborted due to warnings.
Fatal error: Cannot read property 'exit' of undefined
TypeError: Cannot read property 'exit' of undefined
at Object.fail.warn (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\grunt\fail.js:64:15)
at Object.task.options.error (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\grunt.js:128:12)
at Task.<anonymous> (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\util\task.js:214:29)
at Task.runTaskFn (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\util\task.js:250:7)
at Task.<anonymous> (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\util\task.js:293:12)
at Task.start (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\util\task.js:302:5)
at Object.grunt.tasks (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\grunt.js:155:8)
at Object.module.exports [as cli] (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\grunt\cli.js:27:9)
at Object.<anonymous> (C:\Users\myUsername\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt:44:20)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3
C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\grunt\fail.js:48
grunt.util.exit(typeof errcode === 'number' ? errcode : fail.code.FATAL_ERROR);
^
TypeError: Cannot read property 'exit' of undefined
at Object.fail.fatal (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\grunt\fail.js:48:13)
at process.uncaughtHandler (C:\Users\myUsername\IdeaProjects\myProjectName\src\main\webapp\node_modules\grunt\lib\grunt.js:121:10)
at emitOne (events.js:77:13)
at process.emit (events.js:169:7)
at process._fatalException (node.js:224:26)
My Grunt Version is:
$ grunt --version
grunt-cli v1.2.0
grunt v1.0.1
Can someone help me?
Running "jasmine" task
Testing jasmine specs via phantom
Running PhantomJS...ERROR
Can't open 'null'
I'm curious if anyone has had this issue when using the runner through loadNpmTasks. Cloning the project and running the gruntfile contained within grunt-jasmine-runner works fine, however when loading this module as an npm task, this error occurs.
Specifics for error:
Error starts on line 131 of tasks/lib/phantomjs.js:
grunt.task.getFile('lib/phantomjs/bootstrap.js'),
Grunt internally uses grunt.task.searchDirs
for the above command, however this array is empty. This only occurs when loading via npm at the moment. It seems searchDirs
is populated during the loadTasks
method.
For example I shouldn't have to read through the code to find out that the template
cannot just be a path to my template file. Instead it also can be an Object
of the form: { src: ' ... ', opts: { [ template context ] } }
.
Sorry. Me mistook browser tab :(
Sorry if this is a stupid question but I didn't see it mentioned in the readme. I just wanted to know if it's possible to pass a script to phantom, for instance if I wanted to use the evaluate
method:
var page = require('webpage').create();
page.open(url, function (status) {
var title = page.evaluate(function () {
return document.title;
});
console.log('Page title is ' + title);
});
If it is possible does it place nice with AMD testing?
Grunt tasks by default don't make much noise. I'd like the jasmine runner to be equally quiet on the console. Extended output can easily requested by using the -v switch.
Hello,
I have a grunt watch
task that looks at changes to js/spec files and restarts the jasmine
task. However I also have the grunt jasmine-server
running alongside. I am doing that to debug some of my tests in the browser.
When the js/spec files change, grunt watch
simply crashes since the jasmine
task seems to start listening on the same port as the jasmine-server
, causing an exception.
Is there any way I can keep the jasmine-server
running and have grunt watch auto-generate the specrunner.html without crashing ?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.