Enable babel for tests (#4564)

* Enable babel for tests

This enables babel for tests by using a mocha compiler
It uses the babel config from package.json
Transformed OptionsManager test to es2015 to see if it works
Removed the 5s timeout from cli tests, as the default timeout is already 10s, this should probably fix the timouts on travis that we had in babylon
Also run the cli tests on travis, they were disabled if istanbul active, but istanbul is always active on travis so we were never running this tests.

* ignore scripts directory

* only register for tests

* Set only flag correctly
This commit is contained in:
Daniel Tschinder 2016-10-12 10:56:50 +02:00 committed by GitHub
parent c2387f0444
commit 1dca51f8ab
6 changed files with 43 additions and 27 deletions

View File

@ -1,3 +1,5 @@
instrumentation: instrumentation:
root: . root: .
excludes: "**/node_modules/**" excludes:
- "**/node_modules/**"
- "scripts/*.js"

View File

@ -14,6 +14,7 @@
"babel-plugin-transform-runtime": "^6.3.13", "babel-plugin-transform-runtime": "^6.3.13",
"babel-preset-es2015": "^6.13.2", "babel-preset-es2015": "^6.13.2",
"babel-preset-stage-0": "^6.0.0", "babel-preset-stage-0": "^6.0.0",
"babel-register": "^6.14.0",
"babel-runtime": "^6.0.0", "babel-runtime": "^6.0.0",
"browserify": "^11.2.0", "browserify": "^11.2.0",
"bundle-collapser": "^1.2.1", "bundle-collapser": "^1.2.1",

View File

@ -1,5 +1,3 @@
if (process.env.running_under_istanbul) return;
var readdir = require("fs-readdir-recursive"); var readdir = require("fs-readdir-recursive");
var helper = require("babel-helper-fixtures"); var helper = require("babel-helper-fixtures");
var assert = require("assert"); var assert = require("assert");
@ -79,7 +77,6 @@ var buildTest = function (binName, testName, opts) {
var binLoc = path.join(__dirname, "../lib", binName); var binLoc = path.join(__dirname, "../lib", binName);
return function (callback) { return function (callback) {
this.timeout(5000);
clear(); clear();
saveInFiles(opts.inFiles); saveInFiles(opts.inFiles);

View File

@ -1,29 +1,22 @@
var assert = require("assert"); import assert from "assert";
var OptionManager = require("../lib/transformation/file/options/option-manager"); import OptionManager from "../lib/transformation/file/options/option-manager";
var Logger = require("../lib/transformation/file/logger"); import Logger from "../lib/transformation/file/logger";
var path = require("path"); import path from "path";
suite("option-manager", function () { suite("option-manager", () => {
suite("memoisePluginContainer", function () { suite("memoisePluginContainer", () => {
test("throws for babel 5 plugin", function() { test("throws for babel 5 plugin", () => {
return assert.throws( return assert.throws(
function () { () => OptionManager.memoisePluginContainer(({ Plugin }) => new Plugin("object-assign", {})),
OptionManager.memoisePluginContainer(
function (ref) {
var Plugin = ref.Plugin;
return new Plugin("object-assign", {});
}
);
},
/Babel 5 plugin is being run with Babel 6/ /Babel 5 plugin is being run with Babel 6/
); );
}) })
}); });
suite("mergeOptions", function () { suite("mergeOptions", () => {
test("throws for removed babel 5 options", function() { test("throws for removed babel 5 options", () => {
return assert.throws( return assert.throws(
function () { () => {
var opt = new OptionManager(new Logger(null, "unknown")); var opt = new OptionManager(new Logger(null, "unknown"));
opt.init({ opt.init({
'randomOption': true 'randomOption': true
@ -33,9 +26,9 @@ suite("option-manager", function () {
); );
}); });
test("throws for removed babel 5 options", function() { test("throws for removed babel 5 options", () => {
return assert.throws( return assert.throws(
function () { () => {
var opt = new OptionManager(new Logger(null, "unknown")); var opt = new OptionManager(new Logger(null, "unknown"));
opt.init({ opt.init({
'auxiliaryComment': true, 'auxiliaryComment': true,
@ -46,9 +39,9 @@ suite("option-manager", function () {
); );
}); });
test("throws for resolved but erroring preset", function() { test("throws for resolved but erroring preset", () => {
return assert.throws( return assert.throws(
function () { () => {
var opt = new OptionManager(new Logger(null, "unknown")); var opt = new OptionManager(new Logger(null, "unknown"));
opt.init({ opt.init({
'presets': [path.join(__dirname, "fixtures/option-manager/not-a-preset")] 'presets': [path.join(__dirname, "fixtures/option-manager/not-a-preset")]

23
scripts/babel-register.js Normal file
View File

@ -0,0 +1,23 @@
var babel = require("../package.json").babel;
var register = require("babel-register");
var path = require("path");
if (babel.plugins) {
// correct path of relative plugins
babel.plugins = babel.plugins.map(function (plugin) {
if (plugin.charAt(0) === '.') {
return plugin.replace(/^\./, path.join(__dirname, '..'));
}
return plugin;
});
}
register(babel);
register({
extensions: [".js"],
// Only js files in the test folder but not in the subfolder fixtures.
only: /packages\/.+\/test\/(?!fixtures\/).+\.js$/,
babelrc: false,
compact: true,
});

View File

@ -1 +1 @@
--reporter dot --ui tdd --timeout 10000 --reporter dot --ui tdd --timeout 10000 --compilers js:./scripts/babel-register