diff --git a/package/__tests__/development.js b/package/__tests__/development.js index bd1f1e8e1..0de25d672 100644 --- a/package/__tests__/development.js +++ b/package/__tests__/development.js @@ -6,6 +6,10 @@ const { chdirTestApp, chdirCwd } = require('../utils/helpers') chdirTestApp() describe('Development environment', () => { + beforeEach(() => { + jest.resetModules() + }) + afterAll(chdirCwd) describe('toWebpackConfig', () => { diff --git a/package/__tests__/production.js b/package/__tests__/production.js index 96f212817..9fcf57fe5 100644 --- a/package/__tests__/production.js +++ b/package/__tests__/production.js @@ -6,6 +6,10 @@ const { chdirTestApp, chdirCwd } = require('../utils/helpers') chdirTestApp() describe('Production environment', () => { + beforeEach(() => { + jest.resetModules(); + }) + afterAll(chdirCwd) describe('toWebpackConfig', () => { @@ -13,6 +17,7 @@ describe('Production environment', () => { test('should use production config and environment', () => { process.env.RAILS_ENV = 'production' + process.env.NODE_ENV = 'production' const { environment } = require('../index') const config = environment.toWebpackConfig() diff --git a/package/__tests__/staging.js b/package/__tests__/staging.js index 794e61553..d7a39326d 100644 --- a/package/__tests__/staging.js +++ b/package/__tests__/staging.js @@ -6,6 +6,10 @@ const { chdirTestApp, chdirCwd } = require('../utils/helpers') chdirTestApp() describe('Custom environment', () => { + beforeEach(() => { + jest.resetModules() + }) + afterAll(chdirCwd) describe('toWebpackConfig', () => { @@ -13,6 +17,7 @@ describe('Custom environment', () => { test('should use staging config and production environment', () => { process.env.RAILS_ENV = 'staging' + process.env.NODE_ENV = 'staging' const { environment } = require('../index') const config = environment.toWebpackConfig() diff --git a/package/__tests__/test.js b/package/__tests__/test.js index 4fa6cbff0..af5ff9ae1 100644 --- a/package/__tests__/test.js +++ b/package/__tests__/test.js @@ -6,6 +6,10 @@ const { chdirTestApp, chdirCwd } = require('../utils/helpers') chdirTestApp() describe('Test environment', () => { + beforeEach(() => { + jest.resetModules() + }) + afterAll(chdirCwd) describe('toWebpackConfig', () => { @@ -13,6 +17,7 @@ describe('Test environment', () => { test('should use test config and production environment', () => { process.env.RAILS_ENV = 'test' + process.env.NODE_ENV = 'test' const { environment } = require('../index') const config = environment.toWebpackConfig() diff --git a/package/env.js b/package/env.js index 494922d62..ae7181690 100644 --- a/package/env.js +++ b/package/env.js @@ -2,7 +2,7 @@ const { resolve } = require('path') const { safeLoad } = require('js-yaml') const { readFileSync } = require('fs') -const NODE_ENVIRONMENTS = ['development', 'production'] +const NODE_ENVIRONMENTS = ['development', 'test', 'production'] const DEFAULT = 'production' const configPath = resolve('config', 'webpacker.yml')