Skip to content

Commit 7c1c937

Browse files
committed
set angular SDK data globally
1 parent ba80e9d commit 7c1c937

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

packages/angular/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,32 @@
5353
"fix": "run-s fix:eslint fix:prettier",
5454
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
5555
"fix:eslint": "eslint . --format stylish --fix",
56+
"test": "jest",
57+
"test:watch": "jest --watch",
5658
"pack": "npm pack"
5759
},
5860
"volta": {
5961
"extends": "../../package.json"
6062
},
63+
"jest": {
64+
"collectCoverage": true,
65+
"transform": {
66+
"^.+\\.ts$": "ts-jest"
67+
},
68+
"moduleFileExtensions": [
69+
"js",
70+
"ts"
71+
],
72+
"testEnvironment": "jsdom",
73+
"testMatch": [
74+
"**/*.test.ts"
75+
],
76+
"globals": {
77+
"ts-jest": {
78+
"tsConfig": "./tsconfig.json",
79+
"diagnostics": false
80+
}
81+
}
82+
},
6183
"sideEffects": false
6284
}

packages/angular/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { SDK_VERSION } from '@sentry/browser';
2+
import { setSDKInfo } from '@sentry/utils';
3+
14
export * from '@sentry/browser';
25
export { createErrorHandler, ErrorHandlerOptions } from './errorhandler';
36
export {
@@ -8,3 +11,5 @@ export {
811
TraceDirective,
912
TraceService,
1013
} from './tracing';
14+
15+
setSDKInfo('sentry.javascript.angular', 'npm:@sentry/angular', SDK_VERSION);

packages/angular/test/init.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { getGlobalObject } from '@sentry/utils';
2+
3+
import * as Sentry from '../src/index';
4+
5+
const global = getGlobalObject<Window>();
6+
7+
describe('global SDK metadata', () => {
8+
it('sets correct SDK data', () => {
9+
// the SDK data is set when we import from (and therefore run) `../src/index.ts` - it sets the angular part itself,
10+
// and the browser part gets set when it imports from @sentry/browser - so no action is necessary here before we run
11+
// the `expect`s
12+
13+
expect(global.__SENTRY__?.sdkInfo).toBeDefined();
14+
expect(global.__SENTRY__?.sdkInfo?.name).toEqual('sentry.javascript.angular');
15+
expect(global.__SENTRY__?.sdkInfo?.version).toEqual(Sentry.SDK_VERSION);
16+
expect(global.__SENTRY__?.sdkInfo?.packages).toEqual(
17+
expect.arrayContaining([
18+
{ name: 'npm:@sentry/angular', version: Sentry.SDK_VERSION },
19+
{ name: 'npm:@sentry/browser', version: Sentry.SDK_VERSION },
20+
]),
21+
);
22+
});
23+
});

packages/angular/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"extends": "./tsconfig.build.json",
3-
"include": ["src/**/*.ts"],
3+
"include": ["src/**/*.ts", "test/**/*.ts"],
44
"exclude": ["dist"],
55
"compilerOptions": {
6-
"rootDir": "."
6+
"rootDir": ".",
7+
"types": ["jest"]
78
}
89
}

0 commit comments

Comments
 (0)