From aa9ac23e6ec7233c78d1c498ff4274010af26de3 Mon Sep 17 00:00:00 2001 From: Paul Slaughter <pslaughter@gitlab.com> Date: Thu, 14 May 2020 11:48:30 -0500 Subject: [PATCH] Fix eslint broken for Jest **What happened?** Previously we just checked the immediate parent to see if the module was being included from eslint. Now we recursively check all the parents. Also moves this eslint check to it's own config/helper --- config/helpers/is_eslint.js | 18 ++++++++++++++++++ jest.config.base.js | 5 ++--- 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 config/helpers/is_eslint.js diff --git a/config/helpers/is_eslint.js b/config/helpers/is_eslint.js new file mode 100644 index 000000000000..5dfb7e533e4d --- /dev/null +++ b/config/helpers/is_eslint.js @@ -0,0 +1,18 @@ +/** + * Returns true if the given module is required from eslint + */ +const isESLint = mod => { + let parent = mod.parent; + + while (parent) { + if (parent.filename.includes('/eslint')) { + return true; + } + + parent = parent.parent; + } + + return false; +}; + +module.exports = isESLint; diff --git a/jest.config.base.js b/jest.config.base.js index 15fa30752ed5..1a1fd4e7b620 100644 --- a/jest.config.base.js +++ b/jest.config.base.js @@ -1,4 +1,5 @@ const IS_EE = require('./config/helpers/is_ee_env'); +const isESLint = require('./config/helpers/is_eslint'); module.exports = path => { const reporters = ['default']; @@ -24,9 +25,7 @@ module.exports = path => { // workaround for eslint-import-resolver-jest only resolving in test files // see https://github.com/JoinColony/eslint-import-resolver-jest#note - const { filename: parentModuleName } = module.parent; - const isESLint = parentModuleName && parentModuleName.includes('/eslint-import-resolver-jest/'); - if (isESLint) { + if (isESLint(module)) { testMatch = testMatch.map(path => path.replace('_spec.js', '')); } -- GitLab