chore(distro): add integration test

Add a test that ensures the distribution works.

Related to #725
This commit is contained in:
Nico Rehwaldt 2018-01-08 11:02:44 +01:00 committed by Philipp Fromme
parent f1082a563f
commit 5b2b053230
9 changed files with 283 additions and 7 deletions

23
package-lock.json generated
View File

@ -2516,9 +2516,9 @@
} }
}, },
"execa": { "execa": {
"version": "0.7.0", "version": "0.8.0",
"resolved": "https://registry.npmjs.org/execa/-/execa-0.7.0.tgz", "resolved": "https://registry.npmjs.org/execa/-/execa-0.8.0.tgz",
"integrity": "sha1-lEvs00zEHuMqY6n68nrVpl/Fl3c=", "integrity": "sha1-2NdrvBtVIX7RkP1t1J08d07PyNo=",
"dev": true, "dev": true,
"requires": { "requires": {
"cross-spawn": "5.1.0", "cross-spawn": "5.1.0",
@ -6350,6 +6350,23 @@
"dev": true, "dev": true,
"requires": { "requires": {
"execa": "0.7.0" "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": { "text-encoding": {

View File

@ -3,12 +3,13 @@
"version": "0.26.6", "version": "0.26.6",
"description": "A bpmn 2.0 toolkit and web modeler", "description": "A bpmn 2.0 toolkit and web modeler",
"scripts": { "scripts": {
"all": "run-s lint test distro", "all": "run-s lint test distro test:distro",
"lint": "eslint .", "lint": "eslint .",
"dev": "npm test -- --auto-watch --no-single-run", "dev": "npm test -- --auto-watch --no-single-run",
"test": "karma start test/config/karma.unit.js", "test": "karma start test/config/karma.unit.js",
"distro": "node tasks/build-distro.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": { "repository": {
"type": "git", "type": "git",
@ -48,6 +49,7 @@
"envify": "^4.1.0", "envify": "^4.1.0",
"eslint": "^4.14.0", "eslint": "^4.14.0",
"eslint-plugin-mocha": "^4.9.0", "eslint-plugin-mocha": "^4.9.0",
"execa": "^0.8.0",
"jsondiffpatch": "^0.1.26", "jsondiffpatch": "^0.1.26",
"karma": "^1.7.0", "karma": "^1.7.0",
"karma-browserify": "^5.1.1", "karma-browserify": "^5.1.1",

43
tasks/test-distro.js Normal file
View File

@ -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();

View File

@ -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
});
};

View File

@ -40,11 +40,11 @@ module.exports = function(karma) {
], ],
files: [ files: [
'test/**/*Spec.js' 'test/{spec,integration}/**/*Spec.js'
], ],
preprocessors: { preprocessors: {
'test/**/*Spec.js': [ 'browserify', 'env' ] 'test/{spec,integration}/**/*Spec.js': [ 'browserify', 'env' ]
}, },
reporters: [ 'spec' ], reporters: [ 'spec' ],

View File

@ -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);
});
});

View File

@ -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);
});
});

View File

@ -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);
});
});

47
test/distro/helper.js Normal file
View File

@ -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;