|
| 1 | +/* |
| 2 | +* grunt-phantomcss |
| 3 | +* https://github.com/anselmh/grunt-phantomcss |
| 4 | +* |
| 5 | +* Copyright (c) 2013 Chris Gladd |
| 6 | +* Copyright (c) since 2014 Anselm Hannemann |
| 7 | +* |
| 8 | +* Licensed under the MIT license. |
| 9 | +*/ |
| 10 | + |
| 11 | +'use-strict'; |
| 12 | + |
| 13 | +// Get node fileSystem module and define the separator module |
1 | 14 | var fs = require('fs'); |
2 | 15 | var s = fs.separator; |
3 | 16 |
|
4 | 17 | // Parse arguments passed in from the grunt task |
5 | 18 | var args = JSON.parse(phantom.args[0]); |
6 | 19 |
|
| 20 | +// Get viewport arguments (width | height) |
7 | 21 | var viewportSize = { |
8 | | - width: args.viewportSize[0], |
9 | | - height: args.viewportSize[1] |
| 22 | + width: args.viewportSize[0], |
| 23 | + height: args.viewportSize[1] |
10 | 24 | }; |
11 | 25 |
|
12 | 26 | // Messages are sent to the parent by appending them to the tempfile |
13 | 27 | var sendMessage = function() { |
14 | | - fs.write(args.tempFile, JSON.stringify(Array.prototype.slice.call(arguments)) + '\n', 'a'); |
| 28 | + fs.write(args.tempFile, JSON.stringify(Array.prototype.slice.call(arguments)) + '\n', 'a'); |
15 | 29 | }; |
16 | 30 |
|
17 | 31 | // Initialise CasperJs |
18 | 32 | var phantomCSSPath = args.phantomCSSPath; |
| 33 | + |
19 | 34 | phantom.casperPath = phantomCSSPath+s+'CasperJs'; |
20 | 35 | phantom.injectJs(phantom.casperPath+s+'bin'+s+'bootstrap.js'); |
21 | 36 |
|
22 | 37 | var casper = require('casper').create({ |
23 | | - viewportSize: viewportSize, |
24 | | - logLevel: args.logLevel, |
25 | | - verbose: true |
| 38 | + viewportSize: viewportSize, |
| 39 | + logLevel: args.logLevel, |
| 40 | + verbose: true |
26 | 41 | }); |
27 | 42 |
|
28 | 43 | // Require and initialise PhantomCSS module |
29 | 44 | var phantomcss = require(phantomCSSPath+s+'phantomcss.js'); |
30 | 45 |
|
31 | 46 | phantomcss.init({ |
32 | | - screenshotRoot: args.screenshots, |
33 | | - failedComparisonsRoot: args.failures, |
34 | | - libraryRoot: phantomCSSPath, // Give absolute path, otherwise PhantomCSS fails |
35 | | - mismatchTolerance: args.mismatchTolerance, |
| 47 | + screenshotRoot: args.screenshots, |
| 48 | + failedComparisonsRoot: args.failures, |
| 49 | + libraryRoot: phantomCSSPath, // Give absolute path, otherwise PhantomCSS fails |
| 50 | + mismatchTolerance: args.mismatchTolerance, // defaults to 0.05 |
36 | 51 |
|
37 | | - onFail: function(test) { |
38 | | - sendMessage('onFail', test); |
39 | | - }, |
40 | | - onPass: function(test) { |
41 | | - sendMessage('onPass', test); |
42 | | - }, |
43 | | - onTimeout: function(test) { |
44 | | - sendMessage('onTimeout', test); |
45 | | - }, |
46 | | - onComplete: function(allTests, noOfFails, noOfErrors) { |
47 | | - sendMessage('onComplete', allTests, noOfFails, noOfErrors); |
48 | | - } |
| 52 | + onFail: function(test) { |
| 53 | + sendMessage('onFail', test); |
| 54 | + }, |
| 55 | + onPass: function(test) { |
| 56 | + sendMessage('onPass', test); |
| 57 | + }, |
| 58 | + onTimeout: function(test) { |
| 59 | + sendMessage('onTimeout', test); |
| 60 | + }, |
| 61 | + onComplete: function(allTests, noOfFails, noOfErrors) { |
| 62 | + sendMessage('onComplete', allTests, noOfFails, noOfErrors); |
| 63 | + } |
49 | 64 | }); |
50 | 65 |
|
51 | 66 | // Run the test scenarios |
52 | 67 | args.test.forEach(function(testSuite) { |
53 | | - require(testSuite); |
| 68 | + require(testSuite); |
54 | 69 | }); |
55 | 70 |
|
56 | 71 | // End tests and compare screenshots |
57 | 72 | casper.then(function() { |
58 | | - phantomcss.compareAll(); |
| 73 | + phantomcss.compareAll(); |
59 | 74 | }) |
60 | 75 | .then(function() { |
61 | | - casper.test.done(); |
| 76 | + casper.test.done(); |
62 | 77 | }) |
63 | 78 | .run(function() { |
64 | | - phantom.exit(); |
| 79 | + phantom.exit(); |
65 | 80 | }); |
0 commit comments