|
| 1 | +/* eslint-env jest */ |
| 2 | +/* global jasmine */ |
| 3 | +import { join } from 'path' |
| 4 | +import { |
| 5 | + findPort, |
| 6 | + launchApp, |
| 7 | + killApp, |
| 8 | + waitFor, |
| 9 | + initNextServerScript, |
| 10 | +} from 'next-test-utils' |
| 11 | + |
| 12 | +jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 |
| 13 | + |
| 14 | +const appDir = join(__dirname, '..') |
| 15 | +const warningText = `You are using a non-standard "NODE_ENV" value in your environment` |
| 16 | + |
| 17 | +let appPort |
| 18 | +let app |
| 19 | + |
| 20 | +const startServer = async (optEnv = {}, opts) => { |
| 21 | + const scriptPath = join(appDir, 'server.js') |
| 22 | + appPort = appPort = await findPort() |
| 23 | + const env = Object.assign({}, process.env, { PORT: `${appPort}` }, optEnv) |
| 24 | + |
| 25 | + return initNextServerScript( |
| 26 | + scriptPath, |
| 27 | + /ready on/i, |
| 28 | + env, |
| 29 | + /ReferenceError: options is not defined/, |
| 30 | + opts |
| 31 | + ) |
| 32 | +} |
| 33 | + |
| 34 | +describe('Non-Standard NODE_ENV', () => { |
| 35 | + it('should not show the warning with no NODE_ENV set', async () => { |
| 36 | + let output = '' |
| 37 | + |
| 38 | + app = await launchApp(appDir, await findPort(), { |
| 39 | + onStdout(msg) { |
| 40 | + output += msg || '' |
| 41 | + }, |
| 42 | + }) |
| 43 | + await waitFor(2000) |
| 44 | + await killApp(app) |
| 45 | + expect(output).not.toContain(warningText) |
| 46 | + }) |
| 47 | + |
| 48 | + it('should not show the warning with NODE_ENV set to valid value', async () => { |
| 49 | + let output = '' |
| 50 | + |
| 51 | + app = await launchApp(appDir, await findPort(), { |
| 52 | + env: { |
| 53 | + NODE_ENV: 'development', |
| 54 | + }, |
| 55 | + onStdout(msg) { |
| 56 | + output += msg || '' |
| 57 | + }, |
| 58 | + }) |
| 59 | + await waitFor(2000) |
| 60 | + await killApp(app) |
| 61 | + expect(output).not.toContain(warningText) |
| 62 | + }) |
| 63 | + |
| 64 | + it('should not show the warning with NODE_ENV set to valid value (custom server)', async () => { |
| 65 | + let output = '' |
| 66 | + |
| 67 | + app = await startServer( |
| 68 | + { |
| 69 | + NODE_ENV: 'development', |
| 70 | + }, |
| 71 | + { |
| 72 | + onStdout(msg) { |
| 73 | + output += msg || '' |
| 74 | + }, |
| 75 | + } |
| 76 | + ) |
| 77 | + await waitFor(2000) |
| 78 | + await killApp(app) |
| 79 | + expect(output).not.toContain(warningText) |
| 80 | + }) |
| 81 | + |
| 82 | + it('should show the warning with NODE_ENV set to invalid value', async () => { |
| 83 | + let output = '' |
| 84 | + |
| 85 | + app = await launchApp(appDir, await findPort(), { |
| 86 | + env: { |
| 87 | + NODE_ENV: 'abc', |
| 88 | + }, |
| 89 | + onStdout(msg) { |
| 90 | + output += msg || '' |
| 91 | + }, |
| 92 | + }) |
| 93 | + await waitFor(2000) |
| 94 | + await killApp(app) |
| 95 | + expect(output).toContain(warningText) |
| 96 | + }) |
| 97 | + |
| 98 | + it('should show the warning with NODE_ENV set to invalid value (custom server)', async () => { |
| 99 | + let output = '' |
| 100 | + |
| 101 | + app = await startServer( |
| 102 | + { |
| 103 | + NODE_ENV: 'abc', |
| 104 | + }, |
| 105 | + { |
| 106 | + onStdout(msg) { |
| 107 | + output += msg || '' |
| 108 | + }, |
| 109 | + } |
| 110 | + ) |
| 111 | + await waitFor(2000) |
| 112 | + await killApp(app) |
| 113 | + expect(output).toContain(warningText) |
| 114 | + }) |
| 115 | +}) |
0 commit comments