-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup and upgrade unit tests environment
`karma.conf.ci.js` have been merged into `karma.conf.js` for local testing consistency: `gulp unittestWatch` has been replaced by `gulp unittest --watch` and thus use exactly the same config file. Split `test/mockContext.js` into smaller `test/jasmine.*` modules to make easier unit tests maintenance. Upgrade to latest jasmine and karma packages and remove deprecated `gulp-karma` dependency (directly use `karma.Server` in gulp). Finally, move test files under the `test/specs` folder.
- Loading branch information
1 parent
5234899
commit f8d8890
Showing
39 changed files
with
431 additions
and
431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,33 @@ | ||
module.exports = function(config) { | ||
config.set({ | ||
browsers: ['Chrome', 'Firefox'], | ||
/* eslint camelcase: 0 */ | ||
|
||
module.exports = function(karma) { | ||
var config = { | ||
browsers: ['Firefox'], | ||
frameworks: ['browserify', 'jasmine'], | ||
reporters: ['progress', 'html'], | ||
reporters: ['progress', 'kjhtml'], | ||
|
||
preprocessors: { | ||
'src/**/*.js': ['browserify'] | ||
'./test/jasmine.index.js': ['browserify'], | ||
'./src/**/*.js': ['browserify'] | ||
}, | ||
|
||
browserify: { | ||
debug: true | ||
} | ||
}); | ||
}; | ||
}; | ||
|
||
// https://swizec.com/blog/how-to-run-javascript-tests-in-chrome-on-travis/swizec/6647 | ||
if (process.env.TRAVIS) { | ||
config.browsers.push('chrome_travis_ci'); | ||
config.customLaunchers = { | ||
chrome_travis_ci: { | ||
base: 'Chrome', | ||
flags: ['--no-sandbox'] | ||
} | ||
}; | ||
} else { | ||
config.browsers.push('Chrome'); | ||
} | ||
|
||
karma.set(config); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Code from http://stackoverflow.com/questions/4406864/html-canvas-unit-testing | ||
var Context = function() { | ||
this._calls = []; // names/args of recorded calls | ||
this._initMethods(); | ||
|
||
this._fillStyle = null; | ||
this._lineCap = null; | ||
this._lineDashOffset = null; | ||
this._lineJoin = null; | ||
this._lineWidth = null; | ||
this._strokeStyle = null; | ||
|
||
// Define properties here so that we can record each time they are set | ||
Object.defineProperties(this, { | ||
fillStyle: { | ||
get: function() { | ||
return this._fillStyle; | ||
}, | ||
set: function(style) { | ||
this._fillStyle = style; | ||
this.record('setFillStyle', [style]); | ||
} | ||
}, | ||
lineCap: { | ||
get: function() { | ||
return this._lineCap; | ||
}, | ||
set: function(cap) { | ||
this._lineCap = cap; | ||
this.record('setLineCap', [cap]); | ||
} | ||
}, | ||
lineDashOffset: { | ||
get: function() { | ||
return this._lineDashOffset; | ||
}, | ||
set: function(offset) { | ||
this._lineDashOffset = offset; | ||
this.record('setLineDashOffset', [offset]); | ||
} | ||
}, | ||
lineJoin: { | ||
get: function() { | ||
return this._lineJoin; | ||
}, | ||
set: function(join) { | ||
this._lineJoin = join; | ||
this.record('setLineJoin', [join]); | ||
} | ||
}, | ||
lineWidth: { | ||
get: function() { | ||
return this._lineWidth; | ||
}, | ||
set: function(width) { | ||
this._lineWidth = width; | ||
this.record('setLineWidth', [width]); | ||
} | ||
}, | ||
strokeStyle: { | ||
get: function() { | ||
return this._strokeStyle; | ||
}, | ||
set: function(style) { | ||
this._strokeStyle = style; | ||
this.record('setStrokeStyle', [style]); | ||
} | ||
}, | ||
}); | ||
}; | ||
|
||
Context.prototype._initMethods = function() { | ||
// define methods to test here | ||
// no way to introspect so we have to do some extra work :( | ||
var me = this; | ||
var methods = { | ||
arc: function() {}, | ||
beginPath: function() {}, | ||
bezierCurveTo: function() {}, | ||
clearRect: function() {}, | ||
closePath: function() {}, | ||
fill: function() {}, | ||
fillRect: function() {}, | ||
fillText: function() {}, | ||
lineTo: function() {}, | ||
measureText: function(text) { | ||
// return the number of characters * fixed size | ||
return text ? {width: text.length * 10} : {width: 0}; | ||
}, | ||
moveTo: function() {}, | ||
quadraticCurveTo: function() {}, | ||
restore: function() {}, | ||
rotate: function() {}, | ||
save: function() {}, | ||
setLineDash: function() {}, | ||
stroke: function() {}, | ||
strokeRect: function() {}, | ||
setTransform: function() {}, | ||
translate: function() {}, | ||
}; | ||
|
||
Object.keys(methods).forEach(function(name) { | ||
me[name] = function() { | ||
me.record(name, arguments); | ||
return methods[name].apply(me, arguments); | ||
}; | ||
}); | ||
}; | ||
|
||
Context.prototype.record = function(methodName, args) { | ||
this._calls.push({ | ||
name: methodName, | ||
args: Array.prototype.slice.call(args) | ||
}); | ||
}; | ||
|
||
Context.prototype.getCalls = function() { | ||
return this._calls; | ||
}; | ||
|
||
Context.prototype.resetCalls = function() { | ||
this._calls = []; | ||
}; | ||
|
||
module.exports = Context; |
Oops, something went wrong.