casperjs 1.0.0.RC1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/CHANGELOG.md +289 -1
  2. data/CONTRIBUTING.md +93 -0
  3. data/CONTRIBUTORS.md +53 -0
  4. data/README.md +29 -1
  5. data/batchbin/casperjs.bat +5 -0
  6. data/bin/bootstrap.js +164 -114
  7. data/bin/casperjs +84 -0
  8. data/bin/usage.txt +2 -1
  9. data/casperjs.gemspec +7 -4
  10. data/modules/casper.js +661 -239
  11. data/modules/clientutils.js +240 -54
  12. data/modules/colorizer.js +2 -1
  13. data/modules/events.js +13 -1
  14. data/modules/http.js +70 -0
  15. data/modules/mouse.js +1 -2
  16. data/modules/pagestack.js +166 -0
  17. data/modules/tester.js +1013 -659
  18. data/modules/utils.js +519 -367
  19. data/modules/vendors/coffee-script.js +2 -2
  20. data/modules/xunit.js +56 -24
  21. data/package.json +2 -2
  22. data/rpm/casperjs.spec +203 -0
  23. data/rpm/mkrpm.sh +25 -0
  24. data/rubybin/casperjs +9 -4
  25. data/samples/bbcshots.coffee +11 -10
  26. data/samples/bbcshots.js +16 -15
  27. data/samples/cliplay.js +3 -0
  28. data/samples/customevents.js +3 -0
  29. data/samples/customlogging.coffee +17 -19
  30. data/samples/customlogging.js +26 -27
  31. data/samples/download.js +4 -1
  32. data/samples/dynamic.js +3 -0
  33. data/samples/each.js +3 -0
  34. data/samples/events.js +4 -2
  35. data/samples/extends.js +4 -1
  36. data/samples/googlelinks.coffee +4 -1
  37. data/samples/googlelinks.js +10 -3
  38. data/samples/googlematch.coffee +1 -1
  39. data/samples/googlematch.js +5 -2
  40. data/samples/googlepagination.js +4 -1
  41. data/samples/googletesting.js +3 -0
  42. data/samples/logcolor.js +3 -0
  43. data/samples/metaextract.js +3 -0
  44. data/samples/multirun.js +3 -0
  45. data/samples/screenshot.js +4 -1
  46. data/samples/statushandlers.js +4 -1
  47. data/samples/steptimeout.js +3 -0
  48. data/samples/timeout.js +4 -1
  49. data/samples/translate.coffee +23 -0
  50. data/samples/translate.js +30 -0
  51. data/tests/commands/mytest.js +14 -0
  52. data/tests/commands/script.js +3 -0
  53. data/tests/run.js +82 -37
  54. data/tests/sample_modules/config.json +1 -0
  55. data/tests/sample_modules/csmodule.coffee +1 -0
  56. data/tests/sample_modules/jsmodule.js +1 -0
  57. data/tests/selftest.js +57 -0
  58. data/tests/site/dummy.js +1 -0
  59. data/tests/site/field-array.html +14 -0
  60. data/tests/site/frame1.html +10 -0
  61. data/tests/site/frame2.html +11 -0
  62. data/tests/site/frame3.html +11 -0
  63. data/tests/site/frames.html +12 -0
  64. data/tests/site/global.html +6 -1
  65. data/tests/site/includes/include1.js +6 -0
  66. data/tests/site/includes/include2.js +6 -0
  67. data/tests/site/index.html +3 -0
  68. data/tests/site/popup.html +19 -0
  69. data/tests/site/resources.html +7 -8
  70. data/tests/site/urls.html +14 -0
  71. data/tests/suites/casper/agent.js +3 -1
  72. data/tests/suites/casper/alert.js +14 -0
  73. data/tests/suites/casper/auth.js +24 -0
  74. data/tests/suites/casper/capture.js +12 -12
  75. data/tests/suites/casper/click.js +11 -1
  76. data/tests/suites/casper/confirm.js +24 -16
  77. data/tests/suites/casper/debug.js +10 -0
  78. data/tests/suites/casper/elementattribute.js +3 -1
  79. data/tests/suites/casper/encode.js +6 -2
  80. data/tests/suites/casper/evaluate.js +78 -18
  81. data/tests/suites/casper/events.js +3 -1
  82. data/tests/suites/casper/exists.js +3 -1
  83. data/tests/suites/casper/fetchtext.js +3 -1
  84. data/tests/suites/casper/flow.coffee +1 -1
  85. data/tests/suites/casper/formfill.js +39 -4
  86. data/tests/suites/casper/frames.js +43 -0
  87. data/tests/suites/casper/global.js +9 -3
  88. data/tests/suites/casper/headers.js +41 -0
  89. data/tests/suites/casper/history.js +3 -1
  90. data/tests/suites/casper/hooks.js +3 -1
  91. data/tests/suites/casper/keys.js +15 -0
  92. data/tests/suites/casper/location.js +21 -0
  93. data/tests/suites/casper/logging.js +3 -1
  94. data/tests/suites/casper/mouseevents.js +3 -1
  95. data/tests/suites/casper/onerror.js +3 -1
  96. data/tests/suites/casper/open.js +63 -1
  97. data/tests/suites/casper/popup.js +86 -0
  98. data/tests/suites/casper/prompt.js +11 -15
  99. data/tests/suites/casper/request.js +36 -0
  100. data/tests/suites/casper/resources.coffee +5 -5
  101. data/tests/suites/casper/scripts.js +32 -0
  102. data/tests/suites/casper/start.js +3 -1
  103. data/tests/suites/casper/steps.js +4 -2
  104. data/tests/suites/casper/urls.js +21 -0
  105. data/tests/suites/casper/viewport.js +3 -1
  106. data/tests/suites/casper/visible.js +3 -1
  107. data/tests/suites/casper/wait.js +22 -12
  108. data/tests/suites/casper/xpath.js +3 -1
  109. data/tests/suites/cli.js +3 -1
  110. data/tests/suites/clientutils.js +57 -3
  111. data/tests/suites/coffee.coffee +1 -1
  112. data/tests/suites/fs.js +3 -1
  113. data/tests/suites/http_status.js +19 -3
  114. data/tests/suites/popup.js +33 -0
  115. data/tests/suites/require.js +31 -0
  116. data/tests/suites/tester.js +134 -29
  117. data/tests/suites/utils.js +108 -8
  118. data/tests/suites/xunit.js +37 -6
  119. metadata +49 -15
  120. data/modules/injector.js +0 -93
  121. data/tests/suites/injector.js +0 -64
@@ -0,0 +1,31 @@
1
+ /*global casper*/
2
+ /*jshint strict:false*/
3
+ var fs = require('fs');
4
+ var modroot = fs.pathJoin(phantom.casperPath, 'tests', 'sample_modules');
5
+ var jsmod, csmod, config;
6
+
7
+ casper.test.comment('Javascript module loading')
8
+ try {
9
+ jsmod = require(fs.pathJoin(modroot, 'jsmodule'));
10
+ casper.test.assertTrue(jsmod.ok, 'require() patched version can load a js module');
11
+ } catch (e) {
12
+ casper.test.fail('require() patched version can load a js module');
13
+ }
14
+
15
+ casper.test.comment('CoffeeScript module loading')
16
+ try {
17
+ csmod = require(fs.pathJoin(modroot, 'csmodule'));
18
+ casper.test.assertTrue(csmod.ok, 'require() patched version can load a coffeescript module');
19
+ } catch (e) {
20
+ casper.test.fail('require() patched version can load a coffeescript module');
21
+ }
22
+
23
+ casper.test.comment('JSON module loading')
24
+ try {
25
+ config = require(fs.pathJoin(modroot, 'config.json'));
26
+ casper.test.assertTrue(config.ok, 'require() patched version can load a json module');
27
+ } catch (e) {
28
+ casper.test.fail('require() patched version can load a json module');
29
+ }
30
+
31
+ casper.test.done(3);
@@ -1,33 +1,10 @@
1
+ /*global casper*/
2
+ /*jshint strict:false maxstatements:99*/
1
3
  var fs = require('fs');
2
-
3
4
  var t = casper.test;
4
5
 
5
6
  casper.start();
6
7
 
7
- t.comment('Tester.testEquals()');
8
- t.assert(t.testEquals(null, null), 'Tester.testEquals() null equality');
9
- t.assertNot(t.testEquals(null, undefined), 'Tester.testEquals() null vs. undefined inequality');
10
- t.assert(t.testEquals("hi", "hi"), 'Tester.testEquals() string equality');
11
- t.assertNot(t.testEquals("hi", "ih"), 'Tester.testEquals() string inequality');
12
- t.assert(t.testEquals(5, 5), 'Tester.testEquals() number equality');
13
- t.assertNot(t.testEquals("5", 5), 'Tester.testEquals() number equality without implicit cast');
14
- t.assert(t.testEquals(5, 5.0), 'Tester.testEquals() number equality with cast');
15
- t.assertNot(t.testEquals(5, 10), 'Tester.testEquals() number inequality');
16
- t.assert(t.testEquals([], []), 'Tester.testEquals() empty array equality');
17
- t.assert(t.testEquals([1,2], [1,2]), 'Tester.testEquals() array equality');
18
- t.assert(t.testEquals([1,2,[1,2,function(){}]], [1,2,[1,2,function(){}]]), 'Tester.testEquals() complex array equality');
19
- t.assertNot(t.testEquals([1,2,[1,2,function(a){}]], [1,2,[1,2,function(b){}]]), 'Tester.testEquals() complex array inequality');
20
- t.assertNot(t.testEquals([1,2], [2,1]), 'Tester.testEquals() shuffled array inequality');
21
- t.assertNot(t.testEquals([1,2], [1,2,3]), 'Tester.testEquals() array length inequality');
22
- t.assert(t.testEquals({}, {}), 'Tester.testEquals() empty object equality');
23
- t.assert(t.testEquals({a:1,b:2}, {a:1,b:2}), 'Tester.testEquals() object length equality');
24
- t.assert(t.testEquals({a:1,b:2}, {b:2,a:1}), 'Tester.testEquals() shuffled object keys equality');
25
- t.assertNot(t.testEquals({a:1,b:2}, {a:1,b:3}), 'Tester.testEquals() object inequality');
26
- t.assert(t.testEquals({1:{name:"bob",age:28}, 2:{name:"john",age:26}}, {1:{name:"bob",age:28}, 2:{name:"john",age:26}}), 'Tester.testEquals() complex object equality');
27
- t.assertNot(t.testEquals({1:{name:"bob",age:28}, 2:{name:"john",age:26}}, {1:{name:"bob",age:28}, 2:{name:"john",age:27}}), 'Tester.testEquals() complex object inequality');
28
- t.assert(t.testEquals(function(x){return x;}, function(x){return x;}), 'Tester.testEquals() function equality');
29
- t.assertNot(t.testEquals(function(x){return x;}, function(y){return y+2;}), 'Tester.testEquals() function inequality');
30
-
31
8
  t.comment('Tester.sortFiles()');
32
9
  var testDirRoot = fs.pathJoin(phantom.casperPath, 'tests', 'testdir');
33
10
  var files = t.findTestFiles(testDirRoot);
@@ -47,18 +24,40 @@ t.assertEquals(files, expected, 'findTestFiles() find test files and sort them')
47
24
  casper.thenOpen('tests/site/index.html', function() {
48
25
  t.comment('Tester.assertTextExists()');
49
26
  t.assertTextExists('form', 'Tester.assertTextExists() checks that page body contains text');
50
- });
51
27
 
52
- casper.then(function() {
28
+ t.comment('Tester.assertTextExist()');
29
+ t.assertTextExist('form', 'Tester.assertTextExist() checks that page body contains text [alias]');
30
+
31
+ t.comment('Tester.assertTextDoesntExist()');
32
+ t.assertTextDoesntExist('blah', "Tester.assertTextDoesntExist() checks that page body doesn't contain provided text");
33
+
34
+ t.comment('Tester.assertSelectorHasText()');
35
+ t.assertSelectorHasText('h1', 'Title', 'Tester.assertSelectorHasText() works as expected');
36
+
37
+ t.comment('Tester.assertSelectorDoesntHaveText()');
38
+ t.assertSelectorDoesntHaveText('h1', 'Subtitle', 'Tester.assertSelectorDoesntHaveText() works as expected');
39
+
53
40
  t.comment('Tester.assert()');
54
41
  t.assert(true, 'Tester.assert() works as expected');
55
42
 
43
+ t.comment('Tester.assertTrue()');
44
+ t.assertTrue(true, 'Tester.assertTrue() works as expected [alias]');
45
+
46
+ t.comment('Tester.assertTruthy()');
47
+ t.assertTruthy('1', 'Tester.assertTruthy() works as expected');
48
+
49
+ t.comment('Tester.assertFalsy()');
50
+ t.assertFalsy('', 'Tester.assertFalsy() works as expected');
51
+
56
52
  t.comment('Tester.assertNot()');
57
53
  t.assertNot(false, 'Tester.assertNot() works as expected');
58
54
 
59
55
  t.comment('Tester.assertEquals()');
60
56
  t.assertEquals(true, true, 'Tester.assertEquals() works as expected');
61
57
 
58
+ t.comment('Tester.assertEqual()');
59
+ t.assertEqual(true, true, 'Tester.assertEqual() works as expected [alias]');
60
+
62
61
  t.comment('Tester.assertNotEquals()');
63
62
  t.assertNotEquals(true, false, 'Tester.assertNotEquals() works as expected');
64
63
 
@@ -67,43 +66,138 @@ casper.then(function() {
67
66
  return true;
68
67
  }, 'Tester.assertEval() works as expected');
69
68
 
69
+ t.comment('Tester.assertEvaluate()');
70
+ t.assertEvaluate(function() {
71
+ return true;
72
+ }, 'Tester.assertEvaluate() works as expected [alias]');
73
+
70
74
  t.comment('Tester.assertEvalEquals()');
71
75
  t.assertEvalEquals(function() {
72
76
  return 42;
73
77
  }, 42, 'Tester.assertEvalEquals() works as expected');
74
78
 
79
+ t.comment('Tester.assertEvalEqual()');
80
+ t.assertEvalEqual(function() {
81
+ return 42;
82
+ }, 42, 'Tester.assertEvalEqual() works as expected [alias]');
83
+
75
84
  t.comment('Tester.assertExists()');
76
85
  t.assertExists('body', 'Tester.assertExists() works as expected');
77
86
 
87
+ t.comment('Tester.assertExist()');
88
+ t.assertExist('body', 'Tester.assertExist() works as expected [alias]');
89
+
90
+ t.comment('Tester.assertSelectorExists()');
91
+ t.assertSelectorExists('body', 'Tester.assertSelectorExists() works as expected [alias]');
92
+
93
+ t.comment('Tester.assertSelectorExists()');
94
+ t.assertSelectorExist('body', 'Tester.assertSelectorExist() works as expected [alias]');
95
+
78
96
  t.comment('Tester.assertDoesntExist()');
79
97
  t.assertDoesntExist('foobar', 'Tester.assertDoesntExist() works as expected');
80
98
 
99
+ t.comment('Tester.assertNotExist()');
100
+ t.assertDoesntExist('foobar', 'Tester.assertNotExist() works as expected [alias]');
101
+
81
102
  t.comment('Tester.assertHttpStatus()');
82
103
  // using file:// protocol, HTTP status is always null
83
- t.assertHttpStatus(null, 'Tester.assertHttpStatus() works as expected');
104
+ t.assertHttpStatus(200, 'Tester.assertHttpStatus() works as expected');
84
105
 
85
106
  t.comment('Tester.assertMatch()');
86
107
  t.assertMatch("the lazy dog", /lazy/, 'Tester.assertMatch() works as expected');
87
108
 
109
+ t.comment('Tester.assertMatches()');
110
+ t.assertMatches("the lazy dog", /lazy/, 'Tester.assertMatches() works as expected [alias]');
111
+
88
112
  t.comment('Tester.assertRaises()');
89
113
  t.assertRaises(function() {
90
114
  throw new Error('plop');
91
115
  }, [], 'Tester.assertRaises() works as expected');
92
116
 
117
+ t.comment('Tester.assertRaise()');
118
+ t.assertRaise(function() {
119
+ throw new Error('plop');
120
+ }, [], 'Tester.assertRaise() works as expected [alias]');
121
+
122
+ t.comment('Tester.assertThrows()');
123
+ t.assertThrows(function() {
124
+ throw new Error('plop');
125
+ }, [], 'Tester.assertThrows() works as expected [alias]');
126
+
93
127
  t.comment('Tester.assertResourceExists()');
94
128
  t.assertResourceExists(/index\.html/, 'Tester.assertResourceExists() works as expected');
95
129
 
130
+ t.comment('Tester.assertResourceExist()');
131
+ t.assertResourceExist(/index\.html/, 'Tester.assertResourceExist() works as expected [alias]');
132
+
96
133
  t.comment('Tester.assertTitle()');
97
134
  t.assertTitle('CasperJS test index', 'Tester.assertTitle() works as expected');
98
135
 
99
136
  t.comment('Tester.assertTitleMatch()');
100
137
  t.assertTitleMatch(/test index/, 'Tester.assertTitleMatch() works as expected');
101
138
 
139
+ t.comment('Tester.assertTitleMatches()');
140
+ t.assertTitleMatches(/test index/, 'Tester.assertTitleMatches() works as expected [alias]');
141
+
102
142
  t.comment('Tester.assertType()');
103
143
  t.assertType("plop", "string", "Tester.assertType() works as expected");
104
144
 
105
145
  t.comment('Tester.assertUrlMatch()');
106
146
  t.assertUrlMatch(/index\.html$/, "Tester.assertUrlMatch() works as expected");
147
+
148
+ t.comment('Tester.assertUrlMatches()');
149
+ t.assertUrlMatches(/index\.html$/, "Tester.assertUrlMatches() works as expected [alias]");
150
+
151
+ t.comment('Tester.assertVisible()');
152
+ t.assertVisible('img', 'Tester.assertVisible() works as expected');
153
+
154
+ t.comment('Tester.assertNotVisible()');
155
+ t.assertNotVisible('p#hidden', 'Tester.assertNotVisible() works as expected');
156
+
157
+ t.comment('Tester.assertInvisible()');
158
+ t.assertInvisible('p#hidden', 'Tester.assertInvisible() works as expected [alias]');
159
+ });
160
+
161
+ casper.thenOpen('tests/site/form.html', function() {
162
+ t.comment('Tester.assertField()');
163
+ t.comment('1. Fill inputs');
164
+ var fpath = phantom.libraryPath + '/README.md';
165
+ this.fill('form[action="result.html"]', {
166
+ 'email': 'chuck@norris.com',
167
+ 'content': 'Am watching thou',
168
+ 'check': true,
169
+ 'choice': 'no',
170
+ 'topic': 'bar',
171
+ 'file': fpath,
172
+ 'checklist[]': ['1', '3']
173
+ });
174
+ t.assertField('email', 'chuck@norris.com', 'Tester.assertField() works as expected with inputs');
175
+ t.assertField('content', 'Am watching thou', 'Tester.assertField() works as expected with textarea');
176
+ t.assertField('check', true, 'Tester.assertField() works as expected with checkboxes');
177
+ t.assertField('choice', 'no', 'Tester.assertField() works as expected with radios');
178
+ t.assertField('topic', 'bar', 'Tester.assertField() works as expected with selects');
179
+ t.assertField('file', 'C:\\fakepath\\README.md', 'Tester.assertField() works as expected with file inputs');
180
+ t.assertField('checklist[]', ['1', '3'], 'Tester.assertField() works as expected with check lists');
181
+ });
182
+
183
+ casper.reload(function() {
184
+ t.comment('2. Unfill inputs');
185
+ this.fill('form[action="result.html"]', {
186
+ 'email': '',
187
+ 'content': '',
188
+ 'check': false,
189
+ 'choice': '',
190
+ 'topic': '',
191
+ 'file': '',
192
+ 'checklist[]': []
193
+ });
194
+ t.assertField('email', '', 'Tester.assertField() works as expected with inputs');
195
+ t.assertField('content', '', 'Tester.assertField() works as expected with textarea');
196
+ t.assertField('check', false, 'Tester.assertField() works as expected with checkboxes');
197
+ t.assertField('choice', null, 'Tester.assertField() works as expected with radios');
198
+ t.assertField('topic', 'foo', 'Tester.assertField() works as expected with selects');
199
+ t.assertField('file', '', 'Tester.assertField() works as expected with file inputs');
200
+ t.assertField('checklist[]', [], 'Tester.assertField() works as expected with check lists');
107
201
  });
108
202
 
109
203
  casper.then(function() {
@@ -116,6 +210,17 @@ casper.then(function() {
116
210
  t.assertEquals(t.getPasses().length, passCount + 1, "Tester.getPasses() works as expected");
117
211
  });
118
212
 
213
+ casper.then(function() {
214
+ t.comment('Tester.calculateSuiteDuration()');
215
+ function add(a, b) {
216
+ return a + b;
217
+ }
218
+ var passedTime = t.getPassesTime().reduce(add, 0),
219
+ failedTime = t.getFailuresTime().reduce(add, 0),
220
+ calculatedSum = t.calculateSuiteDuration();
221
+ t.assertEquals(calculatedSum, passedTime + failedTime, "Tester.calculateSuiteDuration() works as expected")
222
+ });
223
+
119
224
  casper.run(function() {
120
- t.done();
225
+ t.done(59);
121
226
  });
@@ -1,4 +1,82 @@
1
- var utils = require('utils'), t = casper.test, x = require('casper').selectXPath;
1
+ /*global casper*/
2
+ /*jshint strict:false maxstatements:99*/
3
+ var utils = require('utils'),
4
+ t = casper.test,
5
+ x = require('casper').selectXPath;
6
+
7
+ t.comment('betterTypeOf()');
8
+ (function() {
9
+ var testCases = [
10
+ {subject: 1, expected: 'number'},
11
+ {subject: '1', expected: 'string'},
12
+ {subject: {}, expected: 'object'},
13
+ {subject: [], expected: 'array'},
14
+ {subject: undefined, expected: 'undefined'},
15
+ {subject: null, expected: 'null'},
16
+ {subject: function(){}, expected: 'function'},
17
+ {subject: window, expected: 'domwindow'},
18
+ {subject: new Date(), expected: 'date'},
19
+ {subject: new RegExp(), expected: 'regexp'}
20
+ ];
21
+ testCases.forEach(function(testCase) {
22
+ t.assertEquals(utils.betterTypeOf(testCase.subject), testCase.expected,
23
+ require('utils').format('betterTypeOf() detects expected type "%s"', testCase.subject));
24
+ });
25
+ })();
26
+
27
+ t.comment('cleanUrl()');
28
+ (function() {
29
+ var testCases = {
30
+ 'http://google.com/': 'http://google.com/',
31
+ 'http://google.com': 'http://google.com/',
32
+ 'http://www.google.com/': 'http://www.google.com/',
33
+ 'http://www.google.com/?plop=2': 'http://www.google.com/?plop=2',
34
+ 'https://google.com/': 'https://google.com/',
35
+ 'https://google.com': 'https://google.com/',
36
+ 'https://www.google.com/': 'https://www.google.com/',
37
+ 'https://www.google.com/?plop=2': 'https://www.google.com/?plop=2',
38
+ 'file:///Users/toto/toto.html': 'file:///Users/toto/toto.html',
39
+ '/100': '/100'
40
+ };
41
+ for (var testCase in testCases) {
42
+ t.assertEquals(utils.cleanUrl(testCase), testCases[testCase], 'cleanUrl() cleans an URL');
43
+ }
44
+ })();
45
+
46
+ t.comment('clone()');
47
+ (function() {
48
+ var a = {a: 1, b: 2, c: [1, 2]};
49
+ t.assertEquals(utils.clone(a), a);
50
+ var b = [1, 2, 3, a];
51
+ t.assertEquals(utils.clone(b), b);
52
+ })();
53
+
54
+ t.comment('equals()');
55
+ (function() {
56
+ t.assert(utils.equals(null, null), 'equals() null equality');
57
+ t.assertNot(utils.equals(null, undefined), 'equals() null vs. undefined inequality');
58
+ t.assert(utils.equals("hi", "hi"), 'equals() string equality');
59
+ t.assertNot(utils.equals("hi", "ih"), 'equals() string inequality');
60
+ t.assert(utils.equals(5, 5), 'equals() number equality');
61
+ t.assertNot(utils.equals("5", 5), 'equals() number equality without implicit cast');
62
+ t.assert(utils.equals(5, 5.0), 'equals() number equality with cast');
63
+ t.assertNot(utils.equals(5, 10), 'equals() number inequality');
64
+ t.assert(utils.equals([], []), 'equals() empty array equality');
65
+ t.assert(utils.equals([1,2], [1,2]), 'equals() array equality');
66
+ t.assert(utils.equals([1,2,[1,2,function(){}]], [1,2,[1,2,function(){}]]), 'equals() complex array equality');
67
+ t.assertNot(utils.equals([1,2,[1,2,function(a){}]], [1,2,[1,2,function(b){}]]), 'equals() complex array inequality');
68
+ t.assertNot(utils.equals([1,2], [2,1]), 'equals() shuffled array inequality');
69
+ t.assertNot(utils.equals([1,2], [1,2,3]), 'equals() array length inequality');
70
+ t.assert(utils.equals({}, {}), 'equals() empty object equality');
71
+ t.assert(utils.equals({a:1,b:2}, {a:1,b:2}), 'equals() object length equality');
72
+ t.assert(utils.equals({a:1,b:2}, {b:2,a:1}), 'equals() shuffled object keys equality');
73
+ t.assertNot(utils.equals({a:1,b:2}, {a:1,b:3}), 'equals() object inequality');
74
+ t.assert(utils.equals({1:{name:"bob",age:28}, 2:{name:"john",age:26}}, {1:{name:"bob",age:28}, 2:{name:"john",age:26}}), 'equals() complex object equality');
75
+ t.assertNot(utils.equals({1:{name:"bob",age:28}, 2:{name:"john",age:26}}, {1:{name:"bob",age:28}, 2:{name:"john",age:27}}), 'equals() complex object inequality');
76
+ t.assert(utils.equals(function(x){return x;}, function(x){return x;}), 'equals() function equality');
77
+ t.assertNot(utils.equals(function(x){return x;}, function(y){return y+2;}), 'equals() function inequality');
78
+ t.assert(utils.equals([{a:1, b:2}, {c:3, d:4}], [{a:1, b:2}, {c:3, d:4}]), 'equals() arrays of objects');
79
+ })();
2
80
 
3
81
  t.comment('fileExt()');
4
82
  (function() {
@@ -18,7 +96,7 @@ t.comment('fileExt()');
18
96
 
19
97
  t.comment('fillBlanks()');
20
98
  (function() {
21
- testCases = {
99
+ var testCases = {
22
100
  'foo': 'foo ',
23
101
  ' foo bar ': ' foo bar ',
24
102
  ' foo bar ': ' foo bar '
@@ -31,7 +109,7 @@ t.comment('fillBlanks()');
31
109
 
32
110
  t.comment('getPropertyPath()');
33
111
  (function() {
34
- testCases = [
112
+ var testCases = [
35
113
  {
36
114
  input: utils.getPropertyPath({}, 'a.b.c'),
37
115
  output: undefined
@@ -75,7 +153,7 @@ t.comment('isArray()');
75
153
 
76
154
  t.comment('isClipRect()');
77
155
  (function() {
78
- testCases = [
156
+ var testCases = [
79
157
  [{}, false],
80
158
  [{top: 2}, false],
81
159
  [{top: 2, left: 2, width: 2, height: 2}, true],
@@ -88,6 +166,22 @@ t.comment('isClipRect()');
88
166
  });
89
167
  })();
90
168
 
169
+ t.comment('isHTTPResource()');
170
+ (function() {
171
+ var testCases = [
172
+ [{}, false],
173
+ [{url: 'file:///var/www/i.html'}, false],
174
+ [{url: 'mailto:plop@plop.com'}, false],
175
+ [{url: 'ftp://ftp.plop.com'}, false],
176
+ [{url: 'HTTP://plop.com/'}, true],
177
+ [{url: 'https://plop.com/'}, true]
178
+ ];
179
+
180
+ testCases.forEach(function(testCase) {
181
+ t.assertEquals(utils.isHTTPResource(testCase[0]), testCase[1], 'isHTTPResource() checks for an HTTP resource');
182
+ });
183
+ })();
184
+
91
185
  t.comment('isObject()');
92
186
  (function() {
93
187
  t.assertEquals(utils.isObject({}), true, 'isObject() checks for an Object');
@@ -137,7 +231,7 @@ t.comment('isWebPage()');
137
231
 
138
232
  t.comment('isJsFile()');
139
233
  (function() {
140
- testCases = {
234
+ var testCases = {
141
235
  '': false,
142
236
  'toto.png': false,
143
237
  'plop': false,
@@ -152,7 +246,7 @@ t.comment('isJsFile()');
152
246
 
153
247
  t.comment('mergeObjects()');
154
248
  (function() {
155
- testCases = [
249
+ var testCases = [
156
250
  {
157
251
  obj1: {a: 1}, obj2: {b: 2}, merged: {a: 1, b: 2}
158
252
  },
@@ -181,9 +275,15 @@ t.comment('mergeObjects()');
181
275
  });
182
276
  })();
183
277
 
278
+ t.comment('objectValues()');
279
+ (function() {
280
+ t.assertEquals(utils.objectValues({}), [], 'objectValues() can extract object values');
281
+ t.assertEquals(utils.objectValues({a: 1, b: 2}), [1, 2], 'objectValues() can extract object values');
282
+ })();
283
+
184
284
  t.comment('unique()');
185
285
  (function() {
186
- testCases = [
286
+ var testCases = [
187
287
  {
188
288
  input: [1,2,3],
189
289
  output: [1,2,3]
@@ -206,4 +306,4 @@ t.comment('unique()');
206
306
  });
207
307
  })();
208
308
 
209
- t.done();
309
+ t.done(112);
@@ -1,16 +1,47 @@
1
+ /*global casper*/
2
+ /*jshint strict:false*/
1
3
  casper.test.comment('phantom.Casper.XUnitExporter');
2
4
 
3
- xunit = require('xunit').create();
5
+ var xunit = require('xunit').create();
4
6
  xunit.addSuccess('foo', 'bar');
5
- casper.test.assertMatch(xunit.getXML(), /<testcase classname="foo" name="bar"/, 'XUnitExporter.addSuccess() adds a successful testcase');
7
+ casper.test.assertMatch(xunit.getXML(),
8
+ /<testcase classname="foo" name="bar"/,
9
+ 'XUnitExporter.addSuccess() adds a successful testcase');
6
10
  xunit.addFailure('bar', 'baz', 'wrong', 'chucknorriz');
7
- casper.test.assertMatch(xunit.getXML(), /<testcase classname="bar" name="baz"><failure type="chucknorriz">wrong/, 'XUnitExporter.addFailure() adds a failed testcase');
11
+ casper.test.assertMatch(xunit.getXML(),
12
+ /<testcase classname="bar" name="baz"><failure type="chucknorriz">wrong/,
13
+ 'XUnitExporter.addFailure() adds a failed testcase');
8
14
 
9
15
  // named classname
10
16
  xunit = require('xunit').create();
11
17
  xunit.addSuccess(require('fs').workingDirectory + '/plop.js', 'It worked');
12
- casper.test.assertMatch(xunit.getXML(), /<testcase classname="plop" name="It worked"/, 'XUnitExporter.addSuccess() handles class name');
18
+ casper.test.assertMatch(xunit.getXML(),
19
+ /<testcase classname="(.*)plop" name="It worked"/,
20
+ 'XUnitExporter.addSuccess() handles class name');
13
21
  xunit.addSuccess(require('fs').workingDirectory + '/plip.js', 'Failure');
14
- casper.test.assertMatch(xunit.getXML(), /<testcase classname="plip" name="Failure"/, 'XUnitExporter.addFailure() handles class name');
22
+ casper.test.assertMatch(xunit.getXML(),
23
+ /<testcase classname="(.*)plip" name="Failure"/,
24
+ 'XUnitExporter.addFailure() handles class name');
25
+
26
+ // named with time
27
+ xunit = require('xunit').create();
28
+ xunit.addSuccess('foo', 'It worked', 1024);
29
+ casper.test.assertMatch(xunit.getXML(),
30
+ /<testcase classname="foo" name="It worked" time="(.*)"/,
31
+ 'XUnitExporter.addSuccess() writes duration of test');
32
+ xunit.addFailure('bar', 'baz', 'wrong', 'chucknorriz', 1024);
33
+ casper.test.assertMatch(xunit.getXML(),
34
+ /<testcase classname="bar" name="baz" time="(.*)"><failure type="chucknorriz">wrong/,
35
+ 'XUnitExporter.addFailure() adds a failed testcase with duration');
36
+
37
+ // named with time
38
+ xunit = require('xunit').create();
39
+ casper.test.assertMatch(xunit.getXML(),
40
+ /<testsuite>/,
41
+ 'XUnitExporter.create() created <testsuite> without time');
42
+ xunit.setSuiteDuration(1024);
43
+ casper.test.assertMatch(xunit.getXML(),
44
+ /<testsuite time="1.024">/,
45
+ 'XUnitExporter.setSuiteDuration() sets time in seconds');
15
46
 
16
- casper.test.done();
47
+ casper.test.done(8);