diff --git a/.gitignore b/.gitignore index 6ec1a08..fece6cb 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file +tests/browser/diffs \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 4f411ab..422054b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,5 @@ node_js: - "0.10" before_install: npm install -g grunt-cli install: npm install -before_script: grunt \ No newline at end of file +before_script: + - grunt dev \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index 7b38f99..a22fee6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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'), diff --git a/demo/js/Demo.js b/demo/js/Demo.js index 8e75d60..00304ed 100644 --- a/demo/js/Demo.js +++ b/demo/js/Demo.js @@ -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); diff --git a/tests/browser/TestDemo.js b/tests/browser/TestDemo.js index 1f70c54..3a2dd02 100644 --- a/tests/browser/TestDemo.js +++ b/tests/browser/TestDemo.js @@ -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'); }