-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(node): Add Node SDK integration test structure. #4694
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
55b28c8
test(node): Add Node SDK integration test structure.
onurtemizkan ebf7d5c
Add local version of `jest-environment-node`.
onurtemizkan 1f4ada7
Remove local `jest` version, use global.
onurtemizkan 4786db0
Update version to current master.
onurtemizkan ae36d26
Add `filename` and `release` to replaced keys.
onurtemizkan 9607f9a
Remove `@sentry-internal/node-integration-tests` from base test script.
onurtemizkan 58d2eab
Remove `release` from replace list.
onurtemizkan d191537
Add `version` and `lineno` to replace list.
onurtemizkan 37a3387
Set `release` in test scenarios.
onurtemizkan d8ed981
Update TS configuration.
onurtemizkan d53e4c6
Use, TS source of packages instead of builds.
onurtemizkan ee63243
Merge `init` and `subject` into `scenario`, add a default `server`.
onurtemizkan 54f658e
Remove stale babel and jest configurations.
onurtemizkan 8feb87c
Remove snapshot testing.
onurtemizkan 840525f
Add a manual tracing test.
onurtemizkan 4b4eae7
Follow folder structure of browser tests for public api tests.
onurtemizkan 4d9b216
Add unnamed / named import test scenarios for tracing package.
onurtemizkan 21c3545
Update envelope parser.
onurtemizkan 49ab765
Skip namespace import test case.
onurtemizkan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
module.exports = { | ||
env: { | ||
node: true, | ||
jest: true, | ||
}, | ||
extends: ['../../.eslintrc.js'], | ||
parserOptions: { | ||
sourceType: 'module', | ||
}, | ||
}; |
This file contains hidden or 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,10 @@ | ||
const config = { | ||
transform: { | ||
'^.+\\.ts$': 'ts-jest', | ||
}, | ||
testEnvironment: 'node', | ||
testMatch: ['**/test.ts'], | ||
moduleFileExtensions: ['js', 'ts'], | ||
}; | ||
|
||
module.exports = config; |
This file contains hidden or 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,21 @@ | ||
{ | ||
"name": "@sentry-internal/node-integration-tests", | ||
"version": "6.18.2", | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=10" | ||
}, | ||
"private": true, | ||
"scripts": { | ||
"lint": "run-s lint:prettier lint:eslint", | ||
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish", | ||
"lint:prettier": "prettier --check \"{suites,utils}/**/*.ts\"", | ||
"type-check": "tsc", | ||
"test": "jest --detectOpenHandles --runInBand --forceExit" | ||
}, | ||
"dependencies": { | ||
"express": "^4.17.3", | ||
"nock": "^13.1.0", | ||
"portfinder": "^1.0.28" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/node-integration-tests/suites/public-api/capture-exception/scenario.ts
This file contains hidden or 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,8 @@ | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
}); | ||
|
||
Sentry.captureException(new Error('Captured Error')); |
17 changes: 17 additions & 0 deletions
17
packages/node-integration-tests/suites/public-api/capture-exception/test.ts
This file contains hidden or 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,17 @@ | ||
import { assertSentryEvent, getEventRequest, runServer } from '../../../utils'; | ||
|
||
test('should send captureException', async () => { | ||
const url = await runServer(__dirname); | ||
const requestBody = await getEventRequest(url); | ||
|
||
assertSentryEvent(requestBody, { | ||
exception: { | ||
values: [ | ||
{ | ||
type: 'Error', | ||
value: 'Captured Error', | ||
}, | ||
], | ||
}, | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/node-integration-tests/suites/public-api/capture-message/scenario.ts
This file contains hidden or 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,8 @@ | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
}); | ||
|
||
Sentry.captureMessage('Message'); |
11 changes: 11 additions & 0 deletions
11
packages/node-integration-tests/suites/public-api/capture-message/test.ts
This file contains hidden or 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,11 @@ | ||
import { assertSentryEvent, getEventRequest, runServer } from '../../../utils'; | ||
|
||
test('should send captureMessage', async () => { | ||
const url = await runServer(__dirname); | ||
const requestBody = await getEventRequest(url); | ||
|
||
assertSentryEvent(requestBody, { | ||
message: 'Message', | ||
level: 'info', | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
packages/node-integration-tests/suites/tracing/manual-tracing-namespace-import/scenario.ts
This file contains hidden or 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,12 @@ | ||
import * as Sentry from '@sentry/node'; | ||
import * as _ from '@sentry/tracing'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
}); | ||
|
||
const transaction = Sentry.startTransaction({ name: 'test_transaction_1' }); | ||
|
||
transaction.finish(); |
12 changes: 12 additions & 0 deletions
12
packages/node-integration-tests/suites/tracing/manual-tracing-namespace-import/test.ts
This file contains hidden or 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,12 @@ | ||
import { assertSentryTransaction, getEnvelopeRequest, runServer } from '../../../utils'; | ||
|
||
test.skip('should send a manually started transaction when @sentry/tracing is imported using namespace import.', async () => { | ||
const url = await runServer(__dirname); | ||
const envelope = await getEnvelopeRequest(url); | ||
|
||
expect(envelope).toHaveLength(3); | ||
|
||
assertSentryTransaction(envelope[2], { | ||
transaction: 'test_transaction_1', | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
packages/node-integration-tests/suites/tracing/manual-tracing-unnamed-import/scenario.ts
This file contains hidden or 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,14 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import '@sentry/tracing'; | ||
|
||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
}); | ||
|
||
const transaction = Sentry.startTransaction({ name: 'test_transaction_1' }); | ||
|
||
transaction.finish(); |
12 changes: 12 additions & 0 deletions
12
packages/node-integration-tests/suites/tracing/manual-tracing-unnamed-import/test.ts
This file contains hidden or 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,12 @@ | ||
import { assertSentryTransaction, getEnvelopeRequest, runServer } from '../../../utils'; | ||
|
||
test('should send a manually started transaction when @sentry/tracing is imported using unnamed import.', async () => { | ||
const url = await runServer(__dirname); | ||
const envelope = await getEnvelopeRequest(url); | ||
|
||
expect(envelope).toHaveLength(3); | ||
|
||
assertSentryTransaction(envelope[2], { | ||
transaction: 'test_transaction_1', | ||
}); | ||
}); |
This file contains hidden or 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,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"esModuleInterop": true, | ||
"types": ["jest", "node"] | ||
}, | ||
"include": ["**/*.ts", "jest.config.js"], | ||
"exclude": ["node_modules"] | ||
} |
This file contains hidden or 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,5 @@ | ||
import express from 'express'; | ||
|
||
const app = express(); | ||
|
||
export default app; |
This file contains hidden or 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,81 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
import { Express } from 'express'; | ||
import * as http from 'http'; | ||
import nock from 'nock'; | ||
import * as path from 'path'; | ||
import { getPortPromise } from 'portfinder'; | ||
|
||
const assertSentryEvent = (actual: Record<string, unknown>, expected: Record<string, unknown>): void => { | ||
expect(actual).toMatchObject({ | ||
event_id: expect.any(String), | ||
timestamp: expect.any(Number), | ||
...expected, | ||
}); | ||
}; | ||
|
||
const assertSentryTransaction = (actual: Record<string, unknown>, expected: Record<string, unknown>): void => { | ||
expect(actual).toMatchObject({ | ||
event_id: expect.any(String), | ||
timestamp: expect.any(Number), | ||
start_timestamp: expect.any(Number), | ||
spans: expect.any(Array), | ||
type: 'transaction', | ||
...expected, | ||
}); | ||
}; | ||
|
||
const parseEnvelope = (body: string): Array<Record<string, unknown>> => { | ||
return body.split('\n').map(e => JSON.parse(e)); | ||
}; | ||
|
||
const getEventRequest = async (url: string): Promise<Record<string, unknown>> => { | ||
return new Promise(resolve => { | ||
nock('https://dsn.ingest.sentry.io') | ||
.post('/api/1337/store/', body => { | ||
resolve(body); | ||
return true; | ||
}) | ||
.reply(200); | ||
|
||
http.get(url); | ||
}); | ||
}; | ||
|
||
const getEnvelopeRequest = async (url: string): Promise<Array<Record<string, unknown>>> => { | ||
return new Promise(resolve => { | ||
nock('https://dsn.ingest.sentry.io') | ||
.post('/api/1337/envelope/', body => { | ||
const envelope = parseEnvelope(body); | ||
resolve(envelope); | ||
return true; | ||
}) | ||
.reply(200); | ||
|
||
http.get(url); | ||
}); | ||
}; | ||
|
||
async function runServer(testDir: string, serverPath?: string, scenarioPath?: string): Promise<string> { | ||
const port = await getPortPromise(); | ||
const url = `http://localhost:${port}/test`; | ||
const defaultServerPath = path.resolve(process.cwd(), 'utils', 'defaults', 'server'); | ||
|
||
await new Promise(resolve => { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-member-access | ||
const app = require(serverPath || defaultServerPath).default as Express; | ||
|
||
app.get('/test', async () => { | ||
require(scenarioPath || `${testDir}/scenario`); | ||
|
||
setTimeout(() => server.close(), 500); | ||
}); | ||
|
||
const server = app.listen(port, () => { | ||
resolve(); | ||
}); | ||
}); | ||
|
||
return url; | ||
} | ||
|
||
export { assertSentryEvent, assertSentryTransaction, parseEnvelope, getEventRequest, getEnvelopeRequest, runServer }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skipping this test for now, we can re-enable it with the PR to fix #4731.