0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-17 12:42:17 -05:00

added testDemo to grunt test

This commit is contained in:
liabru 2015-08-04 00:37:40 +01:00
parent a88b3badf5
commit 08c5648bb9
5 changed files with 33 additions and 14 deletions

3
.gitignore vendored
View file

@ -6,5 +6,4 @@ matter-doc-theme
build/matter-dev.js
build/matter-dev.min.js
demo/js/lib/matter-dev.js
tests/browser/diffs
tests/browser/worlds
tests/browser/diffs

View file

@ -3,4 +3,5 @@ node_js:
- "0.10"
before_install: npm install -g grunt-cli
install: npm install
before_script: grunt
before_script:
- grunt dev

View file

@ -109,8 +109,11 @@ module.exports = function(grunt) {
}
},
shell: {
testBrowser: {
command: 'phantomjs tests/browser/TestDemo.js',
testDemo: {
command: function(arg) {
arg = arg ? ' --' + arg : '';
return 'phantomjs tests/browser/TestDemo.js' + arg;
},
options: {
execOptions: {
timeout: 1000 * 60
@ -131,10 +134,22 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-shell');
grunt.registerTask('default', ['test', 'build']);
grunt.registerTask('test', ['jshint']);
grunt.registerTask('testBrowser', ['shell:testBrowser']);
grunt.registerTask('test', ['jshint', 'testDemo']);
grunt.registerTask('dev', ['build:dev', 'connect:watch', 'watch']);
grunt.registerTask('testDemo', function() {
var updateAll = grunt.option('updateAll'),
diff = grunt.option('diff');
if (updateAll) {
grunt.task.run('shell:testDemo:updateAll');
} else if (diff) {
grunt.task.run('shell:testDemo:diff');
} else {
grunt.task.run('shell:testDemo');
}
});
grunt.registerTask('build', function(mode) {
var isDev = (mode === 'dev'),
isRelease = (mode === 'release'),

View file

@ -25,6 +25,7 @@
}
var Demo = {};
Matter.Demo = Demo;
var _engine,
_gui,
@ -34,8 +35,6 @@
_sceneEvents = [],
_useInspector = window.location.hash.indexOf('-inspect') !== -1,
_isMobile = /(ipad|iphone|ipod|android)/gi.test(navigator.userAgent);
window.Matter.Demo = Demo;
// initialise the demo
@ -53,7 +52,6 @@
// create a Matter engine
// NOTE: this is actually Matter.Engine.create(), see the aliases at top of this file
_engine = Engine.create(container, options);
window.Matter.Demo._engine = _engine;
// add a mouse controlled constraint
_mouseConstraint = MouseConstraint.create(_engine);
@ -1611,6 +1609,9 @@
var demoSelect = document.getElementById('demo-select'),
demoReset = document.getElementById('demo-reset');
// engine reference for external use
Matter.Demo._engine = _engine;
// create a Matter.Gui
if (!_isMobile && Gui) {
_gui = Gui.create(_engine);

View file

@ -53,6 +53,9 @@ var test = function(status) {
var worldStart = page.evaluate(function(demo) {
var engine = Matter.Demo._engine;
Matter.Runner.stop(engine);
if (!(demo in Matter.Demo)) {
throw '\'' + demo + '\' is not defined in Matter.Demo';
}
Matter.Demo[demo]();
return engine.world;
}, demo);
@ -71,7 +74,7 @@ var test = function(status) {
if (fs.exists(worldStartPath)) {
var worldStartRef = resurrect.resurrect(fs.read(worldStartPath));
var worldStartDiff = compare(worldStart, worldStartRef);
var worldStartDiff = compare(worldStartRef, worldStart);
if (worldStartDiff.length !== 0) {
if (diff) {
@ -92,7 +95,7 @@ var test = function(status) {
if (fs.exists(worldEndPath)) {
var worldEndRef = resurrect.resurrect(fs.read(worldEndPath));
var worldEndDiff = compare(worldEnd, worldEndRef);
var worldEndDiff = compare(worldEndRef, worldEnd);
if (worldEndDiff.length !== 0) {
if (diff) {
@ -133,9 +136,9 @@ var test = function(status) {
if (isOk) {
console.log('ok');
} else {
console.log('changes detected on:');
console.log('\nchanges detected on:');
console.log(changed.join(', '));
console.log('review, then --update [name] or --updateAll');
console.log('\nreview, then --update [name] or --updateAll');
console.log('use --diff for diff log');
}