Skip to content

Commit 6c6826c

Browse files
author
Sebastien Pereira
committed
rework test infra. Fixes #22. Ref #6.
1 parent cafb772 commit 6c6826c

File tree

17 files changed

+428
-161
lines changed

17 files changed

+428
-161
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.travis.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
language: node_js
2-
node_js: "0.10"
3-
install: "npm -g install [email protected]"
4-
script: "jshint ."
2+
node_js:
3+
- '0.10'
4+
install:
5+
- npm install -g grunt-cli
6+
- npm -g install bower
7+
- npm install
8+
- bower install
9+
script:
10+
- grunt jshint test:remote
11+
env:
12+
global:
13+
- secure: eY1OxvXmDHrxYoO5hQwcWNptaJClL69aswUw5G+ZNppSEymNCTquYN/MS87iZm76G98o4A0aafM989d5UDhjU187NYdxf6K7jEPwtaxuHi6d48M0LRG/DoAWCNOUoNyNuhpRCVEB7XmwvZOG9nmoRcPvt+KjM5VkiOvp+CluCk0=
14+
- secure: F0RyTrC3kdKomLNbKXJJA1Ju0ZCnB5E7oW7eYwkikLjlfn/4rBkuX4MYJqGBdCIwotpx0k30Wmql7cpYsk9pfM36NIqZoY3bOMITAY/FR8gxiE6zLjFEV/JBdY1hKIeDStsCEPJIRPd27oq4yK1j8dVFel9rI+aENWV1+CZ7o7o=

Gruntfile.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* global module */
2+
module.exports = function (grunt) {
3+
grunt.initConfig({
4+
pkg: grunt.file.readJSON("package.json"),
5+
6+
jshint: {
7+
src: [
8+
"**/*.js", "!{node_modules,dev}/**"
9+
],
10+
options: {
11+
jshintrc: ".jshintrc"
12+
}
13+
},
14+
15+
intern: {
16+
// run tests on local desktop browser(s)
17+
local: {
18+
options: {
19+
runType: "runner",
20+
config: "tests/intern/local",
21+
reporters: ["runner"]
22+
}
23+
},
24+
// run tests on remote cloud service
25+
remote: {
26+
options: {
27+
runType: "runner",
28+
config: "tests/intern/saucelab",
29+
reporters: ["runner"]
30+
}
31+
}
32+
}
33+
});
34+
35+
// Load plugins
36+
grunt.loadNpmTasks("intern");
37+
grunt.loadNpmTasks("grunt-contrib-jshint");
38+
39+
// Aliases
40+
grunt.registerTask("default", ["jshint"]);
41+
42+
// Testing.
43+
// always specify the target e.g. grunt test:remote, grunt test:remote
44+
// then add on any other flags afterwards e.g. console, lcovhtml
45+
var testTaskDescription = "Run this task instead of the intern task directly! \n" +
46+
"Always specify the test target e.g. \n" +
47+
"grunt test:local\n" +
48+
"grunt test:local.android\n" +
49+
"grunt test:local.ios\n" +
50+
"grunt test:remote\n\n" +
51+
"Add any optional reporters via a flag e.g. \n" +
52+
"grunt test:local:console\n" +
53+
"grunt test:local:lcovhtml\n" +
54+
"grunt test:local:console:lcovhtml";
55+
grunt.registerTask("test", testTaskDescription, function (target) {
56+
function addReporter(reporter) {
57+
var property = "intern." + target + ".options.reporters",
58+
value = grunt.config.get(property);
59+
if (value.indexOf(reporter) !== -1) {
60+
return;
61+
}
62+
value.push(reporter);
63+
grunt.config.set(property, value);
64+
}
65+
if (this.flags.lcovhtml) {
66+
addReporter("lcovhtml");
67+
}
68+
if (this.flags.console) {
69+
addReporter("console");
70+
}
71+
grunt.task.run("intern:" + target);
72+
});
73+
};

handlers/utils.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ define([
3131

3232
// Check if MouseEvent constructor is supported.
3333
try {
34-
new MouseEvent("mousedown", {}); // jshint ignore:line
34+
//jshint nonew: false
35+
new MouseEvent("mousedown", {});
36+
//jshint nonew: true
3537
utils.SUPPORT_MOUSE_EVENT_CONSTRUCTOR = true;
3638
} catch (e) {
3739
}
@@ -253,6 +255,7 @@ define([
253255
* @param props event properties
254256
* @returns MouseEvent
255257
*/
258+
/*jshint maxcomplexity: 15*/
256259
function createMouseEvent(pointerType, props) {
257260
// Mouse Event spec
258261
// http://www.w3.org/TR/2001/WD-DOM-Level-3-Events-20010823/events.html#Events-eventgroupings-mouseevents
@@ -261,7 +264,7 @@ define([
261264
return new MouseEvent(pointerType, props);
262265
}
263266
var e = document.createEvent("MouseEvents");
264-
/* jshint ignore:start */
267+
265268
e.initMouseEvent(
266269
pointerType,
267270
(props.bubbles),
@@ -279,7 +282,6 @@ define([
279282
(props.button) || 0,
280283
(props.relatedTarget) ||
281284
null);
282-
/* jshint ignore:end */
283285
return e;
284286
}
285287

package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "dpointer",
3+
"version": "0.1.1-dev",
4+
"dependencies": {
5+
},
6+
"devDependencies": {
7+
"intern": "1.6.x",
8+
"grunt": "~0.4.2",
9+
"grunt-contrib-jshint": "~0.6.3"
10+
},
11+
"licenses": [
12+
{
13+
"type": "BSD",
14+
"url": "https://github.com/ibm-js/dpointer/blob/master/LICENSE"
15+
}
16+
],
17+
"bugs": "https://github.com/ibm-js/dpointer/issues"
18+
}

tests/capture/capture1.html renamed to samples/capture.html

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<meta name="viewport"
99
content="width=device-width, initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
1010
<meta name="apple-mobile-web-app-capable" content="yes">
11+
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
1112
<title>Pointer Events: capture > capture1</title>
1213

1314
<style>
@@ -23,24 +24,15 @@
2324
}
2425

2526
#container {
26-
height: 200px;
27-
width: 200px;
27+
height: auto;
28+
width: auto;
2829
background-color: #AAAAAA;
29-
margin: 0;
30+
padding: 10px;
3031
top: 0;
3132
left: 0;
32-
position: absolute;
33-
-webkit-touch-callout: none;
34-
-webkit-user-select: none;
35-
-khtml-user-select: none;
36-
-moz-user-select: none;
37-
-ms-user-select: none;
38-
user-select: none;
3933
}
4034

4135
.btn {
42-
top: 30px;
43-
left: 5px;
4436
width: 150px;
4537
height: 35px;
4638
color: #000000;
@@ -53,6 +45,11 @@
5345
border-color: #000000;
5446
border-radius: 10%;
5547
cursor: pointer;
48+
-webkit-touch-callout: none;
49+
-webkit-user-select: none;
50+
-moz-user-select: none;
51+
-ms-user-select: none;
52+
user-select: none;
5653
}
5754

5855
.btn:active {
@@ -62,11 +59,9 @@
6259
}
6360

6461
#msgArea {
65-
color: white;
6662
background-color: orange;
6763
position: relative;
6864
margin: 0;
69-
top: 200px;
7065
left: 0;
7166
padding: 0;
7267
color: #000000;
@@ -75,12 +70,12 @@
7570
}
7671
</style>
7772

78-
<script>var require = {baseUrl: "../../.."}</script>
79-
<script type="text/javascript" src="../../../requirejs/require.js"></script>
73+
<script>var require = {baseUrl: "../.."}</script>
74+
<script type="text/javascript" src="../../requirejs/require.js"></script>
8075
<script type="text/javascript">
8176
requirejs([
8277
"dpointer/events",
83-
"domReady/domReady!"
78+
"requirejs-domready/domReady!"
8479
], function(pointer){
8580
var msgArea = document.getElementById("msgArea");
8681

@@ -107,6 +102,15 @@
107102
logit(event.target.id + ":pointermove (" + event.clientX + "/" + event.clientY + ")");
108103
});
109104

105+
// disable text selection
106+
msgArea.addEventListener("selectstart", function (e) {
107+
e.preventDefault();
108+
}, false);
109+
110+
// clear log on double click
111+
msgArea.addEventListener("dblclick", function(event){
112+
msgArea.innerHTML = "";
113+
});
110114

111115
function logit(msg){
112116
msgArea.innerHTML = msg + "</br>" + msgArea.innerHTML;
@@ -121,6 +125,6 @@
121125
&#160;
122126
<div id="capturedBtn" class="btn">CAPTURE</div>
123127
</div>
124-
<div id="msgArea">== LOG ==</div>
128+
<div id="msgArea" touch-action="pan-x pan-y">== LOG ==</div>
125129
</body>
126130
</html>

tests/paint/paint2.html renamed to samples/paint-with-capture.html

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
<!DOCTYPE html>
22
<!--
3-
. This sample relies on
4-
pointer capture rather than pointermove and event.button value.
3+
Simple paint application to demonstrate multi touch handling with Pointer Events, using dpointer API.
4+
This sample relies on pointer capture rather than pointermove and event.button value.
55
6-
Sample paint application to demonstrate multi touch handling. This sample illustrate a possible usage of
7-
pointer capture. IE9 doesn't reflect pressed button state on mousemove events. Pointer capture allow to get over
8-
this limitation.
6+
This sample illustrate a possible usage of pointer capture. IE9 doesn't reflect pressed button state on
7+
mousemove events. Pointer capture allow to get over this limitation.
98
10-
Simply change the device orientation to reset the canvas.
11-
Number of active touch point depends on hardware capabilities and system option.
9+
The number of active touch point depends on hardware capabilities and system option.
1210
To use more than 3 touch points on iOS, disable Mutitasking Gestures in Settings > General.
11+
Double Tab/click to clear the canvas.
1312
1413
Tested on:
1514
- Android 4.1.1: stockbrowser + Chrome
@@ -49,12 +48,12 @@
4948
}
5049
</style>
5150

52-
<script>var require = {baseUrl: "../../.."}</script>
53-
<script type="text/javascript" src="../../../requirejs/require.js"></script>
51+
<script>var require = {baseUrl: "../.."}</script>
52+
<script type="text/javascript" src="../../requirejs/require.js"></script>
5453
<script type="text/javascript">
5554
requirejs([
5655
"dpointer/events",
57-
"domReady/domReady!"
56+
"requirejs-domready/domReady!"
5857
], function(pointer){
5958
var canvas = document.getElementById("drawingArea");
6059
var context = canvas.getContext("2d");
@@ -88,8 +87,8 @@
8887
context.fillRect(event.clientX, event.clientY, 5, 5);
8988
}
9089
});
91-
// reset canvas on orientation change
92-
window.addEventListener("resize", function(){
90+
// reset canvas on double tap/click
91+
canvas.addEventListener("dblclick", function(){
9392
canvas.height = window.innerHeight;
9493
canvas.width = window.innerWidth;
9594
});

tests/paint/paint1.html renamed to samples/paint.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!DOCTYPE html>
22
<!--
3-
Sample paint application to demonstrate multi touch handling with pointer events.
4-
Simply change the device orientation to reset the canvas.
5-
Number of active touch point depends on hardware capabilities and system option.
3+
Simple paint application to demonstrate multi touch handling with Pointer Events, using dpointer API.
4+
The number of active touch point depends on hardware capabilities and system option.
65
To use more than 3 touch points on iOS, disable Mutitasking Gestures in Settings > General.
6+
Double Tab/click to clear the canvas.
77
88
Tested on:
99
- Android 4.1.1: stockbrowser + Chrome
@@ -43,12 +43,12 @@
4343
}
4444
</style>
4545

46-
<script>var require = {baseUrl: "../../.."}</script>
47-
<script type="text/javascript" src="../../../requirejs/require.js"></script>
46+
<script>var require = {baseUrl: "../.."}</script>
47+
<script type="text/javascript" src="../../requirejs/require.js"></script>
4848
<script type="text/javascript">
4949
requirejs([
5050
"dpointer/events",
51-
"domReady/domReady!"
51+
"requirejs-domready/domReady!"
5252
], function(pointer){
5353
try {
5454
var canvas = document.getElementById("drawingArea");
@@ -64,8 +64,8 @@
6464
}
6565
});
6666

67-
// reset canvas on orientation change
68-
window.addEventListener("resize", function(){
67+
// reset canvas on double tap/click
68+
canvas.addEventListener("dblclick", function(){
6969
canvas.height = window.innerHeight;
7070
canvas.width = window.innerWidth;
7171
});

tests/intern/TestUtils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Utilities for unit tests
3+
*/
4+
define([], function () {
5+
// avoid failure on IE9: console is not be defined when dev tools is not opened
6+
if (!window.console) {
7+
window.console = {};
8+
}
9+
if (!window.console.log) {
10+
window.console.log = function () {
11+
};
12+
}
13+
return this;
14+
}
15+
);

0 commit comments

Comments
 (0)