From 63f6fcd0b7876b74f7d42f3c787a8fdb53a264e2 Mon Sep 17 00:00:00 2001
From: Winnie Hellmann <winnie@gitlab.com>
Date: Thu, 28 Mar 2019 13:38:29 +0100
Subject: [PATCH] Set gon.ee in Jest

---
 jest.config.js               | 13 ++++---------
 spec/frontend/environment.js |  6 ++++++
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/jest.config.js b/jest.config.js
index 4cdc16adc1647..c7518be9e96eb 100644
--- a/jest.config.js
+++ b/jest.config.js
@@ -1,12 +1,4 @@
-
-const fs = require('fs');
-const path = require('path');
-
-const ROOT_PATH = __dirname;
-const IS_EE =
-  process.env.EE !== undefined
-    ? JSON.parse(process.env.EE)
-    : fs.existsSync(path.join(ROOT_PATH, 'ee'));
+const IS_EE = require('./config/helpers/is_ee_env');
 
 const reporters = ['default'];
 
@@ -46,4 +38,7 @@ module.exports = {
   transformIgnorePatterns: ['node_modules/(?!(@gitlab/ui)/)'],
   timers: 'fake',
   testEnvironment: '<rootDir>/spec/frontend/environment.js',
+  testEnvironmentOptions: {
+    IS_EE,
+  },
 };
diff --git a/spec/frontend/environment.js b/spec/frontend/environment.js
index cb128c7d88098..1067a53906ace 100644
--- a/spec/frontend/environment.js
+++ b/spec/frontend/environment.js
@@ -6,6 +6,7 @@ const JSDOMEnvironment = require('jest-environment-jsdom');
 class CustomEnvironment extends JSDOMEnvironment {
   constructor(config, context) {
     super(config, context);
+
     Object.assign(context.console, {
       error(...args) {
         throw new ErrorWithStack(
@@ -21,6 +22,11 @@ class CustomEnvironment extends JSDOMEnvironment {
         );
       },
     });
+
+    const { testEnvironmentOptions } = config;
+    this.global.gon = {
+      ee: testEnvironmentOptions.IS_EE,
+    };
   }
 }
 
-- 
GitLab