MCPcopy
hub / github.com/vercel/next.js / runTests

Function runTests

test/integration/env-config/test/index.test.ts:33–138  ·  view source on GitHub ↗
(mode = 'dev', didReload = false)

Source from the content-addressed store, hash-verified

31}
32
33const runTests = (mode = 'dev', didReload = false) => {
34 const isDevOnly = mode === 'dev'
35 const isTestEnv = mode === 'test'
36 const isDev = isDevOnly || isTestEnv
37
38 const checkEnvData = (data) => {
39 expect(data.ENV_FILE_KEY).toBe('env')
40 expect(data.LOCAL_ENV_FILE_KEY).toBe(!isTestEnv ? 'localenv' : undefined)
41 expect(data.DEVELOPMENT_ENV_FILE_KEY).toBe(
42 isDevOnly ? 'development' : undefined
43 )
44 expect(data.LOCAL_DEVELOPMENT_ENV_FILE_KEY).toBe(
45 isDevOnly ? 'localdevelopment' : undefined
46 )
47 expect(data.TEST_ENV_FILE_KEY).toBe(isTestEnv ? 'test' : undefined)
48 expect(data.LOCAL_TEST_ENV_FILE_KEY).toBe(
49 isTestEnv ? 'localtest' : undefined
50 )
51 expect(data.PRODUCTION_ENV_FILE_KEY).toBe(isDev ? undefined : 'production')
52 expect(data.LOCAL_PRODUCTION_ENV_FILE_KEY).toBe(
53 isDev ? undefined : 'localproduction'
54 )
55 expect(data.ENV_FILE_EXPANDED).toBe('env')
56 expect(data.ENV_FILE_EXPANDED_CONCAT).toBe('hello-env')
57 expect(data.ENV_FILE_EXPANDED_ESCAPED).toBe('$ENV_FILE_KEY')
58 expect(data.ENV_FILE_KEY_EXCLAMATION).toBe('hello!')
59 expect(data.ENV_FILE_EMPTY_FIRST).toBe(isTestEnv ? '' : '$escaped')
60 expect(data.ENV_FILE_PROCESS_ENV).toBe('env-cli')
61
62 if (didReload) {
63 expect(data.NEW_ENV_KEY).toBe('true')
64 expect(data.NEW_ENV_LOCAL_KEY).toBe('hello')
65 expect(data.NEW_ENV_DEV_KEY).toBe('from-dev')
66 }
67 expect(data.nextConfigEnv).toBe('hello from next.config.js')
68 expect(data.nextConfigPublicEnv).toBe('hello again from next.config.js')
69 expect(data.nextConfigNewPublicEnv).toBe('hello set in next.config.js')
70 }
71
72 it('should have process environment override .env', async () => {
73 const data = await getEnvFromHtml('/')
74 expect(data.PROCESS_ENV_KEY).toEqual('processenvironment')
75 })
76
77 it('should provide global env to next.config.js', async () => {
78 const res = await fetchViaHTTP(appPort, '/hello', undefined, {
79 redirect: 'manual',
80 })
81 const { pathname } = new URL(res.headers.get('location'))
82
83 expect(res.status).toBe(307)
84 expect(pathname).toBe('/another')
85 })
86
87 it('should inline global values during build', async () => {
88 const browser = await webdriver(appPort, '/global')
89
90 expect(await browser.waitForElementByCss('#global-value').text()).toBe(

Callers 1

index.test.tsFile · 0.70

Calls 11

fetchViaHTTPFunction · 0.90
renderViaHTTPFunction · 0.90
getEnvFromHtmlFunction · 0.85
webdriverFunction · 0.85
checkEnvDataFunction · 0.85
waitForElementByCssMethod · 0.80
getMethod · 0.65
textMethod · 0.65
itFunction · 0.50
expectFunction · 0.50
parseMethod · 0.45

Tested by

no test coverage detected