Skip to content

Commit f7e27cf

Browse files
committed
fix phantomjs tests
1 parent a70f5f0 commit f7e27cf

7 files changed

+32
-60
lines changed

js/event.js

+16
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
return false;
1515
}
1616

17+
if (!CustomEvent){
18+
var CustomEvent = function CustomEvent ( event, params ) {
19+
params = params || { bubbles: false, cancelable: false, detail: undefined };
20+
var evt = document.createEvent( 'CustomEvent' );
21+
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
22+
return evt;
23+
}
24+
CustomEvent.prototype = window.Event.prototype;
25+
window.CustomEvent = CustomEvent;
26+
}
27+
1728
// Move these to utils.js
1829

1930
// Maintain references to events so we can mass-remove them later
@@ -225,6 +236,11 @@
225236
/* Add custom events for adding and removing blocks from the DOM */
226237
function registerElementsForAddRemoveEvents(root, eventPrefix, parentList, childList){
227238

239+
if (typeof MutationObserver === 'undefined'){
240+
console.warn('If you see this and you are not running tests in PhantomJS you have problems');
241+
return;
242+
}
243+
228244
var blockObserver = new MutationObserver(function(mutations){
229245
mutations.forEach(function(mutation){
230246
// send childAdded or childRemove event to parent element

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"test": "test"
1010
},
1111
"scripts": {
12-
"test": "./node_modules/karma/bin/karma start karma.conf.js"
12+
"test": "phantomjs test/all-blocks-have-functions.js ; karma start test/karma.conf.js",
13+
"start": "echo \"open http://localhost:8000/playground.html in your web browser\";static -p 8000"
1314
},
1415
"repository": {
1516
"type": "git",
@@ -27,6 +28,7 @@
2728
"karma-coverage": "^0.5.2",
2829
"karma-phantomjs-launcher": "^0.2.1",
2930
"karma-qunit": "^0.1.5",
31+
"node-static": "^0.7.7",
3032
"parse5": "^1.5.0",
3133
"phantomjs": "^1.9.18",
3234
"qunitjs": "^1.19.0"

run_tests.sh

-15
This file was deleted.

test/all-blocks-have-functions.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
/**
22
* Use with PhantomJS:
33
*
4-
* phantomjs test/all-blocks-have-functions.js playground.html
4+
* phantomjs test/all-blocks-have-functions.js
55
*
66
* Tests if all blocks in the page sidebar have defined functions.
77
*/
88
var webPage = require('webpage');
99
var system = require('system');
10-
var pageName;
11-
12-
if (system.args.length <= 1) {
13-
console.error('Must provide playground.html');
14-
phantom.exit(-1);
15-
} else {
16-
pageName = system.args[1];
17-
}
10+
var pageName = 'playground.html';
1811

1912
var page = webPage.create();
2013

karma.conf.js test/karma.conf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = function(config) {
55
config.set({
66

77
// base path that will be used to resolve all patterns (eg. files, exclude)
8-
basePath: '',
8+
basePath: '..',
99

1010

1111
// frameworks to use
@@ -29,7 +29,7 @@ module.exports = function(config) {
2929
'test/test-helpers.js',
3030
'test/sinon-1.12.2.js',
3131
'test/runtime.js',
32-
//'test/all-blocks-have-functions.js'
32+
// 'test/all-blocks-have-functions.js'
3333
],
3434

3535

test/runtime.html

-24
This file was deleted.

test/runtime.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ QUnit.test('copy', function(assert){
4646
assert.ok(copy[0] !== original[2]);
4747
});
4848
QUnit.test('itemAt', function(assert){
49-
var array = runtime.array;
49+
var array = runtime.array;
5050
var image = runtime.image.get('images/mascot/mascot-steampunk.png');
5151
var sprite = runtime.sprite.create();
5252
var original = ['item1',image,sprite];
@@ -71,7 +71,7 @@ QUnit.test('makeString', function(assert){
7171
assert.ok(sentence === "the,boy,went");
7272
});
7373
QUnit.test('append', function(assert){
74-
var array = runtime.array;
74+
var array = runtime.array;
7575
var image = runtime.image.get('images/mascot/mascot-steampunk.png');
7676
var sprite = runtime.sprite.create();
7777
var appended = ['item1',sprite];
@@ -83,7 +83,7 @@ QUnit.test('append', function(assert){
8383
assert.ok(appended[3] === image);
8484
});
8585
QUnit.test('prepend', function(assert){
86-
var array = runtime.array;
86+
var array = runtime.array;
8787
var image = runtime.image.get('images/mascot/mascot-steampunk.png');
8888
var sprite = runtime.sprite.create();
8989
var prependArray = ['item1',sprite];
@@ -95,22 +95,22 @@ QUnit.test('prepend', function(assert){
9595
assert.ok(prependArray[3] === sprite);
9696
});
9797
QUnit.test('length', function(assert){
98-
var array = runtime.array;
98+
var array = runtime.array;
9999
var lengthArray = ['one','two','three'];
100100
assert.ok(array.length(lengthArray) === 3);
101101
});
102102
QUnit.test('removeItem', function(assert){
103-
var array = runtime.array;
103+
var array = runtime.array;
104104
var image = runtime.image.get('images/mascot/mascot-steampunk.png');
105105
var sprite = runtime.sprite.create();
106106
var array1 = ['item1',image,sprite];
107107
array.removeItem(array1,1);
108108
assert.ok(array1[0] === 'item1');
109109
assert.ok(array1[1] === sprite);
110-
assert.ok(array1.length === 2);
110+
assert.ok(array1.length === 2);
111111
});
112112
QUnit.test('pop', function(assert){
113-
var array = runtime.array;
113+
var array = runtime.array;
114114
var image = runtime.image.get('images/mascot/mascot-steampunk.png');
115115
var sprite = runtime.sprite.create();
116116
var array1 = ['item1',image,sprite];
@@ -120,7 +120,7 @@ QUnit.test('pop', function(assert){
120120
assert.ok(array1.length === 2);
121121
});
122122
QUnit.test('shift', function(assert){
123-
var array = runtime.array;
123+
var array = runtime.array;
124124
var image = runtime.image.get('images/mascot/mascot-steampunk.png');
125125
var sprite = runtime.sprite.create();
126126
var array1 = ['item1',image,sprite];
@@ -130,7 +130,7 @@ QUnit.test('shift', function(assert){
130130
assert.ok(array1.length === 2);
131131
});
132132
QUnit.test('reverse', function(assert){
133-
var array = runtime.array;
133+
var array = runtime.array;
134134
var image = runtime.image.get('images/mascot/mascot-steampunk.png');
135135
var sprite = runtime.sprite.create();
136136
var array1 = ['item1',image,sprite];

0 commit comments

Comments
 (0)