-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add programmatic Node interface
- Loading branch information
1 parent
0c85059
commit 5639f03
Showing
21 changed files
with
19,273 additions
and
145 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"target-url": "https://api.punkapi.com/v2" | ||
} |
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 |
---|---|---|
@@ -1,4 +1,19 @@ | ||
#!/usr/bin/env node | ||
|
||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
process.env.NODE_ENV = 'production'; | ||
|
||
require('../dist'); | ||
const { Memento, createCli } = require('../dist'); | ||
|
||
const memento = Memento(); | ||
|
||
memento.run().then(() => { | ||
createCli({ container: memento.container }).show(); | ||
}); | ||
|
||
function stopServer() { | ||
memento.stop(); | ||
} | ||
|
||
process.on('SIGINT', stopServer); | ||
process.on('exit', stopServer); |
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,6 +1,5 @@ | ||
{ | ||
"targetUrl": "https://api.punkapi.com/v2", | ||
"target-url": "https://api.punkapi.com/v2", | ||
"delay": 0, | ||
"port": 3344, | ||
"cache-location": "file" | ||
"port": 3344 | ||
} |
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,3 @@ | ||
{ | ||
"target-url": "https://pokeapi.co/api/v2" | ||
} |
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,24 @@ | ||
# How to stub external services? | ||
|
||
1. Add memento as a dev dependency: `yarn add @antoinechalifour/memento --dev` or `npm install --save-dev @antoinechalifour/memento` | ||
2. Add a `.mementorc` in your project. | ||
3. Configure your test environment for using Memento as the API url | ||
4. Import memento in your test files, and plug it into your test runner hooks | ||
|
||
```js | ||
const { Memento } = require('@antoinechalifour/memento'); | ||
|
||
const memento = Memento({ | ||
cacheDirectory: path.join(__dirname, '<path to cache directory>') | ||
}); | ||
|
||
beforeAll(async () => { | ||
await memento.run(); | ||
}); | ||
|
||
afterAll(() => { | ||
memento.stop(); | ||
}); | ||
``` | ||
|
||
5. If the requests are not in the cache on the first test run, the assertions will be made against the actual API responses. On the next runs, they will be made against the cache. |
Oops, something went wrong.