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: Document Jest & Jasmine support using setup-polly-jest #135

Merged
merged 1 commit into from Nov 13, 2018
Merged
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
1 change: 1 addition & 0 deletions docs/_sidebar.md
Expand Up @@ -8,6 +8,7 @@

- [Mocha](test-frameworks/mocha.md)
- [QUnit](test-frameworks/qunit.md)
- [Jest & Jasmine](test-frameworks/jest-jasmine.md)

- Frameworks

Expand Down
11 changes: 11 additions & 0 deletions docs/test-frameworks/jest-jasmine.md
@@ -0,0 +1,11 @@
# Jest & Jasmine

Due to the nature of the Jest & Jasmine APIs and their restrictions on accessing
the current running test and its parent modules, we've decided to keep this test helper
as a 3rd party library provided by [@gribnoysup](https://github.com/gribnoysup).

The [setup-polly-jest](https://github.com/gribnoysup/setup-polly-jest) package provides a `setupPolly` utility which will setup a new polly instance for each test as well as stop it once the test has ended.
The Polly instance's recording name is derived from the current test name as well as its
parent module(s).

[README.md](https://raw.githubusercontent.com/gribnoysup/setup-polly-jest/master/README.md ':include :type=markdown')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will embed the entire readme into the page 😄

Expand Up @@ -31,11 +31,11 @@
"cookies": [
{
"domain": ".typicode.com",
"expires": "2019-10-03T09:11:36.000Z",
"expires": "2019-11-12T02:23:32.000Z",
"httpOnly": true,
"name": "__cfduid",
"path": "/",
"value": "dcb604bf87d85ac09ab6d90601d45a8541538557896"
"value": "dd0b0973c25af6f3001745bc056326e451541989412"
}
],
"headers": [
Expand All @@ -53,7 +53,7 @@
},
{
"name": "cf-ray",
"value": "463e4842385fc2f6-FRA"
"value": "4785898709366cc4-SJC"
},
{
"name": "connection",
Expand All @@ -69,7 +69,7 @@
},
{
"name": "date",
"value": "Wed, 03 Oct 2018 09:11:36 GMT"
"value": "Mon, 12 Nov 2018 02:23:32 GMT"
},
{
"name": "etag",
Expand All @@ -81,7 +81,7 @@
},
{
"name": "expires",
"value": "Wed, 03 Oct 2018 13:11:36 GMT"
"value": "Mon, 12 Nov 2018 06:23:32 GMT"
},
{
"name": "pragma",
Expand All @@ -93,7 +93,7 @@
},
{
"name": "set-cookie",
"value": "__cfduid=dcb604bf87d85ac09ab6d90601d45a8541538557896; expires=Thu, 03-Oct-19 09:11:36 GMT; path=/; domain=.typicode.com; HttpOnly"
"value": "__cfduid=dd0b0973c25af6f3001745bc056326e451541989412; expires=Tue, 12-Nov-19 02:23:32 GMT; path=/; domain=.typicode.com; HttpOnly"
},
{
"name": "transfer-encoding",
Expand Down Expand Up @@ -122,16 +122,16 @@
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2018-10-03T09:11:35.827Z",
"time": 114,
"startedDateTime": "2018-11-12T02:23:32.890Z",
"time": 84,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 114
"wait": 84
}
}
],
Expand Down
Expand Up @@ -31,11 +31,11 @@
"cookies": [
{
"domain": ".typicode.com",
"expires": "2019-10-03T09:11:36.000Z",
"expires": "2019-11-12T02:23:33.000Z",
"httpOnly": true,
"name": "__cfduid",
"path": "/",
"value": "d2ddf3370e0873b99b131f00b8e9046a61538557896"
"value": "dab40fd038dfd6c8b7dbaa93b83697d421541989413"
}
],
"headers": [
Expand All @@ -53,7 +53,7 @@
},
{
"name": "cf-ray",
"value": "463e4842b80c96a0-FRA"
"value": "47858987490e6e20-SJC"
},
{
"name": "connection",
Expand All @@ -69,7 +69,7 @@
},
{
"name": "date",
"value": "Wed, 03 Oct 2018 09:11:36 GMT"
"value": "Mon, 12 Nov 2018 02:23:33 GMT"
},
{
"name": "etag",
Expand All @@ -81,7 +81,7 @@
},
{
"name": "expires",
"value": "Wed, 03 Oct 2018 13:11:36 GMT"
"value": "Mon, 12 Nov 2018 06:23:33 GMT"
},
{
"name": "pragma",
Expand All @@ -93,7 +93,7 @@
},
{
"name": "set-cookie",
"value": "__cfduid=d2ddf3370e0873b99b131f00b8e9046a61538557896; expires=Thu, 03-Oct-19 09:11:36 GMT; path=/; domain=.typicode.com; HttpOnly"
"value": "__cfduid=dab40fd038dfd6c8b7dbaa93b83697d421541989413; expires=Tue, 12-Nov-19 02:23:33 GMT; path=/; domain=.typicode.com; HttpOnly"
},
{
"name": "transfer-encoding",
Expand Down Expand Up @@ -122,16 +122,16 @@
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2018-10-03T09:11:35.953Z",
"time": 67,
"startedDateTime": "2018-11-12T02:23:32.986Z",
"time": 25,
"timings": {
"blocked": -1,
"connect": -1,
"dns": -1,
"receive": 0,
"send": 0,
"ssl": -1,
"wait": 67
"wait": 25
}
}
],
Expand Down
15 changes: 3 additions & 12 deletions examples/jest-node-fetch/__tests__/index.test.js
@@ -1,6 +1,7 @@
const path = require('path');

const { Polly } = require('@pollyjs/core');
const { setupPolly } = require('setup-polly-jest');
const FetchAdapter = require('@pollyjs/adapter-fetch');
const FSPersister = require('@pollyjs/persister-fs');

Expand All @@ -9,8 +10,8 @@ Polly.register(FSPersister);

const { posts, users } = require('../src');

const setupPolly = name => {
return new Polly(name, {
describe('jest-node-fetch', () => {
setupPolly({
adapters: ['fetch'],
persister: 'fs',
persisterOptions: {
Expand All @@ -19,35 +20,25 @@ const setupPolly = name => {
}
}
});
};

describe('jest-node-fetch', () => {
describe('posts', () => {
it('should return post', async () => {
const polly = setupPolly('jest-node-fetch/posts/should return post');

const post = await posts('1');

expect(post.id).toBe(1);
expect(post.title).toBe(
'sunt aut facere repellat provident occaecati excepturi optio reprehenderit'
);

await polly.stop();
});
});

describe('users', () => {
it('should return user', async () => {
const polly = setupPolly('jest-node-fetch/users/should return user');

const user = await users('1');

expect(user.id).toBe(1);
expect(user.name).toBe('Leanne Graham');
expect(user.email).toBe('Sincere@april.biz');

await polly.stop();
});
});
});
3 changes: 2 additions & 1 deletion examples/jest-node-fetch/package.json
Expand Up @@ -11,6 +11,7 @@
"@pollyjs/core": "*",
"@pollyjs/persister-fs": "*",
"jest": "*",
"node-fetch": "*"
"node-fetch": "*",
"setup-polly-jest": "*"
}
}