From af73f349f88202bcf8e11d39d3fe3703fb3d5bad Mon Sep 17 00:00:00 2001 From: Heiko Behrens Date: Fri, 22 Mar 2013 18:07:20 +0100 Subject: [PATCH 1/2] test to verify hanging on failed load of iframe --- Gruntfile.js | 28 ++++++++++++++++++++++++++-- package.json | 2 +- test/selfTest/TaskSpec.js | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 test/selfTest/TaskSpec.js diff --git a/Gruntfile.js b/Gruntfile.js index d31d810..396cf7a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -9,7 +9,22 @@ 'use strict'; module.exports = function(grunt) { + grunt.initConfig({ + + connect: { + return500: { + options: { + port: 9000, + middleware: function(connect, options) { + return [function(req, res, next){ + res.statusCode = 500; + res.end(); + }]; + } + } + } + }, jshint: { all: [ 'Gruntfile.js', @@ -45,8 +60,16 @@ module.exports = function(grunt) { consolidate: true } } + }, + selfTest: { + options: { + specs:["test/selfTest/*.js"], + "--web-security": "no" + } } }, + + nodeunit: { tasks: ['test/*_test.js'] } @@ -57,7 +80,8 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-nodeunit'); grunt.loadNpmTasks('grunt-contrib-internal'); + grunt.loadNpmTasks('grunt-contrib-connect'); - grunt.registerTask('test', ['jshint', 'jasmine', 'nodeunit']); - grunt.registerTask('default', ['test', 'build-contrib']); + grunt.registerTask('test', ['connect:return500', 'jasmine', 'nodeunit']); + grunt.registerTask('default', ['jshint', 'test', 'build-contrib']); }; diff --git a/package.json b/package.json index 84c459b..5d1fe9c 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "test": "grunt test" }, "dependencies": { - "grunt-lib-phantomjs": "~0.2.0", + "grunt-lib-phantomjs": "git://github.com/HBehrens/grunt-lib-phantomjs.git#20f675c331893ee4b1a328ae7a1ce82d75099e50", "rimraf": "~2.0.3" }, "devDependencies": { diff --git a/test/selfTest/TaskSpec.js b/test/selfTest/TaskSpec.js new file mode 100644 index 0000000..d33e3fb --- /dev/null +++ b/test/selfTest/TaskSpec.js @@ -0,0 +1,32 @@ +describe("Task", function() { + + /* + when running this test with `grunt jasmine:selfTest -d` you got this output + + [D] ["phantomjs","onLoadFinished","success"] + [D] ["phantomjs","onResourceRequested","http://httpbin.org/status/500"] + [D] ["phantomjs","onResourceReceived","http://httpbin.org/status/500"] + [D] ["phantomjs","onLoadFinished","fail"] + [D] ["phantomjs","fail.load","_SpecRunner.html"] + + phantomjs.page.onLoadFinished seems to be called for iframes, too. + A failing onLoadFinished caused this grunt taks to hang. + Now, after removing the event handler, this following test should work as expected + */ + it("can handle fail on iframe", function(){ + var waitedLongEnough; + runs(function(){ + iframe = document.createElement("iframe"); + iframe.src = "http://localhost:9000"; + document.body.appendChild(iframe); + + setTimeout(function(){waitedLongEnough=true;}, 50); + }); + waitsFor(function(){ + return waitedLongEnough; + }); + runs(function(){ + expect(true).toBeTruthy("without change in grunt-lib-phantomjs, jasmine would never reach this line"); + }); + }); +}); \ No newline at end of file From d2cc443e6be6e79a83f4246fabc5a5e99fdeb98b Mon Sep 17 00:00:00 2001 From: Heiko Behrens Date: Wed, 5 Jun 2013 14:36:57 +0200 Subject: [PATCH 2/2] use fixed version of grunt-lib-phantomjs to update https://github.com/gruntjs/grunt-contrib-jasmine/pull/44 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7881597..81b96c6 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "test": "grunt test" }, "dependencies": { - "grunt-lib-phantomjs": "~0.3.0", + "grunt-lib-phantomjs": "git://github.com/HBehrens/grunt-lib-phantomjs.git#791ae961b2d4c8d59a55dd9be50d15ee8b949081", "rimraf": "~2.0.3" }, "devDependencies": {