-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re-create docs for v22.3 with latest changes from master
- Loading branch information
Showing
30 changed files
with
323 additions
and
160 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
website/versioned_docs/version-22.2.2/CLI.md → website/versioned_docs/version-22.3/CLI.md
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,5 +1,5 @@ | ||
--- | ||
id: version-22.2.2-cli | ||
id: version-22.3-cli | ||
title: Jest CLI Options | ||
original_id: cli | ||
--- | ||
|
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
170 changes: 122 additions & 48 deletions
170
...oned_docs/version-22.2.2/Es6ClassMocks.md → ...sioned_docs/version-22.3/Es6ClassMocks.md
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ersioned_docs/version-22.2.2/ExpectAPI.md → .../versioned_docs/version-22.3/ExpectAPI.md
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,5 +1,5 @@ | ||
--- | ||
id: version-22.2.2-expect | ||
id: version-22.3-expect | ||
title: Expect | ||
original_id: expect | ||
--- | ||
|
2 changes: 1 addition & 1 deletion
2
...ned_docs/version-22.2.2/GettingStarted.md → ...ioned_docs/version-22.3/GettingStarted.md
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
2 changes: 1 addition & 1 deletion
2
...ersioned_docs/version-22.2.2/GlobalAPI.md → .../versioned_docs/version-22.3/GlobalAPI.md
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,5 +1,5 @@ | ||
--- | ||
id: version-22.2.2-api | ||
id: version-22.3-api | ||
title: Globals | ||
original_id: api | ||
--- | ||
|
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
2 changes: 1 addition & 1 deletion
2
...ioned_docs/version-22.2.2/JestPlatform.md → ...rsioned_docs/version-22.3/JestPlatform.md
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
2 changes: 1 addition & 1 deletion
2
...sioned_docs/version-22.2.2/ManualMocks.md → ...ersioned_docs/version-22.3/ManualMocks.md
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
2 changes: 1 addition & 1 deletion
2
...ned_docs/version-22.2.2/MigrationGuide.md → ...ioned_docs/version-22.3/MigrationGuide.md
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
2 changes: 1 addition & 1 deletion
2
...ed_docs/version-22.2.2/MockFunctionAPI.md → ...oned_docs/version-22.3/MockFunctionAPI.md
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
2 changes: 1 addition & 1 deletion
2
...oned_docs/version-22.2.2/MockFunctions.md → ...sioned_docs/version-22.3/MockFunctions.md
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,128 @@ | ||
--- | ||
id: version-22.3-mongodb | ||
title: Using with MongoDB | ||
original_id: mongodb | ||
--- | ||
|
||
With the [Global Setup/Teardown](Configuration.md#globalsetup-string) and | ||
[Async Test Environment](Configuration.md#testenvironment-string) APIs, Jest can | ||
work smoothly with [MongoDB](https://www.mongodb.com/). | ||
|
||
## A jest-mongodb example | ||
|
||
The basic idea is to: | ||
|
||
1. Spin up in-memory mongodb server | ||
2. Export a global variable with mongo URI | ||
3. Write tests for queries / aggregations using a real database ✨ | ||
4. Shut down mongodb server using Global Teardown | ||
|
||
Here's an example of the GlobalSetup script | ||
|
||
```js | ||
// setup.js | ||
const MongodbMemoryServer = require('mongodb-memory-server'); | ||
|
||
const MONGO_DB_NAME = 'jest'; | ||
const mongod = new MongodbMemoryServer.default({ | ||
instance: { | ||
dbName: MONGO_DB_NAME, | ||
}, | ||
binary: { | ||
version: '3.2.19', | ||
}, | ||
}); | ||
|
||
module.exports = function() { | ||
global.__MONGOD__ = mongod; | ||
global.__MONGO_DB_NAME__ = MONGO_DB_NAME; | ||
}; | ||
``` | ||
|
||
Then we need a custom Test Environment for Mongo | ||
|
||
```js | ||
// mongo-environment.js | ||
class MongoEnvironment extends NodeEnvironment { | ||
constructor(config) { | ||
super(config); | ||
} | ||
|
||
async setup() { | ||
console.log('Setup MongoDB Test Environment'); | ||
|
||
this.global.__MONGO_URI__ = await global.__MONGOD__.getConnectionString(); | ||
this.global.__MONGO_DB_NAME__ = global.__MONGO_DB_NAME__; | ||
|
||
await super.setup(); | ||
} | ||
|
||
async teardown() { | ||
console.log('Teardown MongoDB Test Environment'); | ||
|
||
await super.teardown(); | ||
} | ||
|
||
runScript(script) { | ||
return super.runScript(script); | ||
} | ||
} | ||
``` | ||
|
||
Finally we can shut down mongodb server | ||
|
||
```js | ||
// teardown.js | ||
module.exports = async function() { | ||
await global.__MONGOD__.stop(); | ||
}; | ||
``` | ||
|
||
With all the things set up, we can now write our tests like this: | ||
|
||
```js | ||
// test.js | ||
const {MongoClient} = require('mongodb'); | ||
|
||
let connection; | ||
let db; | ||
|
||
beforeAll(async () => { | ||
connection = await MongoClient.connect(global.__MONGO_URI__); | ||
db = await connection.db(global.__MONGO_DB_NAME__); | ||
}); | ||
|
||
afterAll(async () => { | ||
await connection.close(); | ||
await db.close(); | ||
}); | ||
|
||
it('should aggregate docs from collection', async () => { | ||
const files = db.collection('files'); | ||
|
||
await files.insertMany([ | ||
{type: 'Document'}, | ||
{type: 'Video'}, | ||
{type: 'Image'}, | ||
{type: 'Document'}, | ||
{type: 'Image'}, | ||
{type: 'Document'}, | ||
]); | ||
|
||
const topFiles = await files | ||
.aggregate([ | ||
{$group: {_id: '$type', count: {$sum: 1}}}, | ||
{$sort: {count: -1}}, | ||
]) | ||
.toArray(); | ||
|
||
expect(topFiles).toEqual([ | ||
{_id: 'Document', count: 3}, | ||
{_id: 'Image', count: 2}, | ||
{_id: 'Video', count: 1}, | ||
]); | ||
}); | ||
``` | ||
|
||
Here's the code of | ||
[full working example](https://github.com/vladgolubev/jest-mongodb). |
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
2 changes: 1 addition & 1 deletion
2
...ersioned_docs/version-22.2.2/Puppeteer.md → .../versioned_docs/version-22.3/Puppeteer.md
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
2 changes: 1 addition & 1 deletion
2
...d_docs/version-22.2.2/SetupAndTeardown.md → ...ned_docs/version-22.3/SetupAndTeardown.md
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
2 changes: 1 addition & 1 deletion
2
...d_docs/version-22.2.2/TestingAsyncCode.md → ...ned_docs/version-22.3/TestingAsyncCode.md
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
2 changes: 1 addition & 1 deletion
2
..._docs/version-22.2.2/TestingFrameworks.md → ...ed_docs/version-22.3/TestingFrameworks.md
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
2 changes: 1 addition & 1 deletion
2
...rsioned_docs/version-22.2.2/TimerMocks.md → ...versioned_docs/version-22.3/TimerMocks.md
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,5 +1,5 @@ | ||
--- | ||
id: version-22.2.2-timer-mocks | ||
id: version-22.3-timer-mocks | ||
title: Timer Mocks | ||
original_id: timer-mocks | ||
--- | ||
|
2 changes: 1 addition & 1 deletion
2
...ed_docs/version-22.2.2/Troubleshooting.md → ...oned_docs/version-22.3/Troubleshooting.md
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
2 changes: 1 addition & 1 deletion
2
...oned_docs/version-22.2.2/TutorialAsync.md → ...sioned_docs/version-22.3/TutorialAsync.md
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
2 changes: 1 addition & 1 deletion
2
...oned_docs/version-22.2.2/TutorialReact.md → ...sioned_docs/version-22.3/TutorialReact.md
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
2 changes: 1 addition & 1 deletion
2
...ned_docs/version-22.2.2/TutorialjQuery.md → ...ioned_docs/version-22.3/TutorialjQuery.md
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
Oops, something went wrong.