Skip to content

Commit eb7e68a

Browse files
committed
Updated karma config to use phantomJS, removed features that break in old browsers.
1 parent af222a1 commit eb7e68a

File tree

8 files changed

+80
-61
lines changed

8 files changed

+80
-61
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: node_js
22
node_js:
33
- "0.10"
4+
- "0.12"
45
before_script:
56
- export DISPLAY=:99.0
67
- sh -e /etc/init.d/xvfb start

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ dist/%.js: $(BIN)
2929
@$(BIN)/webpack --devtool source-map
3030

3131
test: $(BIN)
32-
@$(BIN)/karma start --browsers Firefox --single-run
32+
@$(BIN)/karma start --single-run
3333

3434
dev: $(BIN)
3535
script/build-watch
@@ -52,15 +52,15 @@ define release
5252
git tag "v$$NEXT_VERSION" -m "release v$$NEXT_VERSION"
5353
endef
5454

55-
release-patch: test build
55+
release-patch: test clean build
5656
@$(call release,patch)
5757

58-
release-minor: test build
58+
release-minor: test clean build
5959
@$(call release,minor)
6060

61-
release-major: test build
61+
release-major: test clean build
6262
@$(call release,major)
6363

64-
publish: build
64+
publish: clean build
6565
git push --tags origin HEAD:master
6666
npm publish

karma.conf.js

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
11
module.exports = function(config) {
2-
config.set({
2+
config.set({
33

4-
basePath: '',
4+
basePath: '',
55

6-
frameworks: ['jasmine'],
6+
frameworks: ['jasmine'],
77

8-
files: [
9-
'specs/main.js'
10-
],
8+
files: [
9+
'specs/main.js'
10+
],
1111

12-
exclude: [
13-
],
12+
exclude: [
13+
],
1414

15-
preprocessors: {
16-
'specs/main.js': ['webpack']
17-
},
15+
preprocessors: {
16+
'specs/main.js': ['webpack']
17+
},
1818

19-
webpack: {
20-
cache: true,
21-
module: {
22-
loaders: [
23-
{
24-
test: /\.(?:js|es).?$/,
25-
loader: 'babel-loader',
26-
exclude: /(node_modules)/
27-
}
28-
]
29-
},
30-
resolve: {
31-
extensions: ["", ".webpack.js", ".web.js", ".js", ".es6"]
32-
}
33-
},
19+
webpack: {
20+
cache: true,
21+
module: {
22+
loaders: [
23+
{
24+
test: /\.(?:js|es).?$/,
25+
loader: 'babel-loader',
26+
exclude: /(node_modules)/
27+
}
28+
]
29+
},
30+
resolve: {
31+
extensions: ["", ".webpack.js", ".web.js", ".js", ".es6"]
32+
}
33+
},
3434

35-
webpackServer: {
36-
stats: {
37-
colors: true
38-
}
39-
},
35+
webpackServer: {
36+
stats: {
37+
colors: true
38+
}
39+
},
4040

41-
reporters: ['progress'],
41+
reporters: ['progress'],
4242

43-
port: 9876,
43+
port: 9876,
4444

45-
colors: true,
45+
colors: true,
4646

47-
logLevel: config.LOG_INFO,
47+
logLevel: config.LOG_INFO,
4848

49-
autoWatch: false,
49+
autoWatch: false,
5050

51-
browsers: ['Chrome'],
51+
browsers: ['PhantomJS', 'Firefox'],
5252

53-
singleRun: false,
53+
singleRun: false,
5454

55-
plugins: [
56-
require('karma-jasmine'),
57-
require('karma-chrome-launcher'),
58-
require('karma-firefox-launcher'),
59-
require('karma-webpack')
60-
]
61-
});
55+
plugins: [
56+
require('karma-jasmine'),
57+
require('karma-phantomjs-launcher'),
58+
require('karma-firefox-launcher'),
59+
require('karma-webpack')
60+
]
61+
});
6262
};

lib/utils/domFns.es6

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {findInArray, isFunction, int} from './shims';
1+
import {findInArray, isFunction, isNum, int} from './shims';
22
import browserPrefix from './getPrefix';
33
import assign from 'object-assign';
44
import React from 'react';
@@ -125,7 +125,7 @@ export function styleHacks(draggable) {
125125
export function createCoreEvent(draggable, clientX, clientY) {
126126
// State changes are often (but not always!) async. We want the latest value.
127127
let state = draggable._pendingState || draggable.state;
128-
let isStart = !Number.isFinite(state.lastX);
128+
let isStart = !isNum(state.lastX);
129129

130130
return {
131131
node: React.findDOMNode(draggable),

lib/utils/shims.es6

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ let lifeCycleMethods = ['constructor', 'componentWillMount', 'componentDidMount'
2222
// ES6 classes don't autobind their methods
2323
export function autobind(component) {
2424
let toBind = Object.getOwnPropertyNames(Object.getPrototypeOf(component));
25-
for (let key of toBind) {
25+
// Not using for...of here because it requires a full core-js shim to work everywhere.
26+
for (var i = 0; i < toBind.length; i++) {
27+
var key = toBind[i];
2628
if (!isFunction(component[key]) || lifeCycleMethods.indexOf(key) !== -1) continue;
2729
component[key] = component[key].bind(component);
2830
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"test": "make test",
88
"dev": "make dev",
9-
"build": "make build",
9+
"build": "make clean build",
1010
"commitLint": "eslint `git diff --cached --diff-filter=ACMRTUXB --name-only HEAD | egrep '\\.es6$'`"
1111
},
1212
"repository": {
@@ -30,13 +30,14 @@
3030
"babel-loader": "^5.1.4",
3131
"eslint": "^0.23.0",
3232
"karma": "^0.12.19",
33-
"karma-chrome-launcher": "^0.1.4",
3433
"karma-cli": "0.0.4",
3534
"karma-firefox-launcher": "^0.1.3",
3635
"karma-jasmine": "^0.1.5",
36+
"karma-phantomjs-launcher": "^0.2.0",
3737
"karma-webpack": "^1.2.1",
3838
"lodash": "^3.9.3",
3939
"open": "0.0.5",
40+
"phantomjs": "^1.9.17",
4041
"pre-commit": "^1.0.10",
4142
"react": "^0.13.2",
4243
"semver": "^4.3.3",

specs/draggable.spec.jsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var TestUtils = require('react/lib/ReactTestUtils');
33
var Draggable = require('../index');
44
var DraggableCore = require('../index').DraggableCore;
55
var _ = require('lodash');
6+
var browserPrefix = require('../lib/utils/getPrefix.es6');
7+
var dashedBrowserPrefix = browserPrefix ? '-' + browserPrefix.toLowerCase() + '-' : '';
68

79
/*global describe,it,expect,afterEach */
810
describe('react-draggable', function () {
@@ -33,8 +35,8 @@ describe('react-draggable', function () {
3335
drag = (<Draggable><div className="foo" style={{color: 'black'}}/></Draggable>);
3436

3537
expect(renderToHTML(drag)).toEqual('<div class="foo" ' +
36-
'style="touch-action:none;color:black;transform:translate(0px,0px);-moz-transform:translate(0px,0px);" ' +
37-
'data-reactid=".1"></div>');
38+
'style="touch-action:none;color:black;transform:translate(0px,0px);' + dashedBrowserPrefix +
39+
'transform:translate(0px,0px);" data-reactid=".1"></div>');
3840
});
3941

4042
// NOTE: this runs a shallow renderer, which DOES NOT actually render <DraggableCore>
@@ -48,7 +50,7 @@ describe('react-draggable', function () {
4850
<DraggableCore {...Draggable.defaultProps} handle=".foo" className="react-draggable"
4951
style={{
5052
'transform': 'translate(0px,0px)',
51-
'MozTransform': 'translate(0px,0px)'
53+
[browserPrefix + 'Transform']: 'translate(0px,0px)'
5254
}}>
5355
<div />
5456
</DraggableCore>
@@ -131,8 +133,12 @@ describe('react-draggable', function () {
131133
TestUtils.Simulate.mouseDown(node, {clientX: 0, clientY: 0});
132134
// Simulate a movement; can't use TestUtils here because it uses react's event system only,
133135
// but <DraggableCore> attaches event listeners directly to the document.
134-
var e = new MouseEvent('mousemove', {clientX: 100, clientY: 100});
135-
document.dispatchEvent(e);
136+
// Would love to new MouseEvent() here but it doesn't work with PhantomJS / old browsers.
137+
// var e = new MouseEvent('mousemove', {clientX: 100, clientY: 100});
138+
var evt = document.createEvent('MouseEvents');
139+
evt.initMouseEvent('mousemove', true, true, window,
140+
0, 0, 0, 100, 100, false, false, false, false, 0, null);
141+
document.dispatchEvent(evt);
136142
TestUtils.Simulate.mouseUp(node);
137143

138144
var style = node.getAttribute('style');
@@ -142,7 +148,7 @@ describe('react-draggable', function () {
142148

143149
it('should add and remove user-select styles', function () {
144150
// Karma runs in firefox in our tests
145-
var userSelectStyle = ';user-select: none;-moz-user-select: none;';
151+
var userSelectStyle = ';user-select: none;' + dashedBrowserPrefix + 'user-select: none;';
146152

147153
drag = TestUtils.renderIntoDocument(
148154
<Draggable>

specs/main.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1+
// PhantomJS STILL doesn't support bind yet
2+
/*eslint no-extend-native:0*/
3+
Function.prototype.bind = Function.prototype.bind || function (thisp) {
4+
var fn = this;
5+
return function () {
6+
return fn.apply(thisp, arguments);
7+
};
8+
};
9+
110
require('./draggable.spec.jsx');

0 commit comments

Comments
 (0)