-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(whook): Improve test coveraging
- Loading branch information
Showing
17 changed files
with
808 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,4 +135,4 @@ | |
"preversion": " && npm run compile", | ||
"test": "npm run jest" | ||
} | ||
} | ||
} |
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,35 @@ | ||
import { noop, identity, pipe, compose } from './utils'; | ||
|
||
describe('noop', () => { | ||
it('should work', () => { | ||
noop(); | ||
}); | ||
}); | ||
|
||
describe('identity', () => { | ||
it('should work', () => { | ||
expect(identity('a')).toEqual('a'); | ||
}); | ||
}); | ||
|
||
describe('pipe', () => { | ||
it('should work', () => { | ||
expect( | ||
pipe( | ||
identity, | ||
identity, | ||
)('a'), | ||
).toEqual('a'); | ||
}); | ||
}); | ||
|
||
describe('noop', () => { | ||
it('should work', () => { | ||
expect( | ||
compose( | ||
identity, | ||
identity, | ||
)('a'), | ||
).toEqual('a'); | ||
}); | ||
}); |
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,57 @@ | ||
import initENV from './ENV'; | ||
|
||
describe('initENV', () => { | ||
const log = jest.fn(); | ||
const readFile = jest.fn(); | ||
|
||
beforeEach(() => { | ||
log.mockReset(); | ||
readFile.mockReset(); | ||
}); | ||
|
||
it('should work with existing file', async () => { | ||
readFile.mockResolvedValueOnce( | ||
Buffer.from( | ||
`DB_PASSWORD=oudelali | ||
DB_HOST = 'localhost' | ||
`, | ||
), | ||
); | ||
|
||
const ENV = await initENV({ | ||
ENV: { ENV: 1337 }, | ||
NODE_ENV: 'development', | ||
BASE_ENV: { KEY_BASE_ENV: 'test' }, | ||
PROCESS_ENV: { KEY_PROCESS_ENV: 'test' }, | ||
PWD: '/home/whoami/my-whook-project', | ||
log, | ||
readFile, | ||
}); | ||
|
||
expect({ | ||
ENV, | ||
logCalls: log.mock.calls, | ||
readFileCalls: readFile.mock.calls, | ||
}).toMatchSnapshot(); | ||
}); | ||
|
||
it('should fail with non-existing file', async () => { | ||
readFile.mockRejectedValueOnce(new Error('EEXISTS')); | ||
|
||
const ENV = await initENV({ | ||
ENV: { ENV: 1337 }, | ||
NODE_ENV: 'development', | ||
BASE_ENV: { KEY_BASE_ENV: 'test' }, | ||
PROCESS_ENV: { KEY_PROCESS_ENV: 'test' }, | ||
PWD: '/home/whoami/my-whook-project', | ||
log, | ||
readFile, | ||
}); | ||
|
||
expect({ | ||
ENV, | ||
logCalls: log.mock.calls.filter(args => 'debug' !== args[0]), | ||
readFileCalls: readFile.mock.calls, | ||
}).toMatchSnapshot(); | ||
}); | ||
}); |
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,57 @@ | ||
import initHOST from './HOST'; | ||
|
||
describe('initHOST', () => { | ||
const log = jest.fn(); | ||
const internalIp = { v4: jest.fn() }; | ||
|
||
beforeEach(() => { | ||
log.mockReset(); | ||
internalIp.v4.mockReset(); | ||
}); | ||
|
||
it('should use the env HOST first', async () => { | ||
const HOST = await initHOST({ | ||
ENV: { HOST: '192.168.1.11' }, | ||
log, | ||
internalIp, | ||
}); | ||
|
||
expect({ | ||
HOST, | ||
logCalls: log.mock.calls, | ||
internalIpV4Calls: internalIp.v4.mock.calls, | ||
}).toMatchSnapshot(); | ||
}); | ||
|
||
it('should find a HOST by itself if no env HOST', async () => { | ||
internalIp.v4.mockResolvedValueOnce('192.168.1.10'); | ||
|
||
const HOST = await initHOST({ | ||
ENV: {}, | ||
log, | ||
internalIp, | ||
}); | ||
|
||
expect(HOST); | ||
expect({ | ||
logCalls: log.mock.calls, | ||
internalIpV4Calls: internalIp.v4.mock.calls, | ||
}).toMatchSnapshot(); | ||
}); | ||
|
||
it('should fallback to localhost', async () => { | ||
internalIp.v4.mockResolvedValueOnce(''); | ||
|
||
const HOST = await initHOST({ | ||
ENV: {}, | ||
log, | ||
internalIp, | ||
}); | ||
|
||
expect(HOST); | ||
expect({ | ||
logCalls: log.mock.calls, | ||
internalIpV4Calls: internalIp.v4.mock.calls, | ||
}).toMatchSnapshot(); | ||
}); | ||
}); |
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,34 @@ | ||
import initPORT from './PORT'; | ||
|
||
describe('initPORT', () => { | ||
const log = jest.fn(); | ||
|
||
beforeEach(() => { | ||
log.mockReset(); | ||
}); | ||
|
||
it('should use the env port first', async () => { | ||
const port = await initPORT({ | ||
ENV: { PORT: 1337 }, | ||
log, | ||
}); | ||
|
||
expect({ | ||
port, | ||
logCalls: log.mock.calls, | ||
}).toMatchSnapshot(); | ||
}); | ||
|
||
it('should find a port by itself if no env port', async () => { | ||
const port = await initPORT({ | ||
log, | ||
}); | ||
|
||
expect(port); | ||
expect({ | ||
logCalls: log.mock.calls.map(([arg1, arg2, ...args]) => { | ||
return [arg1, arg2.replace(/port (\d+)/, 'port ${PORT}'), ...args]; | ||
}), | ||
}).toMatchSnapshot(); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
packages/whook/src/services/__snapshots__/ENV.test.js.snap
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,63 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`initENV should fail with non-existing file 1`] = ` | ||
Object { | ||
"ENV": Object { | ||
"KEY_BASE_ENV": "test", | ||
"KEY_PROCESS_ENV": "test", | ||
"NODE_ENV": "development", | ||
"PWD": "/home/whoami/my-whook-project", | ||
}, | ||
"logCalls": Array [ | ||
Array [ | ||
"info", | ||
"Loading the environment service.", | ||
], | ||
Array [ | ||
"info", | ||
"Using local env.", | ||
], | ||
Array [ | ||
"info", | ||
"Could not load \\".env.development\\" file.", | ||
], | ||
], | ||
"readFileCalls": Array [ | ||
Array [ | ||
"/home/whoami/my-whook-project/.env.development", | ||
], | ||
], | ||
} | ||
`; | ||
|
||
exports[`initENV should work with existing file 1`] = ` | ||
Object { | ||
"ENV": Object { | ||
"DB_HOST": "localhost", | ||
"DB_PASSWORD": "oudelali", | ||
"KEY_BASE_ENV": "test", | ||
"KEY_PROCESS_ENV": "test", | ||
"NODE_ENV": "development", | ||
"PWD": "/home/whoami/my-whook-project", | ||
}, | ||
"logCalls": Array [ | ||
Array [ | ||
"info", | ||
"Loading the environment service.", | ||
], | ||
Array [ | ||
"info", | ||
"Using local env.", | ||
], | ||
Array [ | ||
"info", | ||
"Using .env file at /home/whoami/my-whook-project/.env.development.", | ||
], | ||
], | ||
"readFileCalls": Array [ | ||
Array [ | ||
"/home/whoami/my-whook-project/.env.development", | ||
], | ||
], | ||
} | ||
`; |
Oops, something went wrong.