Skip to content

Commit 913ef27

Browse files
Merge pull request #214 from juliandescottes/feature-add-tests
Feature add tests
2 parents 17824ae + 1a8f10c commit 913ef27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1162
-180
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: node_js
22
node_js:
3-
- 0.8
3+
- 0.10
44
before_install:
55
- npm update -g npm
66
- npm install -g grunt-cli

Gruntfile.js

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,48 @@
1010
* If you run this task locally, it may require some env set up first.
1111
*/
1212

13-
var SOURCE_FOLDER = "src";
1413

1514
module.exports = function(grunt) {
1615
var dateFormat = require('dateformat');
1716
var now = new Date();
1817
var version = '-' + dateFormat(now, "yyyy-mm-dd-hh-MM");
1918

20-
var mapToSrcFolder = function (path) {return [SOURCE_FOLDER, path].join('/');};
19+
var mapToSrcFolder = function (path) {
20+
return "src/" + path;
21+
};
2122

22-
var piskelScripts = require('./src/piskel-script-list.js').scripts.map(mapToSrcFolder);
23+
var piskelScripts = require('./src/piskel-script-list.js').scripts.map(mapToSrcFolder).filter(function (path) {
24+
return path.indexOf('devtools') === -1;
25+
});
2326
var piskelStyles = require('./src/piskel-style-list.js').styles.map(mapToSrcFolder);
2427

25-
var getGhostConfig = function (delay) {
28+
var mapToCasperFolder = function (path) {
29+
return "test/casperjs/" + path;
30+
};
31+
32+
var casperEnvironments = {
33+
'local' : {
34+
suite : './test/casperjs/LocalTestSuite.js',
35+
delay : 50
36+
},
37+
'travis' : {
38+
suite : './test/casperjs/TravisTestSuite.js',
39+
delay : 5000
40+
}
41+
};
42+
43+
var getCasperConfig = function (env) {
44+
var conf = casperEnvironments[env];
45+
var tests = require(conf.suite).tests.map(mapToCasperFolder);
2646
return {
27-
filesSrc : ['test/integration/casperjs/*_test.js'],
47+
filesSrc : tests,
2848
options : {
2949
args : {
30-
baseUrl : 'http://localhost:' + '<%= connect.test.options.port %>/src/',
50+
baseUrl : 'http://localhost:' + '<%= express.test.options.port %>/',
3151
mode : '?debug',
32-
delay : delay
52+
delay : conf.delay
3353
},
54+
async : false,
3455
direct : false,
3556
logLevel : 'info',
3657
printCommand : false,
@@ -39,6 +60,23 @@ module.exports = function(grunt) {
3960
};
4061
};
4162

63+
var getExpressConfig = function (source, port, host) {
64+
var bases;
65+
if (typeof source === 'string') {
66+
bases = [source];
67+
} else if (Array.isArray(source)) {
68+
bases = source;
69+
}
70+
71+
return {
72+
options: {
73+
port: port,
74+
hostname : host || 'localhost',
75+
bases: bases
76+
}
77+
};
78+
};
79+
4280
grunt.initConfig({
4381
clean: {
4482
before: ['dest'],
@@ -62,29 +100,10 @@ module.exports = function(grunt) {
62100
'!src/js/lib/**/*.js' // Exclude lib folder (note the leading !)
63101
]
64102
},
65-
connect : {
66-
test : {
67-
options : {
68-
base : '.',
69-
port : 4321
70-
}
71-
}
72-
},
73103
express: {
74-
regular: {
75-
options: {
76-
port: 9001,
77-
hostname : 'localhost',
78-
bases: ['dest']
79-
}
80-
},
81-
debug: {
82-
options: {
83-
port: 9901,
84-
hostname : 'localhost',
85-
bases: ['src']
86-
}
87-
}
104+
test: getExpressConfig(['src', 'test'], 9991),
105+
regular: getExpressConfig('dest', 9001),
106+
debug: getExpressConfig(['src', 'test'], 9901)
88107
},
89108
open : {
90109
regular : {
@@ -105,8 +124,8 @@ module.exports = function(grunt) {
105124
}
106125
},
107126
ghost : {
108-
'default' : getGhostConfig(5000),
109-
local : getGhostConfig(50)
127+
'travis' : getCasperConfig('travis'),
128+
'local' : getCasperConfig('local')
110129
},
111130
concat : {
112131
js : {
@@ -236,6 +255,11 @@ module.exports = function(grunt) {
236255
dest: 'build/closure/closure_compiled_binary.js'
237256
}
238257
},
258+
karma: {
259+
unit: {
260+
configFile: 'karma.conf.js'
261+
}
262+
},
239263
nodewebkit: {
240264
options: {
241265
build_dir: './dest/desktop/', // destination folder of releases.
@@ -262,7 +286,6 @@ module.exports = function(grunt) {
262286
grunt.loadNpmTasks('grunt-closure-tools');
263287
grunt.loadNpmTasks('grunt-contrib-clean');
264288
grunt.loadNpmTasks('grunt-contrib-concat');
265-
grunt.loadNpmTasks('grunt-contrib-connect');
266289
grunt.loadNpmTasks('grunt-contrib-copy');
267290
grunt.loadNpmTasks('grunt-contrib-jshint');
268291
grunt.loadNpmTasks('grunt-contrib-uglify');
@@ -271,18 +294,25 @@ module.exports = function(grunt) {
271294
grunt.loadNpmTasks('grunt-replace');
272295
grunt.loadNpmTasks('grunt-ghost');
273296
grunt.loadNpmTasks('grunt-open');
297+
grunt.loadNpmTasks('grunt-karma');
274298
grunt.loadNpmTasks('grunt-leading-indent');
275299
grunt.loadNpmTasks('grunt-node-webkit-builder');
276300
grunt.loadNpmTasks('grunt-contrib-copy');
277301

278302
// Validate
279303
grunt.registerTask('lint', ['leadingIndent:jsFiles', 'leadingIndent:cssFiles', 'jshint']);
280304

281-
// Validate & Test
282-
grunt.registerTask('test', ['lint', 'compile', 'connect:test', 'ghost:default']);
305+
// karma/unit-tests task
306+
grunt.registerTask('unit-test', ['karma']);
283307

308+
// Validate & Test
309+
grunt.registerTask('test-travis', ['lint', 'compile', 'unit-test', 'express:test', 'ghost:travis']);
284310
// Validate & Test (faster version) will NOT work on travis !!
285-
grunt.registerTask('precommit', ['lint', 'compile', 'connect:test', 'ghost:local']);
311+
grunt.registerTask('test-local', ['lint', 'compile', 'unit-test', 'express:test', 'ghost:local']);
312+
313+
grunt.registerTask('test', ['test-travis']);
314+
grunt.registerTask('precommit', ['test-local']);
315+
286316

287317
// Compile JS code (eg verify JSDoc annotation and types, no actual minified code generated).
288318
grunt.registerTask('compile', ['closureCompiler:compile', 'clean:after']);

karma.conf.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Karma configuration
2+
// Generated on Tue Jul 22 2014 23:49:26 GMT+0200 (Romance Daylight Time)
3+
4+
module.exports = function(config) {
5+
6+
var mapToSrcFolder = function (path) {return ['src', path].join('/');};
7+
8+
var piskelScripts = require('./src/piskel-script-list.js').scripts.map(mapToSrcFolder);
9+
piskelScripts.push('test/js/**/*.js');
10+
config.set({
11+
12+
// base path that will be used to resolve all patterns (eg. files, exclude)
13+
basePath: '',
14+
15+
16+
// frameworks to use
17+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
18+
frameworks: ['jasmine'],
19+
20+
21+
// list of files / patterns to load in the browser
22+
files: piskelScripts,
23+
24+
25+
// list of files to exclude
26+
exclude: [],
27+
28+
29+
// preprocess matching files before serving them to the browser
30+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
31+
preprocessors: {
32+
},
33+
34+
35+
// test results reporter to use
36+
// possible values: 'dots', 'progress'
37+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
38+
reporters: ['progress'],
39+
40+
41+
// web server port
42+
port: 9876,
43+
44+
45+
// enable / disable colors in the output (reporters and logs)
46+
colors: true,
47+
48+
49+
// level of logging
50+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
51+
logLevel: config.LOG_INFO,
52+
53+
54+
// enable / disable watching file and executing tests whenever any file changes
55+
autoWatch: true,
56+
57+
58+
// start these browsers
59+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
60+
browsers: ['PhantomJS'],
61+
62+
63+
// Continuous Integration mode
64+
// if true, Karma captures browsers, runs the tests and exits
65+
singleRun: true
66+
});
67+
};

misc/scripts/package-windows-executable.cmd

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,14 @@ SETLOCAL
1212
set APP_BIN="%PISKEL_HOME%\dest\desktop\cache\win\0.9.2"
1313
set MISC_FOLDER=%PISKEL_HOME%\misc
1414
set RELEASES_FOLDER=%PISKEL_HOME%\dest\desktop\releases
15-
set DEST_FOLDER=%RELEASES_FOLDER%\win
15+
set DEST_FOLDER=%RELEASES_FOLDER%\piskel\win\piskel
1616

17-
ECHO "Building Piskel executable for Windows ..."
18-
19-
ECHO "Creating release directory ..."
20-
MKDIR "%DEST_FOLDER%"
21-
ECHO "DONE"
22-
23-
ECHO "Packaging executable ..."
24-
COPY /b "%APP_BIN%\nw.exe"+"%RELEASES_FOLDER%\piskel\piskel.nw" "%DEST_FOLDER%\piskel-raw.exe"
25-
ECHO "DONE"
26-
27-
ECHO "COPYing dependencies ..."
28-
COPY "%APP_BIN%\*.dll" "%DEST_FOLDER%\"
29-
COPY "%APP_BIN%\nw.pak" "%DEST_FOLDER%\"
30-
ECHO "DONE"
3117

3218
ECHO "Updating Piskel icon -- Using Resource Hacker"
33-
%RESOURCE_HACKER_PATH%\ResHacker -addoverwrite "%DEST_FOLDER%\piskel-raw.exe", "%DEST_FOLDER%\piskel-exploded.exe", "%MISC_FOLDER%\desktop\logo.ico", ICONGROUP, IDR_MAINFRAME, 1033
34-
DEL "%DEST_FOLDER%\piskel-raw.exe"
19+
%RESOURCE_HACKER_PATH%\ResHacker -addoverwrite "%DEST_FOLDER%\piskel.exe", "%DEST_FOLDER%\piskel-logo.exe", "%MISC_FOLDER%\desktop\logo.ico", ICONGROUP, IDR_MAINFRAME, 1033
20+
DEL "%DEST_FOLDER%\piskel.exe"
3521
ECHO "DONE"
3622

37-
ECHO "Boxing application to single file -- Using Enigma Virtual Box"
38-
%VBOX_PATH%\enigmavbconsole "%MISC_FOLDER%\desktop\package-piskel.evb"
39-
DEL "%DEST_FOLDER%\*.dll"
40-
DEL "%DEST_FOLDER%\nw.pak"
41-
DEL "%DEST_FOLDER%\piskel-exploded.exe"
42-
ECHO "DONE"
4323

4424
PAUSE
4525
explorer "%DEST_FOLDER%\"

package.json

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "piskel",
44
"main": "./dest/index.html",
55
"description": "Web based 2d animations editor",
6-
"version": "0.1.0",
6+
"version": "0.2.0",
77
"homepage": "http://github.com/juliandescottes/piskel",
88
"repository": {
99
"type": "git",
@@ -14,23 +14,27 @@
1414
"start": "nodewebkit"
1515
},
1616
"devDependencies": {
17-
"grunt": "~0.4.1",
17+
"dateformat": "1.0.8-1.2.3",
18+
"grunt": "~0.4.5",
19+
"grunt-closure-tools": "~0.9.7",
1820
"grunt-contrib-clean": "0.5.0",
19-
"grunt-contrib-connect": "0.3.0",
20-
"grunt-contrib-concat": "0.1.2",
21+
"grunt-contrib-concat": "0.5.0",
2122
"grunt-contrib-copy": "0.5.0",
22-
"grunt-contrib-jshint": "0.5.4",
23-
"grunt-contrib-uglify": "0.2.2",
23+
"grunt-contrib-jshint": "0.10.0",
24+
"grunt-contrib-uglify": "0.5.0",
2425
"grunt-contrib-watch": "0.6.1",
25-
"grunt-express": "1.0",
26-
"grunt-replace": "0.7.8",
27-
"grunt-ghost": "1.0.12",
28-
"grunt-open": "0.2.3",
26+
"grunt-express": "1.4.1",
27+
"grunt-ghost": "1.1.0",
2928
"grunt-leading-indent": "0.1.0",
30-
"grunt-closure-tools": "~0.8.3",
31-
"grunt-node-webkit-builder": "0.1.19",
32-
"nodewebkit": "0.8.4",
33-
"dateformat" : "1.0.8-1.2.3"
29+
"grunt-node-webkit-builder": "0.1.21",
30+
"grunt-open": "0.2.3",
31+
"grunt-replace": "0.7.8",
32+
"grunt-karma": "~0.8.2",
33+
"karma": "0.12.17",
34+
"karma-chrome-launcher": "^0.1.4",
35+
"karma-phantomjs-launcher": "^0.1.4",
36+
"karma-jasmine": "^0.1.5",
37+
"nodewebkit": "~0.10.1"
3438
},
3539
"window": {
3640
"title": "Piskel",

src/js/Constants.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,8 @@ var Constants = {
6969
MOUSEMOVE_THROTTLING : 10,
7070

7171
ABSTRACT_FUNCTION : function () {throw 'abstract method should be implemented';},
72-
EMPTY_FUNCTION : function () {}
72+
EMPTY_FUNCTION : function () {},
73+
74+
// TESTS
75+
DRAWING_TEST_FOLDER : 'drawing'
7376
};

src/js/Events.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
var Events = {
33

44
TOOL_SELECTED : "TOOL_SELECTED",
5+
SELECT_TOOL : "SELECT_TOOL",
6+
57
TOOL_RELEASED : "TOOL_RELEASED",
68
SELECT_PRIMARY_COLOR: "SELECT_PRIMARY_COLOR",
79
SELECT_SECONDARY_COLOR: "SELECT_SECONDARY_COLOR",
@@ -47,5 +49,12 @@ var Events = {
4749

4850
ZOOM_CHANGED : "ZOOM_CHANGED",
4951

50-
CURRENT_COLORS_UPDATED : "CURRENT_COLORS_UPDATED"
52+
CURRENT_COLORS_UPDATED : "CURRENT_COLORS_UPDATED",
53+
54+
MOUSE_EVENT : "MOUSE_EVENT",
55+
56+
// Tests
57+
TEST_RECORD_END : "TEST_RECORD_END",
58+
TEST_CASE_END : "TEST_CASE_END",
59+
TEST_SUITE_END : "TEST_SUITE_END"
5160
};

0 commit comments

Comments
 (0)