From 08999f9d94b356407366270c6247350d14b3789c Mon Sep 17 00:00:00 2001 From: Kevin Grandon Date: Fri, 22 Dec 2017 22:52:44 -0800 Subject: [PATCH] Add __DEV__ to jest environment Fixes #90 --- build/jest-config.js | 3 +++ test/cli/test-app.js | 11 +++++++++++ .../test-jest-app/__tests__/environment-variables.js | 5 +++++ 3 files changed, 19 insertions(+) create mode 100644 test/fixtures/test-jest-app/__tests__/environment-variables.js diff --git a/build/jest-config.js b/build/jest-config.js index fec8ac37..493ffb71 100644 --- a/build/jest-config.js +++ b/build/jest-config.js @@ -3,8 +3,11 @@ module.exports = { cache: true, globals: { + // Parity with create-universal-package globals. + // https://github.com/rtsao/create-universal-package#globals __NODE__: process.env.JEST_ENV === 'node', __BROWSER__: process.env.JEST_ENV === 'jsdom', + __DEV__: process.env.NODE_ENV !== 'production', }, rootDir: process.cwd(), setupFiles: [ diff --git a/test/cli/test-app.js b/test/cli/test-app.js index 5c32c928..6bf77949 100644 --- a/test/cli/test-app.js +++ b/test/cli/test-app.js @@ -157,3 +157,14 @@ test('`fusion test-app` coverage', async t => { t.ok(response.stdout.includes('Uncovered Lines')); t.end(); }); + +test.only('`fusion test-app` environment variables', async t => { + const dir = path.resolve(__dirname, '../fixtures/test-jest-app'); + const args = `test-app --dir=${dir} --configPath=../../../build/jest-config.js --coverage --match=environment-variables`; + + const cmd = `require('${runnerPath}').run('${args}')`; + const response = await exec(`node -e "${cmd}"`); + t.equal(countTests(response.stderr), 2, 'ran 2 tests'); + + t.end(); +}); diff --git a/test/fixtures/test-jest-app/__tests__/environment-variables.js b/test/fixtures/test-jest-app/__tests__/environment-variables.js new file mode 100644 index 00000000..c45fb4e3 --- /dev/null +++ b/test/fixtures/test-jest-app/__tests__/environment-variables.js @@ -0,0 +1,5 @@ +import {test} from 'fusion-test-utils'; + +test('__DEV__ environment variable is set', assert => { + assert.equal(__DEV__, true); +});