Commit c64cd455 c64cd455fee549b99e53f5da6d7bc231af6c8177 by Nicolas Perriault

migrated so tests to use setUp/tearDown - refs #397

1 parent 047a8091
1 Subproject commit 2f5e1fcd2b9812b286a7eac98df327691b7558b7 1 Subproject commit 442060c4b89053177962720d76e89468afd2918e
......
...@@ -14,12 +14,19 @@ function fetchUA(request) { ...@@ -14,12 +14,19 @@ function fetchUA(request) {
14 testUA(headers.pop().value, /plop/); 14 testUA(headers.pop().value, /plop/);
15 } 15 }
16 16
17 casper.test.begin('userAgent() tests', 3, function(test) { 17 casper.test.begin('userAgent() tests', 3, {
18 testUA(casper.options.pageSettings.userAgent, /CasperJS/); 18 originalUA: casper.options.pageSettings.userAgent,
19 casper.start(); 19
20 casper.userAgent('plop').once('resource.requested', fetchUA); 20 tearDown: function(test) {
21 casper.thenOpen('tests/site/index.html'); 21 casper.userAgent(this.originalUA);
22 casper.run(function() { 22 },
23 test.done(); 23
24 }); 24 test: function(test) {
25 testUA(casper.options.pageSettings.userAgent, /CasperJS/);
26 casper.start().userAgent('plop').once('resource.requested', fetchUA);
27 casper.thenOpen('tests/site/index.html').run(function() {
28 test.done();
29 });
30 }
25 }); 31 });
32
......
1 /*global casper*/ 1 /*global casper*/
2 /*jshint strict:false*/ 2 /*jshint strict:false*/
3 casper.test.begin('alert events', 1, function(test) { 3 casper.test.begin('alert events', 1, {
4 var ok = false; 4 ok: false,
5 casper.once('remote.alert', function(message) { 5
6 ok = message === 'plop'; 6 tearDown: function(test) {
7 }); 7 casper.removeAllListeners('remote.alert');
8 casper.start('tests/site/alert.html', function() { 8 },
9 test.assert(ok, 'alert event has been intercepted'); 9
10 }); 10 test: function(test) {
11 casper.run(function() { 11 var self = this;
12 this.removeAllListeners('remote.alert'); 12
13 test.done(); 13 casper.once('remote.alert', function(message) {
14 }); 14 self.ok = (message === 'plop');
15 });
16
17 casper.start('tests/site/alert.html', function() {
18 test.assert(self.ok, 'alert event has been intercepted');
19 });
20
21 casper.run(function() {
22 test.done();
23 });
24 }
15 }); 25 });
......
1 /*global casper*/ 1 /*global casper*/
2 /*jshint strict:false*/ 2 /*jshint strict:false*/
3 var fs = require('fs'), 3 var fs = require('fs');
4 testFile = '/tmp/__casper_test_capture.png';
5 4
6 if (fs.exists(testFile) && fs.isFile(testFile)) { 5 casper.test.begin('Casper.capture() tests', 1, {
7 fs.remove(testFile); 6 testFile: '/tmp/__casper_test_capture.png',
8 }
9 7
10 casper.test.begin('Casper.capture() tests', 1, function(test) { 8 setUp: function(test) {
11 casper.start('tests/site/index.html', function() { 9 if (fs.exists(this.testFile) && fs.isFile(this.testFile)) {
12 this.viewport(300, 200); 10 try {
13 this.capture(testFile); 11 fs.remove(this.testFile);
14 test.assert(fs.isFile(testFile), 'Casper.capture() captured a screenshot'); 12 } catch (e) {
15 }).run(function() { 13 }
14 }
15 },
16
17 tearDown: function(test) {
16 try { 18 try {
17 fs.remove(testFile); 19 fs.remove(this.testFile);
18 } catch(e) { 20 } catch(e) {
19 this.warn('Unable to delete test file ' + testFile + '; please delete it manually');
20 } 21 }
21 test.done(); 22 },
22 }); 23
24 test: function(test) {
25 var self = this;
26
27 casper.start('tests/site/index.html', function() {
28 this.viewport(300, 200);
29 this.capture(self.testFile);
30 test.assert(fs.isFile(self.testFile), 'Casper.capture() captured a screenshot');
31 });
32
33 casper.run(function() {
34 test.done();
35 });
36 }
23 }); 37 });
24 38
25 casper.test.begin('Casper.captureBase64() tests', 3, function(test) { 39 casper.test.begin('Casper.captureBase64() tests', 3, function(test) {
26 casper.start('tests/site/index.html', function() { 40 casper.start('tests/site/index.html', function() {
27 test.assert(this.captureBase64('png').length > 0, 41 test.assert(this.captureBase64('png').length > 0,
28 'Casper.captureBase64() rendered a page capture as base64'); 42 'Casper.captureBase64() rendered a page capture as base64');
29 test.assert(this.captureBase64('png', 'ul').length > 0, 43 test.assert(this.captureBase64('png', 'ul').length > 0,
30 'Casper.captureBase64() rendered a capture from a selector as base64'); 44 'Casper.captureBase64() rendered a capture from a selector as base64');
31 test.assert(this.captureBase64('png', {top: 0, left: 0, width: 30, height: 30}).length > 0, 45 test.assert(this.captureBase64('png', {top: 0, left: 0, width: 30, height: 30}).length > 0,
32 'Casper.captureBase64() rendered a capture from a clipRect as base64'); 46 'Casper.captureBase64() rendered a capture from a clipRect as base64');
33 }).run(function() { 47 }).run(function() {
34 test.done(); 48 test.done();
35 }); 49 });
......