-
Notifications
You must be signed in to change notification settings - Fork 816
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
114 additions
and
83 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
114 changes: 57 additions & 57 deletions
114
live-coding/01-node-callbacks-promises/tests/dotenv.test.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 |
---|---|---|
@@ -1,57 +1,57 @@ | ||
import { describe, it, beforeEach, afterEach } from 'node:test' | ||
import { equal } from 'node:assert/strict' | ||
import { unlinkSync, writeFileSync } from 'node:fs' | ||
import { createRequire } from 'node:module' | ||
import { config } from '../solutions/dotenv.js' | ||
|
||
describe('1. dotenv', () => { | ||
beforeEach(() => { | ||
// clean process.env | ||
for (const key of Object.keys(process.env)) { | ||
delete process.env[key] | ||
} | ||
}) | ||
|
||
afterEach(() => { | ||
try { | ||
unlinkSync('.env') | ||
} catch {} | ||
|
||
try { | ||
unlinkSync('./test/.env.local') | ||
} catch {} | ||
}) | ||
|
||
it('1.1. load .env file', () => { | ||
// create .env file in root directory | ||
writeFileSync('.env', 'PORT=3000\nTOKEN="123abc"') | ||
config() | ||
|
||
equal(process.env.PORT, '3000') | ||
equal(process.env.TOKEN, '123abc') | ||
}) | ||
|
||
it('1.2. load .env file from custom path', () => { | ||
// create .env file in root directory | ||
writeFileSync('./test/.env.local', 'PORT=3000\nTOKEN="123abc"') | ||
config({ path: './test/.env.local' }) | ||
|
||
equal(process.env.PORT, '3000') | ||
equal(process.env.TOKEN, '123abc') | ||
}) | ||
|
||
it('1.3 it works even without .env file', () => { | ||
config() | ||
equal(process.env.TOKEN, undefined) | ||
}) | ||
|
||
it('1.4 dont use dotenv dependency', () => { | ||
// check that dotenv dependency is not installed | ||
try { | ||
const require = createRequire(import.meta.url) | ||
require('dotenv') | ||
} catch (error) { | ||
equal(error.code, 'MODULE_NOT_FOUND') | ||
} | ||
}) | ||
}) | ||
// import { describe, it, beforeEach, afterEach } from 'node:test' | ||
// import { equal } from 'node:assert/strict' | ||
// import { unlinkSync, writeFileSync } from 'node:fs' | ||
// import { createRequire } from 'node:module' | ||
// import { config } from '../solutions/dotenv.js' | ||
|
||
// describe('1. dotenv', () => { | ||
// beforeEach(() => { | ||
// // clean process.env | ||
// for (const key of Object.keys(process.env)) { | ||
// delete process.env[key] | ||
// } | ||
// }) | ||
|
||
// afterEach(() => { | ||
// try { | ||
// unlinkSync('.env') | ||
// } catch {} | ||
|
||
// try { | ||
// unlinkSync('./test/.env.local') | ||
// } catch {} | ||
// }) | ||
|
||
// it('1.1. load .env file', () => { | ||
// // create .env file in root directory | ||
// writeFileSync('.env', 'PORT=3000\nTOKEN="123abc"') | ||
// config() | ||
|
||
// equal(process.env.PORT, '3000') | ||
// equal(process.env.TOKEN, '123abc') | ||
// }) | ||
|
||
// it('1.2. load .env file from custom path', () => { | ||
// // create .env file in root directory | ||
// writeFileSync('./test/.env.local', 'PORT=3000\nTOKEN="123abc"') | ||
// config({ path: './test/.env.local' }) | ||
|
||
// equal(process.env.PORT, '3000') | ||
// equal(process.env.TOKEN, '123abc') | ||
// }) | ||
|
||
// it('1.3 it works even without .env file', () => { | ||
// config() | ||
// equal(process.env.TOKEN, undefined) | ||
// }) | ||
|
||
// it('1.4 dont use dotenv dependency', () => { | ||
// // check that dotenv dependency is not installed | ||
// try { | ||
// const require = createRequire(import.meta.url) | ||
// require('dotenv') | ||
// } catch (error) { | ||
// equal(error.code, 'MODULE_NOT_FOUND') | ||
// } | ||
// }) | ||
// }) |
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