Skip to content

Commit

Permalink
added testDemo to grunt test
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Aug 3, 2015
1 parent a88b3ba commit 08c5648
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 19 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'),
Expand Down
7 changes: 4 additions & 3 deletions demo/js/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
}

var Demo = {};
Matter.Demo = Demo;

var _engine,
_gui,
Expand All @@ -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

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions tests/browser/TestDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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');
}

Expand Down

0 comments on commit 08c5648

Please sign in to comment.