|
1 |
| -var fs = require('fs'); |
2 |
| -var system = require('system'); |
3 |
| - |
4 |
| -// Parse arguments passed in from the grunt task |
5 |
| -var args = JSON.parse(system.args[1]); |
6 |
| - |
7 |
| -var viewportSize = { |
8 |
| - "width": args.viewportSize[0], |
9 |
| - "height": args.viewportSize[1] |
10 |
| -}; |
11 |
| - |
12 |
| -// Messages are sent to the parent by appending them to the tempfile |
13 |
| -var sendMessage = function() { |
14 |
| - fs.write(args.tempFile, JSON.stringify(Array.prototype.slice.call(arguments)) + '\n', 'a'); |
15 |
| -}; |
16 |
| - |
17 |
| -// Initialise CasperJs |
18 |
| -phantom.casperPath = args.casperPath; |
19 |
| -phantom.injectJs([args.casperPath, 'bin', 'bootstrap.js'].join(fs.separator)); |
20 |
| - |
21 |
| -var casper = require('casper').create({ |
22 |
| - "viewportSize": viewportSize, |
23 |
| - "logLevel": args.logLevel, |
24 |
| - "verbose": true |
25 |
| -}); |
26 |
| - |
27 |
| -// Require and initialise PhantomCSS module |
28 |
| -var phantomcss = require('phantomcss'); |
29 |
| - |
30 |
| -phantomcss.init({ |
31 |
| - "libraryRoot": args.phantomCSSPath, // Give absolute path, otherwise PhantomCSS fails |
32 |
| - |
33 |
| - "screenshotRoot": args.screenshots, |
34 |
| - "failedComparisonsRoot": args.failures, |
35 |
| - |
36 |
| - /** |
37 |
| - * Mismatch tolerance defaults to 0.05%. Increasing this value |
38 |
| - * will decrease test coverage |
39 |
| - */ |
40 |
| - "mismatchTolerance": 0.05, |
41 |
| - |
42 |
| - "onFail": function(test) { |
43 |
| - sendMessage('onFail', test); |
44 |
| - }, |
45 |
| - "onPass": function(test) { |
46 |
| - sendMessage('onPass', test); |
47 |
| - }, |
48 |
| - "onTimeout": function(test) { |
49 |
| - sendMessage('onTimeout', test); |
50 |
| - }, |
51 |
| - "onComplete": function(allTests, noOfFails, noOfErrors) { |
52 |
| - sendMessage('onComplete', allTests, noOfFails, noOfErrors); |
53 |
| - } |
54 |
| -}); |
55 |
| - |
56 |
| -// Run the test scenarios |
57 |
| -args.test.forEach(function(testSuite) { |
58 |
| - require(testSuite); |
59 |
| -}); |
60 |
| - |
61 |
| -// End tests and compare screenshots |
62 |
| -casper.then(function() { |
63 |
| - phantomcss.compareAll(); |
64 |
| -}).run(function() { |
65 |
| - phantom.exit(0); |
66 |
| -}); |
| 1 | +var fs = require('fs'); |
| 2 | +var system = require('system'); |
| 3 | + |
| 4 | +// Parse arguments passed in from the grunt task |
| 5 | +var args = JSON.parse(system.args[1]); |
| 6 | + |
| 7 | +var viewportSize = { |
| 8 | + "width": args.viewportSize[0], |
| 9 | + "height": args.viewportSize[1] |
| 10 | +}; |
| 11 | + |
| 12 | +// Messages are sent to the parent by appending them to the tempfile |
| 13 | +var sendMessage = function() { |
| 14 | + fs.write(args.tempFile, JSON.stringify(Array.prototype.slice.call(arguments)) + '\n', 'a'); |
| 15 | +}; |
| 16 | + |
| 17 | +// Initialise CasperJs |
| 18 | +phantom.casperPath = args.casperPath; |
| 19 | +phantom.injectJs([args.casperPath, 'bin', 'bootstrap.js'].join(fs.separator)); |
| 20 | + |
| 21 | +var casper = require('casper').create({ |
| 22 | + "viewportSize": viewportSize, |
| 23 | + "logLevel": args.logLevel, |
| 24 | + "logLevel": args.logLevel, |
| 25 | + "verbose": true |
| 26 | +}); |
| 27 | + |
| 28 | +// Require and initialise PhantomCSS module |
| 29 | +var phantomcss = require('phantomcss'); |
| 30 | + |
| 31 | +phantomcss.init({ |
| 32 | + "libraryRoot": args.phantomCSSPath, // Give absolute path, otherwise PhantomCSS fails |
| 33 | + "screenshotRoot": args.screenshots, |
| 34 | + "failedComparisonsRoot": args.failures, |
| 35 | + |
| 36 | + /** |
| 37 | + * Mismatch tolerance defaults to 0.05%. Increasing this value |
| 38 | + * will decrease test coverage |
| 39 | + */ |
| 40 | + "mismatchTolerance": args.mismatchTolerance, |
| 41 | + |
| 42 | + "onFail": function(test) { |
| 43 | + sendMessage('onFail', test); |
| 44 | + }, |
| 45 | + "onPass": function(test) { |
| 46 | + sendMessage('onPass', test); |
| 47 | + }, |
| 48 | + "onTimeout": function(test) { |
| 49 | + sendMessage('onTimeout', test); |
| 50 | + }, |
| 51 | + "onComplete": function(allTests, noOfFails, noOfErrors) { |
| 52 | + sendMessage('onComplete', allTests, noOfFails, noOfErrors); |
| 53 | + } |
| 54 | +}); |
| 55 | + |
| 56 | +// Run the test scenarios |
| 57 | +args.test.forEach(function(testSuite) { |
| 58 | + require(testSuite); |
| 59 | +}); |
| 60 | + |
| 61 | +// End tests and compare screenshots |
| 62 | +casper.then(function() { |
| 63 | + phantomcss.compareAll(); |
| 64 | +}).run(function() { |
| 65 | + phantom.exit(0); |
| 66 | +}); |
0 commit comments