From 159d6845a025a6cca3118a647295ac57093b3c3f Mon Sep 17 00:00:00 2001 From: Daniel Castellon Date: Thu, 25 Oct 2018 15:43:34 -0400 Subject: [PATCH 1/3] fix: Import Babel config from package.json and export in babel.config.js so that tests in custom plugins w/ package.json files work --- babel.config.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 babel.config.js diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 00000000000..75a4414580e --- /dev/null +++ b/babel.config.js @@ -0,0 +1,19 @@ +const fs = require("fs"); + +/** + * @summary Babel 7 doesn't transpile files in sub-directories that have a package.json when Babel is configured + * through package.json or .babelrc. This causes Jest test failures in custom plugins that have a package.json. It + * isn't an issue with non-test files because those are imported through the main Reaction app (see /server/plugins.js + * and client/plugins.js). Babel does transpile these files when it is configured through the new babel.config.js. + * Meteor currently only loads Babel config through .babelrc or package.json. So, in order to support Babel transpiling + * of Jest tests, we load the babel config defined in package.json and export it here. + * See this Github comment: https://github.com/facebook/jest/issues/6053#issuecomment-383632515 + */ +module.exports = function(api) { + api.cache(false); + + const file = fs.readFileSync("./package.json"); + const packageJSON = JSON.parse(file); + + return packageJSON.babel; +} From 7bcb4ec1fbca9f273379b4598383a31710a3647c Mon Sep 17 00:00:00 2001 From: Daniel Castellon Date: Thu, 25 Oct 2018 15:49:25 -0400 Subject: [PATCH 2/3] chore: fix eslint issue --- babel.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/babel.config.js b/babel.config.js index 75a4414580e..e50f65fceac 100644 --- a/babel.config.js +++ b/babel.config.js @@ -9,11 +9,11 @@ const fs = require("fs"); * of Jest tests, we load the babel config defined in package.json and export it here. * See this Github comment: https://github.com/facebook/jest/issues/6053#issuecomment-383632515 */ -module.exports = function(api) { +module.exports = function (api) { api.cache(false); const file = fs.readFileSync("./package.json"); const packageJSON = JSON.parse(file); return packageJSON.babel; -} +}; From dd143732f59505c8fd13ab8062e11d5bd4cd416b Mon Sep 17 00:00:00 2001 From: Daniel Castellon Date: Thu, 25 Oct 2018 17:34:38 -0400 Subject: [PATCH 3/3] chore: add more comments around 2 babel configs --- babel.config.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/babel.config.js b/babel.config.js index e50f65fceac..9f907cc132e 100644 --- a/babel.config.js +++ b/babel.config.js @@ -12,6 +12,11 @@ const fs = require("fs"); module.exports = function (api) { api.cache(false); + /** + * Meteor only reads the babel config from .babelrc or package.json. So with just babel.config.js, + * the Meteor app fails but the Jest tests pass. With just package.json, the Jest tests in custom plugins + * fail but the app runs. + */ const file = fs.readFileSync("./package.json"); const packageJSON = JSON.parse(file);