chore: resurrect translation reporter
This restores the translation reporter that allows us to extract translations from the library, as we test it.
This commit is contained in:
parent
826d909d62
commit
3ff287266c
|
@ -8,6 +8,7 @@
|
||||||
"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",
|
||||||
|
"collect-translations": "COLLECT_TRANSLATIONS=1 npm test",
|
||||||
"test:distro": "node tasks/test-distro.js",
|
"test:distro": "node tasks/test-distro.js",
|
||||||
"preversion": "run-s distro test:distro"
|
"preversion": "run-s distro test:distro"
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
|
||||||
|
var collectTranslations = process.env.COLLECT_TRANSLATIONS;
|
||||||
|
|
||||||
var coverage = process.env.COVERAGE;
|
var coverage = process.env.COVERAGE;
|
||||||
|
|
||||||
// configures browsers to run test against
|
// configures browsers to run test against
|
||||||
|
@ -19,7 +21,8 @@ var suite = coverage ? 'test/coverageBundle.js' : 'test/testBundle.js';
|
||||||
|
|
||||||
|
|
||||||
module.exports = function(karma) {
|
module.exports = function(karma) {
|
||||||
karma.set({
|
|
||||||
|
var config = {
|
||||||
|
|
||||||
basePath,
|
basePath,
|
||||||
|
|
||||||
|
@ -86,5 +89,16 @@ module.exports = function(karma) {
|
||||||
},
|
},
|
||||||
devtool: 'eval-source-map'
|
devtool: 'eval-source-map'
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (collectTranslations) {
|
||||||
|
config.plugins = [].concat(config.plugins || [], 'karma-*', require('./translation-reporter'));
|
||||||
|
config.reporters = [].concat(config.reporters || [], 'translation-reporter');
|
||||||
|
|
||||||
|
config.envPreprocessor = [
|
||||||
|
'TRANSLATIONS'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
karma.set(config);
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,7 +10,7 @@ var {
|
||||||
function TranslationReporter() {
|
function TranslationReporter() {
|
||||||
process.env.TRANSLATIONS = 'enabled';
|
process.env.TRANSLATIONS = 'enabled';
|
||||||
|
|
||||||
var outputFile = path.join(__dirname, '../../docs/translations.json');
|
var translationsFile = path.join(__dirname, '../../docs/translations.json');
|
||||||
|
|
||||||
var translations = [];
|
var translations = [];
|
||||||
|
|
||||||
|
@ -38,10 +38,10 @@ function TranslationReporter() {
|
||||||
|
|
||||||
|
|
||||||
this.onRunComplete = function() {
|
this.onRunComplete = function() {
|
||||||
translations = uniqueBy(function(e) {return e;}, translations);
|
translations = uniqueBy(function(e) { return e; }, translations);
|
||||||
translations = sortBy(translations, function(e) {return e;});
|
translations = sortBy(translations, function(e) { return e; });
|
||||||
|
|
||||||
fs.writeFileSync(outputFile, JSON.stringify(translations, null, 2));
|
fs.writeFileSync(translationsFile, JSON.stringify(translations, null, 2));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,12 +39,22 @@ import {
|
||||||
import TestContainer from 'mocha-test-container-support';
|
import TestContainer from 'mocha-test-container-support';
|
||||||
|
|
||||||
import Modeler from '../../lib/Modeler';
|
import Modeler from '../../lib/Modeler';
|
||||||
|
import NavigatedViewer from '../../lib/NavigatedViewer';
|
||||||
import Viewer from '../../lib/Viewer';
|
import Viewer from '../../lib/Viewer';
|
||||||
|
|
||||||
var OPTIONS, BPMN_JS;
|
var OPTIONS, BPMN_JS;
|
||||||
|
|
||||||
import translationModule from './TranslationCollector';
|
import translationModule from './TranslationCollector';
|
||||||
|
|
||||||
|
export var collectTranslations = window.__env__ && window.__env__.TRANSLATIONS === 'enabled';
|
||||||
|
|
||||||
|
// inject logging translation module into default modules
|
||||||
|
if (collectTranslations) {
|
||||||
|
|
||||||
|
[ Modeler, Viewer, NavigatedViewer ].forEach(function(constructor) {
|
||||||
|
constructor.prototype._modules.push(translationModule);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function bootstrapBpmnJS(BpmnJS, diagram, options, locals) {
|
export function bootstrapBpmnJS(BpmnJS, diagram, options, locals) {
|
||||||
|
|
||||||
|
@ -105,7 +115,7 @@ export function bootstrapBpmnJS(BpmnJS, diagram, options, locals) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// used to extract translations used during tests
|
// used to extract translations used during tests
|
||||||
if (window.__env__ && window.__env__.TRANSLATIONS === 'enabled') {
|
if (collectTranslations) {
|
||||||
_options.additionalModules = [].concat(
|
_options.additionalModules = [].concat(
|
||||||
_options.additionalModules || [],
|
_options.additionalModules || [],
|
||||||
[ translationModule ]
|
[ translationModule ]
|
||||||
|
@ -278,4 +288,4 @@ export function insertCSS(name, css) {
|
||||||
}
|
}
|
||||||
|
|
||||||
head.appendChild(style);
|
head.appendChild(style);
|
||||||
}
|
}
|
|
@ -10,7 +10,8 @@ import {
|
||||||
|
|
||||||
import {
|
import {
|
||||||
setBpmnJS,
|
setBpmnJS,
|
||||||
clearBpmnJS
|
clearBpmnJS,
|
||||||
|
collectTranslations
|
||||||
} from 'test/TestHelper';
|
} from 'test/TestHelper';
|
||||||
|
|
||||||
|
|
||||||
|
@ -156,7 +157,7 @@ describe('Modeler', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('translate support', function() {
|
!collectTranslations && describe('translate support', function() {
|
||||||
|
|
||||||
var xml = require('../fixtures/bpmn/simple.bpmn');
|
var xml = require('../fixtures/bpmn/simple.bpmn');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue