Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add with firestore docs page #14852

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 67 additions & 0 deletions website/versioned_docs/version-29.4/Firestore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
id: firestore
title: Using with Firestore
---

With Jest's [Global Setup/Teardown](Configuration.md#globalsetup-string) and [Async Test Environment](Configuration.md#testenvironment-string) APIs, the developer experience for [Firestore](https://firebase.google.com/docs/firestore) is improved compared to using the `firebase emulators:exec` command.

## Use jest-firestore Preset

[Jest Firestore](https://github.com/thekip/jest-firestore) provides all required configuration to run your tests using Firestore Emulator.

1. First install `@thekip/jest-firestore`

```bash npm2yarn
npm install --save-dev @thekip/jest-firestore
```

2. Specify preset in your Jest configuration:

```json
{
"preset": "jest-firestore"
}
```

3. Write your test

```ts
import {type Firestore, getFirestore} from 'firebase-admin/firestore';
import {initializeApp} from 'firebase-admin/app';

describe('insert', () => {
let firestore: Firestore;
// setup deffiernet database for each jest worker to enable parallelism
const databaseName = `test-${process.pid}`;

beforeAll(() => {
// `firebase-admin` automatically discover
// FIRESTORE_EMULATOR_HOST provided by jest-firestore
const app = initializeApp();
firestore = getFirestore(app, databaseName);
});

beforeEach(async () => {
// clear database before each test
await fetch(
`http://${process.env.FIRESTORE_EMULATOR_HOST}/emulator/v1/projects/${process.env.GCLOUD_PROJECT}/databases/${databaseName}/documents`,
{method: 'DELETE'},
);
});

it('should insert a doc into collection', async () => {
const users = firestore.collection('users');

const mockUser = {_id: 'some-user-id', name: 'John'};
const {id} = await users.add(mockUser);

const insertedUser = await users.doc(id).get();

expect(insertedUser.data()).toEqual(mockUser);
});
});
```

There's no need to load any dependencies.

See [documentation](https://github.com/thekip/jest-firestore) for details.
67 changes: 67 additions & 0 deletions website/versioned_docs/version-29.5/Firestore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
id: firestore
title: Using with Firestore
---

With Jest's [Global Setup/Teardown](Configuration.md#globalsetup-string) and [Async Test Environment](Configuration.md#testenvironment-string) APIs, the developer experience for [Firestore](https://firebase.google.com/docs/firestore) is improved compared to using the `firebase emulators:exec` command.

## Use jest-firestore Preset

[Jest Firestore](https://github.com/thekip/jest-firestore) provides all required configuration to run your tests using Firestore Emulator.

1. First install `@thekip/jest-firestore`

```bash npm2yarn
npm install --save-dev @thekip/jest-firestore
```

2. Specify preset in your Jest configuration:

```json
{
"preset": "jest-firestore"
}
```

3. Write your test

```ts
import {type Firestore, getFirestore} from 'firebase-admin/firestore';
import {initializeApp} from 'firebase-admin/app';

describe('insert', () => {
let firestore: Firestore;
// setup deffiernet database for each jest worker to enable parallelism
const databaseName = `test-${process.pid}`;

beforeAll(() => {
// `firebase-admin` automatically discover
// FIRESTORE_EMULATOR_HOST provided by jest-firestore
const app = initializeApp();
firestore = getFirestore(app, databaseName);
});

beforeEach(async () => {
// clear database before each test
await fetch(
`http://${process.env.FIRESTORE_EMULATOR_HOST}/emulator/v1/projects/${process.env.GCLOUD_PROJECT}/databases/${databaseName}/documents`,
{method: 'DELETE'},
);
});

it('should insert a doc into collection', async () => {
const users = firestore.collection('users');

const mockUser = {_id: 'some-user-id', name: 'John'};
const {id} = await users.add(mockUser);

const insertedUser = await users.doc(id).get();

expect(insertedUser.data()).toEqual(mockUser);
});
});
```

There's no need to load any dependencies.

See [documentation](https://github.com/thekip/jest-firestore) for details.
67 changes: 67 additions & 0 deletions website/versioned_docs/version-29.6/Firestore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
id: firestore
title: Using with Firestore
---

With Jest's [Global Setup/Teardown](Configuration.md#globalsetup-string) and [Async Test Environment](Configuration.md#testenvironment-string) APIs, the developer experience for [Firestore](https://firebase.google.com/docs/firestore) is improved compared to using the `firebase emulators:exec` command.

## Use jest-firestore Preset

[Jest Firestore](https://github.com/thekip/jest-firestore) provides all required configuration to run your tests using Firestore Emulator.

1. First install `@thekip/jest-firestore`

```bash npm2yarn
npm install --save-dev @thekip/jest-firestore
```

2. Specify preset in your Jest configuration:

```json
{
"preset": "jest-firestore"
}
```

3. Write your test

```ts
import {type Firestore, getFirestore} from 'firebase-admin/firestore';
import {initializeApp} from 'firebase-admin/app';

describe('insert', () => {
let firestore: Firestore;
// setup deffiernet database for each jest worker to enable parallelism
const databaseName = `test-${process.pid}`;

beforeAll(() => {
// `firebase-admin` automatically discover
// FIRESTORE_EMULATOR_HOST provided by jest-firestore
const app = initializeApp();
firestore = getFirestore(app, databaseName);
});

beforeEach(async () => {
// clear database before each test
await fetch(
`http://${process.env.FIRESTORE_EMULATOR_HOST}/emulator/v1/projects/${process.env.GCLOUD_PROJECT}/databases/${databaseName}/documents`,
{method: 'DELETE'},
);
});

it('should insert a doc into collection', async () => {
const users = firestore.collection('users');

const mockUser = {_id: 'some-user-id', name: 'John'};
const {id} = await users.add(mockUser);

const insertedUser = await users.doc(id).get();

expect(insertedUser.data()).toEqual(mockUser);
});
});
```

There's no need to load any dependencies.

See [documentation](https://github.com/thekip/jest-firestore) for details.
67 changes: 67 additions & 0 deletions website/versioned_docs/version-29.7/Firestore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
id: firestore
title: Using with Firestore
---

With Jest's [Global Setup/Teardown](Configuration.md#globalsetup-string) and [Async Test Environment](Configuration.md#testenvironment-string) APIs, the developer experience for [Firestore](https://firebase.google.com/docs/firestore) is improved compared to using the `firebase emulators:exec` command.

## Use jest-firestore Preset

[Jest Firestore](https://github.com/thekip/jest-firestore) provides all required configuration to run your tests using Firestore Emulator.

1. First install `@thekip/jest-firestore`

```bash npm2yarn
npm install --save-dev @thekip/jest-firestore
```

2. Specify preset in your Jest configuration:

```json
{
"preset": "jest-firestore"
}
```

3. Write your test

```ts
import {type Firestore, getFirestore} from 'firebase-admin/firestore';
import {initializeApp} from 'firebase-admin/app';

describe('insert', () => {
let firestore: Firestore;
// setup deffiernet database for each jest worker to enable parallelism
const databaseName = `test-${process.pid}`;

beforeAll(() => {
// `firebase-admin` automatically discover
// FIRESTORE_EMULATOR_HOST provided by jest-firestore
const app = initializeApp();
firestore = getFirestore(app, databaseName);
});

beforeEach(async () => {
// clear database before each test
await fetch(
`http://${process.env.FIRESTORE_EMULATOR_HOST}/emulator/v1/projects/${process.env.GCLOUD_PROJECT}/databases/${databaseName}/documents`,
{method: 'DELETE'},
);
});

it('should insert a doc into collection', async () => {
const users = firestore.collection('users');

const mockUser = {_id: 'some-user-id', name: 'John'};
const {id} = await users.add(mockUser);

const insertedUser = await users.doc(id).get();

expect(insertedUser.data()).toEqual(mockUser);
});
});
```

There's no need to load any dependencies.

See [documentation](https://github.com/thekip/jest-firestore) for details.
1 change: 1 addition & 0 deletions website/versioned_sidebars/version-29.4-sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"puppeteer",
"mongodb",
"dynamodb",
"firestore",
"tutorial-jquery",
"watch-plugins",
"migration-guide",
Expand Down
1 change: 1 addition & 0 deletions website/versioned_sidebars/version-29.5-sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"puppeteer",
"mongodb",
"dynamodb",
"firestore",
"tutorial-jquery",
"watch-plugins",
"migration-guide",
Expand Down
1 change: 1 addition & 0 deletions website/versioned_sidebars/version-29.6-sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"puppeteer",
"mongodb",
"dynamodb",
"firestore",
"tutorial-jquery",
"watch-plugins",
"migration-guide",
Expand Down
1 change: 1 addition & 0 deletions website/versioned_sidebars/version-29.7-sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"puppeteer",
"mongodb",
"dynamodb",
"firestore",
"tutorial-jquery",
"watch-plugins",
"migration-guide",
Expand Down