-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update checking for existing dotenv usage (#11496)
* Update checking for existing dotenv usage * Check for package-lock.json also
- Loading branch information
Showing
6 changed files
with
131 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "env-config", | ||
"devDependencies": { | ||
"dotenv": "latest" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
test/integration/env-config-disable/app/packages/sub-app/.env/.env.development
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
HELLO=world |
4 changes: 4 additions & 0 deletions
4
test/integration/env-config-disable/app/packages/sub-app/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "env-config", | ||
"dependencies": {} | ||
} |
1 change: 1 addition & 0 deletions
1
test/integration/env-config-disable/app/packages/sub-app/pages/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => 'hi' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import fs from 'fs-extra' | ||
import { join } from 'path' | ||
import { | ||
nextBuild, | ||
findPort, | ||
launchApp, | ||
killApp, | ||
nextStart, | ||
renderViaHTTP, | ||
} from 'next-test-utils' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2 | ||
|
||
const monorepoRoot = join(__dirname, '../app') | ||
const yarnLock = join(monorepoRoot, 'yarn.lock') | ||
const lernaConf = join(monorepoRoot, 'lerna.json') | ||
const appDir = join(monorepoRoot, 'packages/sub-app') | ||
|
||
let app | ||
let appPort | ||
|
||
const runTests = () => { | ||
describe('dev mode', () => { | ||
it('should start dev server without errors', async () => { | ||
let stderr = '' | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort, { | ||
onStderr(msg) { | ||
stderr += msg || '' | ||
}, | ||
}) | ||
|
||
const html = await renderViaHTTP(appPort, '/') | ||
await killApp(app) | ||
|
||
expect(html).toContain('hi') | ||
expect(stderr).not.toContain('Failed to load env') | ||
}) | ||
}) | ||
|
||
describe('production mode', () => { | ||
it('should build app successfully', async () => { | ||
const { stderr, code } = await nextBuild(appDir, [], { stderr: true }) | ||
expect(code).toBe(0) | ||
expect((stderr || '').length).toBe(0) | ||
}) | ||
|
||
it('should start without error', async () => { | ||
let stderr = '' | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort, { | ||
onStderr(msg) { | ||
stderr += msg || '' | ||
}, | ||
}) | ||
|
||
const html = await renderViaHTTP(appPort, '/') | ||
await killApp(app) | ||
|
||
expect(html).toContain('hi') | ||
expect(stderr).not.toContain('Failed to load env') | ||
}) | ||
}) | ||
} | ||
|
||
describe('Env support disabling', () => { | ||
describe('with yarn based monorepo', () => { | ||
beforeAll(() => fs.writeFile(yarnLock, 'test')) | ||
afterAll(() => fs.remove(yarnLock)) | ||
|
||
runTests() | ||
}) | ||
|
||
describe('with lerna based monorepo', () => { | ||
beforeAll(() => fs.writeFile(lernaConf, 'test')) | ||
afterAll(() => fs.remove(lernaConf)) | ||
|
||
runTests() | ||
}) | ||
}) |