Skip to content

Commit

Permalink
Tools: Add ES transpile to karma setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
bre1470 committed Mar 17, 2019
1 parent 7f5cca6 commit c4ce6aa
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@
}
},
"devDependencies": {
"@babel/core": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"aws-sdk": "^2.388.0",
"babel-plugin-transform-es2015-arrow-functions": "^6.8.0",
"babel-runtime": "^6.20.0",
"browser-detect": "^0.2.28",
"browserify": "^12.0.2",
"closurecompiler": "^1.6.1",
"colors": "^1.3.3",
Expand Down
1 change: 1 addition & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ parserOptions:

rules:
no-undefined: 0
object-shorthand: 0
30 changes: 30 additions & 0 deletions test/karma-conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ const browserStackBrowsers = {
module.exports = function (config) {

const argv = require('yargs').argv;
const Babel = require("@babel/core");
const browserDetect = require('browser-detect');

// The tests to run by default
const defaultTests = [
Expand Down Expand Up @@ -331,6 +333,32 @@ module.exports = function (config) {
'$1/$2'
);

// es6 transpiling
const babelTarget = {};
const browser = 'ie'; // browserDetect(req.headers['user-agent']);
console.log(browser.name, browser.versionNumber);
switch (browser.name) {
case 'ie':
babelTarget.ie = '8';
break;
case 'safari':
if (browser.versionNumber < 10) {
babelTarget.safari = '5';
}
break;
}
if (Object.keys(babelTarget).length) {
let result = Babel.transformSync(js, {
ast: false,
presets: [[
'@babel/preset-env',
{ targets: babelTarget }
]]
});
js = result.code;
}

// unit tests
if (path.indexOf('unit-tests') !== -1) {
if (argv.debug) {
if (js.indexOf('Highcharts.setOptions') !== -1) {
Expand Down Expand Up @@ -478,7 +506,9 @@ module.exports = function (config) {
${reset}
});
`;

file.path = file.originalPath + '.preprocessed';

done(js);
}
}]
Expand Down
18 changes: 12 additions & 6 deletions test/test-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@
* The DOM element of the container
*/
function createContainer() {

var container = global.document.createElement('div'),
containerStyle = container.style;

containerStyle.left = '0';
containerStyle.position = 'absolute';
containerStyle.top = '0';

global.document.body.appendChild(container);

return container;
}

Expand All @@ -55,9 +59,11 @@
* The copy of the source.
*/
function treeCopy(source, propertiesTree) {

if (!source) {
return source;
}

switch (typeof source) {
default:
return source;
Expand Down Expand Up @@ -237,8 +243,8 @@
testInitializer = this.testInitializer;

this.testCases.push({
chartOptions,
testCallback
chartOptions: chartOptions,
testCallback: testCallback
});

if (!this.ready) {
Expand Down Expand Up @@ -327,10 +333,10 @@
}

templates[name] = {
name,
chartConstructor,
chartOptions,
testInitializer
name: name,
chartConstructor: chartConstructor,
chartOptions: chartOptions,
testInitializer: testInitializer
};

};
Expand Down

0 comments on commit c4ce6aa

Please sign in to comment.