1- const { chdirTestApp } = require ( "../helpers" )
1+ const { chdirTestApp, resetEnv } = require ( "../helpers" )
22
33const rootPath = process . cwd ( )
44chdirTestApp ( )
55
6- const envKeys = [
7- "NODE_ENV" ,
8- "RAILS_ENV" ,
9- "SHAKAPACKER_DEV_SERVER_HOST" ,
10- "SHAKAPACKER_DEV_SERVER_PORT" ,
11- "SHAKAPACKER_DEV_SERVER_DISABLE_HOST_CHECK" ,
12- "TEST_SHAKAPACKER_DEV_SERVER_HOST" ,
13- "TEST_SHAKAPACKER_DEV_SERVER_PORT"
14- ]
15-
166describe ( "DevServer" , ( ) => {
17- let originalEnv
18-
197 beforeEach ( ( ) => {
20- originalEnv = Object . fromEntries (
21- envKeys . map ( ( key ) => [ key , process . env [ key ] ] )
22- )
238 jest . resetModules ( )
24- } )
25-
26- afterEach ( ( ) => {
27- envKeys . forEach ( ( key ) => {
28- if ( originalEnv [ key ] === undefined ) {
29- delete process . env [ key ]
30- } else {
31- process . env [ key ] = originalEnv [ key ]
32- }
33- } )
9+ resetEnv ( )
3410 } )
3511
3612 afterAll ( ( ) => process . chdir ( rootPath ) )
@@ -39,8 +15,8 @@ describe("DevServer", () => {
3915 process . env . NODE_ENV = "development"
4016 process . env . RAILS_ENV = "development"
4117 process . env . SHAKAPACKER_DEV_SERVER_HOST = "0.0.0.0"
42- process . env . SHAKAPACKER_DEV_SERVER_PORT = 5000
43- process . env . SHAKAPACKER_DEV_SERVER_DISABLE_HOST_CHECK = false
18+ process . env . SHAKAPACKER_DEV_SERVER_PORT = " 5000"
19+ process . env . SHAKAPACKER_DEV_SERVER_DISABLE_HOST_CHECK = " false"
4420
4521 const devServer = require ( "../../package/dev_server" )
4622 expect ( devServer ) . toBeDefined ( )
@@ -50,15 +26,11 @@ describe("DevServer", () => {
5026 } )
5127
5228 test ( "with custom env prefix" , ( ) => {
53- // Set NODE_ENV/RAILS_ENV before requiring config: config resolves
54- // dev_server from shakapacker.yml at load time, and production has no
55- // dev_server section. Without this, a reordered run (e.g. --randomize)
56- // where the production test ran first leaks NODE_ENV=production here and
57- // config.dev_server is undefined.
29+ // NODE_ENV must precede require: config reads shakapacker.yml at load time; production has no dev_server.
5830 process . env . NODE_ENV = "development"
5931 process . env . RAILS_ENV = "development"
6032 process . env . TEST_SHAKAPACKER_DEV_SERVER_HOST = "0.0.0.0"
61- process . env . TEST_SHAKAPACKER_DEV_SERVER_PORT = 5000
33+ process . env . TEST_SHAKAPACKER_DEV_SERVER_PORT = " 5000"
6234
6335 const config = require ( "../../package/config" )
6436 config . dev_server . env_prefix = "TEST_SHAKAPACKER_DEV_SERVER"
0 commit comments