From 5b2b05323089ac03d49107bf6dc54219a6b1c102 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Mon, 8 Jan 2018 11:02:44 +0100 Subject: [PATCH] chore(distro): add integration test Add a test that ensures the distribution works. Related to #725 --- package-lock.json | 23 +++++++-- package.json | 6 ++- tasks/test-distro.js | 43 +++++++++++++++++ test/config/karma.distro.js | 70 ++++++++++++++++++++++++++++ test/config/karma.unit.js | 4 +- test/distro/bpmn-modeler.js | 38 +++++++++++++++ test/distro/bpmn-navigated-viewer.js | 34 ++++++++++++++ test/distro/bpmn-viewer.js | 25 ++++++++++ test/distro/helper.js | 47 +++++++++++++++++++ 9 files changed, 283 insertions(+), 7 deletions(-) create mode 100644 tasks/test-distro.js create mode 100644 test/config/karma.distro.js create mode 100644 test/distro/bpmn-modeler.js create mode 100644 test/distro/bpmn-navigated-viewer.js create mode 100644 test/distro/bpmn-viewer.js create mode 100644 test/distro/helper.js diff --git a/package-lock.json b/package-lock.json index a204ecc7..447c65e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2516,9 +2516,9 @@ } }, "execa": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/execa/-/execa-0.7.0.tgz", - "integrity": "sha1-lEvs00zEHuMqY6n68nrVpl/Fl3c=", + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-0.8.0.tgz", + "integrity": "sha1-2NdrvBtVIX7RkP1t1J08d07PyNo=", "dev": true, "requires": { "cross-spawn": "5.1.0", @@ -6350,6 +6350,23 @@ "dev": true, "requires": { "execa": "0.7.0" + }, + "dependencies": { + "execa": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-0.7.0.tgz", + "integrity": "sha1-lEvs00zEHuMqY6n68nrVpl/Fl3c=", + "dev": true, + "requires": { + "cross-spawn": "5.1.0", + "get-stream": "3.0.0", + "is-stream": "1.1.0", + "npm-run-path": "2.0.2", + "p-finally": "1.0.0", + "signal-exit": "3.0.2", + "strip-eof": "1.0.0" + } + } } }, "text-encoding": { diff --git a/package.json b/package.json index 7aca7cac..dddbd3d5 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,13 @@ "version": "0.26.6", "description": "A bpmn 2.0 toolkit and web modeler", "scripts": { - "all": "run-s lint test distro", + "all": "run-s lint test distro test:distro", "lint": "eslint .", "dev": "npm test -- --auto-watch --no-single-run", "test": "karma start test/config/karma.unit.js", "distro": "node tasks/build-distro.js", - "prepublishOnly": "run-s distro" + "test:distro": "node tasks/test-distro.js", + "prepublishOnly": "run-s distro test:distro" }, "repository": { "type": "git", @@ -48,6 +49,7 @@ "envify": "^4.1.0", "eslint": "^4.14.0", "eslint-plugin-mocha": "^4.9.0", + "execa": "^0.8.0", "jsondiffpatch": "^0.1.26", "karma": "^1.7.0", "karma-browserify": "^5.1.1", diff --git a/tasks/test-distro.js b/tasks/test-distro.js new file mode 100644 index 00000000..bfdb953b --- /dev/null +++ b/tasks/test-distro.js @@ -0,0 +1,43 @@ +var execSync = require('execa').sync; + +var failures = 0; + +function runTest(variant, env) { + + var NODE_ENV = process.env.NODE_ENV; + + process.env.VARIANT = variant; + process.env.NODE_ENV = env; + + console.log(`[TEST] ${variant}@${env}`); + + try { + execSync('karma', [ 'start', 'test/config/karma.distro.js' ]); + } catch (e) { + console.error('[TEST] FAILURE'); + console.error(e); + + failures++; + } finally { + process.env.NODE_ENV = NODE_ENV; + } +} + +function test() { + + runTest('bpmn-modeler', 'development'); + runTest('bpmn-modeler', 'production'); + + runTest('bpmn-navigated-viewer', 'development'); + runTest('bpmn-navigated-viewer', 'production'); + + runTest('bpmn-viewer', 'development'); + runTest('bpmn-viewer', 'production'); + + if (failures) { + process.exit(1); + } +} + + +test(); \ No newline at end of file diff --git a/test/config/karma.distro.js b/test/config/karma.distro.js new file mode 100644 index 00000000..5ff4e820 --- /dev/null +++ b/test/config/karma.distro.js @@ -0,0 +1,70 @@ +'use strict'; + +/* global process */ + +// configures browsers to run test against +// any of [ 'ChromeHeadless', 'Chrome', 'Firefox', 'IE', 'PhantomJS' ] +var browsers = + (process.env.TEST_BROWSERS || 'PhantomJS') + .replace(/^\s+|\s+$/, '') + .split(/\s*,\s*/g) + .map(function(browser) { + if (browser === 'ChromeHeadless') { + process.env.CHROME_BIN = require('puppeteer').executablePath(); + + // workaround https://github.com/GoogleChrome/puppeteer/issues/290 + if (process.platform === 'linux') { + return 'ChromeHeadless_Linux'; + } + } else { + return browser; + } + }); + + +var VARIANT = process.env.VARIANT; + +var NODE_ENV = process.env.NODE_ENV; + +module.exports = function(karma) { + karma.set({ + + basePath: '../../', + + frameworks: [ + 'mocha', + 'sinon-chai' + ], + + files: [ + `dist/${VARIANT}.${NODE_ENV === 'production' ? 'production.min' : 'development'}.js`, + 'dist/assets/bpmn-font/css/bpmn.css', + 'dist/assets/diagram-js.css', + { pattern: 'resources/initial.bpmn', included: false }, + { pattern: 'dist/assets/**/*', included: false }, + 'test/distro/helper.js', + `test/distro/${VARIANT}.js` + ], + + reporters: [ 'spec' ], + + customLaunchers: { + ChromeHeadless_Linux: { + base: 'ChromeHeadless', + flags: [ + '--no-sandbox', + '--disable-setuid-sandbox' + ], + debug: true + } + }, + + browsers: browsers, + + browserNoActivityTimeout: 30000, + + singleRun: true, + autoWatch: false + }); + +}; diff --git a/test/config/karma.unit.js b/test/config/karma.unit.js index 4792a076..cf860e10 100644 --- a/test/config/karma.unit.js +++ b/test/config/karma.unit.js @@ -40,11 +40,11 @@ module.exports = function(karma) { ], files: [ - 'test/**/*Spec.js' + 'test/{spec,integration}/**/*Spec.js' ], preprocessors: { - 'test/**/*Spec.js': [ 'browserify', 'env' ] + 'test/{spec,integration}/**/*Spec.js': [ 'browserify', 'env' ] }, reporters: [ 'spec' ], diff --git a/test/distro/bpmn-modeler.js b/test/distro/bpmn-modeler.js new file mode 100644 index 00000000..dd67b0a7 --- /dev/null +++ b/test/distro/bpmn-modeler.js @@ -0,0 +1,38 @@ +'use strict'; + + +describe('bpmn-modeler', function() { + + it('should expose globals', function() { + + var BpmnJS = window.BpmnJS; + + // then + expect(BpmnJS).to.exist; + expect(new BpmnJS()).to.exist; + }); + + + it('should expose Viewer and NavigatedViewer', function() { + + var BpmnJS = window.BpmnJS; + + // then + expect(BpmnJS.NavigatedViewer).to.exist; + expect(new BpmnJS.NavigatedViewer()).to.exist; + + expect(BpmnJS.Viewer).to.exist; + expect(new BpmnJS.Viewer()).to.exist; + }); + + + it('should import initial diagram', function(done) { + + var BpmnJS = window.BpmnJS; + + // then + /* global testImport */ + testImport(BpmnJS, done); + }); + +}); \ No newline at end of file diff --git a/test/distro/bpmn-navigated-viewer.js b/test/distro/bpmn-navigated-viewer.js new file mode 100644 index 00000000..988d96c4 --- /dev/null +++ b/test/distro/bpmn-navigated-viewer.js @@ -0,0 +1,34 @@ +'use strict'; + + +describe('bpmn-navigated-viewer', function() { + + it('should expose globals', function() { + + var BpmnJS = window.BpmnJS; + + // then + expect(BpmnJS).to.exist; + expect(new BpmnJS()).to.exist; + }); + + + it('should expose Viewer', function() { + + var BpmnJS = window.BpmnJS; + + // then + expect(BpmnJS.Viewer).not.to.exist; + }); + + + it('should import initial diagram', function(done) { + + var BpmnJS = window.BpmnJS; + + // then + /* global testImport */ + testImport(BpmnJS, done); + }); + +}); \ No newline at end of file diff --git a/test/distro/bpmn-viewer.js b/test/distro/bpmn-viewer.js new file mode 100644 index 00000000..7b1ffd18 --- /dev/null +++ b/test/distro/bpmn-viewer.js @@ -0,0 +1,25 @@ +'use strict'; + + +describe('bpmn-navigated-viewer', function() { + + it('should expose globals', function() { + + var BpmnJS = window.BpmnJS; + + // then + expect(BpmnJS).to.exist; + expect(new BpmnJS()).to.exist; + }); + + + it('should import initial diagram', function(done) { + + var BpmnJS = window.BpmnJS; + + // then + /* global testImport */ + testImport(BpmnJS, done); + }); + +}); \ No newline at end of file diff --git a/test/distro/helper.js b/test/distro/helper.js new file mode 100644 index 00000000..8317018f --- /dev/null +++ b/test/distro/helper.js @@ -0,0 +1,47 @@ + +function testImport(BpmnJS, done) { + + var container = document.createElement('div'); + container.style.height = '500px'; + container.style.border = 'solid 1px #666'; + + document.body.appendChild(container); + + get('/base/resources/initial.bpmn', function(err, text) { + + if (err) { + return done(err); + } + + var modeler = new BpmnJS({ container: container }); + + modeler.importXML(text, function(err, warnings) { + return done(err, warnings, modeler); + }); + }); + +} + +function get(url, done) { + var httpRequest = new XMLHttpRequest(); + + if (!httpRequest) { + return done(new Error('cannot create XMLHttpRequest')); + } + + httpRequest.onreadystatechange = checkDone; + httpRequest.open('GET', url); + httpRequest.send(); + + function checkDone() { + if (httpRequest.readyState === XMLHttpRequest.DONE) { + if (httpRequest.status === 200) { + return done(null, httpRequest.responseText); + } else { + return done(new Error('status = ' + httpRequest.status), null, httpRequest); + } + } + } +} + +window.testImport = testImport; \ No newline at end of file