sentry-testkit 5.0.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -89
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,28 +1,49 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
+
<a href="https://npmjs.org/package/sentry-testkit">
|
|
3
|
+
<img src="https://img.shields.io/npm/v/sentry-testkit.svg" alt="npm version">
|
|
4
|
+
</a>
|
|
5
|
+
<a href="https://npmjs.org/package/sentry-testkit">
|
|
6
|
+
<img src="https://img.shields.io/npm/dm/sentry-testkit.svg" alt="npm downloads">
|
|
7
|
+
</a>
|
|
8
|
+
<a href="https://github.com/wix/sentry-testkit/actions">
|
|
9
|
+
<img src="https://github.com/wix/sentry-testkit/workflows/Test/badge.svg" alt="Test">
|
|
10
|
+
</a>
|
|
11
|
+
</p>
|
|
12
|
+
<p align="center">
|
|
13
|
+
<a href="#">
|
|
14
|
+
<img src="https://img.shields.io/badge/Compatible%20with%20Sentry-v6-blue" alt="sentry version 6">
|
|
15
|
+
</a>
|
|
16
|
+
<a href="#">
|
|
17
|
+
<img src="https://img.shields.io/badge/Compatible%20with%20Sentry-v7-blue" alt="sentry version 7">
|
|
18
|
+
</a>
|
|
19
|
+
</p>
|
|
20
|
+
</p>
|
|
21
|
+
<p align="center">
|
|
22
|
+
<a href="https://wix.github.io/sentry-testkit/">
|
|
2
23
|
<img alt="sentry-teskit" src="./docs/logo/Sentry_github.svg" height="132">
|
|
24
|
+
</a>
|
|
3
25
|
</p>
|
|
4
26
|
|
|
5
|
-
|
|
6
|
-
[](https://npmjs.org/package/sentry-testkit)
|
|
7
|
-
[](https://npmjs.org/package/sentry-testkit)
|
|
8
|
-
[](https://github.com/wix/sentry-testkit/actions)
|
|
9
|
-

|
|
10
|
-

|
|
11
|
-
|
|
12
27
|
Sentry is an open-source JavaScript SDK published by [Sentry](https://sentry.io/welcome/) to enable error tracking that helps developers monitor and fix crashes in real time.<br>
|
|
13
|
-
However, when building tests for your application, you want to assert that the right flow-tracking or error is being sent to
|
|
28
|
+
However, when building tests for your application, you want to assert that the right flow-tracking or error is being sent to _Sentry_, **but** without really sending it to _Sentry_ servers. This way you won't swamp Sentry with false reports during test running and other CI operations.
|
|
14
29
|
|
|
15
30
|
## Sentry Testkit - to the rescue
|
|
16
|
-
*Sentry Testkit* enables Sentry to work natively in your application, and by overriding the default Sentry transport mechanism, the report is not really sent but rather logged locally into memory. In this way, the logged reports can be fetched later for your own usage, verification, or any other use you may have in your local developing/testing environment.
|
|
17
31
|
|
|
32
|
+
_Sentry Testkit_ enables Sentry to work natively in your application, and by overriding the default Sentry transport mechanism, the report is not really sent but rather logged locally into memory. In this way, the logged reports can be fetched later for your own usage, verification, or any other use you may have in your local developing/testing environment.
|
|
18
33
|
|
|
19
|
-
##
|
|
20
|
-
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
**npm:**
|
|
21
37
|
```
|
|
22
38
|
npm install sentry-testkit --save-dev
|
|
23
39
|
```
|
|
40
|
+
**yarn:**
|
|
41
|
+
```
|
|
42
|
+
yarn add sentry-testkit --dev
|
|
43
|
+
```
|
|
24
44
|
|
|
25
45
|
## Usage
|
|
46
|
+
|
|
26
47
|
```javascript
|
|
27
48
|
// some.spec.js
|
|
28
49
|
const sentryTestkit = require('sentry-testkit')
|
|
@@ -36,102 +57,44 @@ Sentry.init({
|
|
|
36
57
|
//... other configurations
|
|
37
58
|
})
|
|
38
59
|
|
|
39
|
-
test('
|
|
60
|
+
test('collect error events', function () {
|
|
40
61
|
// run any scenario that eventually calls Sentry.captureException(...)
|
|
41
62
|
expect(testkit.reports()).toHaveLength(1)
|
|
42
63
|
const report = testkit.reports()[0]
|
|
43
64
|
expect(report).toHaveProperty(...)
|
|
44
65
|
});
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Working with []() [Jest](https://jestjs.io/en/)
|
|
48
|
-
We've added a new option to integrate `sentry-testkit` with `jest`'s mocking mechanism. Detailed implementation can be seen [here](https://github.com/wix/sentry-testkit/blob/master/src/jestMock.js).
|
|
49
|
-
|
|
50
|
-
At the moment it is available only to `@sentry/browser` package but we will expand to more packages as we should figure out how to do it right for all Sentry's client packages.
|
|
51
|
-
|
|
52
|
-
If you're using `Jest` for testing, all you have to do in your `spec.js` file is to import the Jest mock.
|
|
53
|
-
```javascript
|
|
54
|
-
// some.spec.js
|
|
55
|
-
import { testkit } from 'sentry-testkit/dist/jestMock';
|
|
56
66
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
expect(testkit.reports().length).toBeGreaterThan(0);
|
|
67
|
+
// Similarly for performance events
|
|
68
|
+
test('collect performance events', function () {
|
|
69
|
+
// run any scenario that eventually calls Sentry.startTransaction(...)
|
|
70
|
+
expect(testkit.transactions()).toHaveLength(1)
|
|
62
71
|
});
|
|
63
72
|
```
|
|
64
|
-
> Make sure to put your `import` statement before all other imports.
|
|
65
73
|
|
|
66
|
-
##
|
|
67
|
-
Instead of modifying your application code, you can use network interception libraries in conjunction with the testkit.\
|
|
68
|
-
Example with [nock](https://github.com/nock/nock):
|
|
69
|
-
```javascript
|
|
70
|
-
|
|
71
|
-
const nock = require('nock')
|
|
72
|
-
const sentryTestkit = require('sentry-testkit')
|
|
73
|
-
const { testkit, initNetworkInterceptor } = sentryTestkit()
|
|
74
|
-
|
|
75
|
-
beforeAll(() => {
|
|
76
|
-
const myAppDSN = '<your DSN goes here>'
|
|
77
|
-
initNetworkInterceptor(myAppDSN, (baseUrl, handleRequestBody) => {
|
|
78
|
-
// This callback is where we init our interceptor.
|
|
79
|
-
// The interceptor should intercept requests from `baseUrl` and pass the
|
|
80
|
-
// request body (as json) to the `handleRequestBody` function.
|
|
81
|
-
nock(baseUrl)
|
|
82
|
-
.persist()
|
|
83
|
-
.post(/.*/)
|
|
84
|
-
.reply(200, (_, requestBody) => {
|
|
85
|
-
handleRequestBody(requestBody)
|
|
86
|
-
})
|
|
87
|
-
})
|
|
88
|
-
})
|
|
74
|
+
## Testkit API
|
|
89
75
|
|
|
90
|
-
|
|
91
|
-
const err = new Error('error to look for')
|
|
76
|
+
See full API description and documentation here: https://wix.github.io/sentry-testkit/
|
|
92
77
|
|
|
93
|
-
|
|
78
|
+
## Running in browser
|
|
94
79
|
|
|
95
|
-
|
|
96
|
-
expect(report).toBeDefined()
|
|
97
|
-
})
|
|
98
|
-
```
|
|
80
|
+
`sentry-testkit` relies on `express` and `http` packages from NodeJS. We have separated entry `sentry-testkit/browser` where we not include any NodeJS-related code.
|
|
99
81
|
|
|
100
|
-
## Yes! We 💙 [Puppeteer](https://pptr.dev/)
|
|
101
82
|
```javascript
|
|
102
|
-
const sentryTestkit = require('sentry-testkit')
|
|
103
|
-
|
|
104
|
-
const {testkit} = sentryTestkit()
|
|
105
|
-
|
|
106
|
-
testkit.puppeteer.startListening(page);
|
|
107
|
-
|
|
108
|
-
// Run any scenario that will call Sentry.captureException(...), for example:
|
|
109
|
-
await page.addScriptTag({ content: `throw new Error('An error');` });
|
|
110
|
-
|
|
111
|
-
expect(testKit.reports()).toHaveLength(1)
|
|
112
|
-
const report = testKit.reports()[0]
|
|
113
|
-
expect(report).toHaveProperty(...)
|
|
83
|
+
const sentryTestkit = require('sentry-testkit/browser')
|
|
114
84
|
|
|
115
|
-
testkit
|
|
85
|
+
const { testkit } = sentryTestkit()
|
|
86
|
+
// Your code for browser
|
|
116
87
|
```
|
|
117
88
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
## Test Kit API
|
|
121
|
-
See full API description and documentation here: https://wix.github.io/sentry-testkit/
|
|
89
|
+
## Raven-Testkit
|
|
90
|
+
The good old legacy `raven-testkit` documentation can be found [here](LEGACY_API.md). It it still there to serve `Raven` which is the old legacy SDK of _Sentry_ for JavaScript/Node.js platforms
|
|
122
91
|
|
|
123
|
-
##
|
|
124
|
-
|
|
125
|
-
`sentry-testkit` have full support in both `@sentry/browser` and `@sentry/node` since they have the same API and lifecycle under the hood.
|
|
92
|
+
## Change Log
|
|
93
|
+
We're constantly and automatically updating our [CHANGELOG](./CHANGELOG.md) file, so its always a good spot to checkout what have we been up to...
|
|
126
94
|
|
|
127
|
-
##
|
|
128
|
-
|
|
95
|
+
## Contribution
|
|
96
|
+
We'd love any kind of contribution, to get better, improve our capabilities, fix bugs and bring more features as Sentry expanding their tools as well. Please check our [CONTRIBUTING](./CONTRIBUTING.md) guidelines for more info and how to get started.
|
|
129
97
|
|
|
130
|
-
##
|
|
131
|
-
`sentry-testkit` relies on `express` and `http` packages from NodeJS. We have separated entry `sentry-testkit/browser` where we not include any NodeJS-related code.
|
|
132
|
-
```javascript
|
|
133
|
-
const sentryTestkit = require('sentry-testkit/browser');
|
|
98
|
+
## License
|
|
134
99
|
|
|
135
|
-
|
|
136
|
-
// Your code for browser
|
|
137
|
-
```
|
|
100
|
+
Sentry Testkit is [MIT licensed](./LICENSE).
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sentry-testkit",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Sentry Testkit enables Sentry to work natively in your application while running tests. The report is not really sent but rather logged locally into memory. In this way, the logged reports can be fetched for your own verification or any other purpose in your local development environment.",
|
|
5
|
-
"main": "dist/index
|
|
6
|
-
"types": "index
|
|
5
|
+
"main": "dist/index",
|
|
6
|
+
"types": "dist/index",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist",
|
|
9
9
|
"index.d.ts"
|