-
-
Notifications
You must be signed in to change notification settings - Fork 359
feat(core): Generate sentry.options.json from Expo plugin config #5804
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import * as fs from 'fs'; | ||
| import * as os from 'os'; | ||
| import * as path from 'path'; | ||
| import { writeSentryOptions } from '../../plugin/src/utils'; | ||
|
|
||
| jest.mock('../../plugin/src/logger'); | ||
|
|
||
| describe('writeSentryOptions', () => { | ||
| let tempDir: string; | ||
|
|
||
| beforeEach(() => { | ||
| tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'sentry-options-test-')); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| fs.rmSync(tempDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| test('creates sentry.options.json when file does not exist', () => { | ||
| writeSentryOptions(tempDir, { dsn: 'https://key@sentry.io/123', environment: 'staging' }); | ||
|
|
||
| const filePath = path.join(tempDir, 'sentry.options.json'); | ||
| const content = JSON.parse(fs.readFileSync(filePath, 'utf8')); | ||
| expect(content).toEqual({ dsn: 'https://key@sentry.io/123', environment: 'staging' }); | ||
| }); | ||
|
|
||
| test('merges options into existing sentry.options.json', () => { | ||
| const filePath = path.join(tempDir, 'sentry.options.json'); | ||
| fs.writeFileSync(filePath, JSON.stringify({ dsn: 'https://key@sentry.io/123', environment: 'production' })); | ||
|
|
||
| writeSentryOptions(tempDir, { environment: 'staging', debug: true }); | ||
|
|
||
| const content = JSON.parse(fs.readFileSync(filePath, 'utf8')); | ||
| expect(content).toEqual({ dsn: 'https://key@sentry.io/123', environment: 'staging', debug: true }); | ||
| }); | ||
|
|
||
| test('plugin options take precedence over existing file values', () => { | ||
| const filePath = path.join(tempDir, 'sentry.options.json'); | ||
| fs.writeFileSync(filePath, JSON.stringify({ dsn: 'https://old@sentry.io/1', debug: false })); | ||
|
|
||
| writeSentryOptions(tempDir, { dsn: 'https://new@sentry.io/2' }); | ||
|
|
||
| const content = JSON.parse(fs.readFileSync(filePath, 'utf8')); | ||
| expect(content.dsn).toBe('https://new@sentry.io/2'); | ||
| expect(content.debug).toBe(false); // preserved from existing file | ||
| }); | ||
|
|
||
| test('does not crash and warns when sentry.options.json contains invalid JSON', () => { | ||
| const { warnOnce } = require('../../plugin/src/logger'); | ||
| const filePath = path.join(tempDir, 'sentry.options.json'); | ||
| fs.writeFileSync(filePath, 'invalid json{{{'); | ||
|
|
||
| writeSentryOptions(tempDir, { environment: 'staging' }); | ||
|
|
||
| expect(warnOnce).toHaveBeenCalledWith(expect.stringContaining('Failed to parse')); | ||
| // File should remain unchanged | ||
| expect(fs.readFileSync(filePath, 'utf8')).toBe('invalid json{{{'); | ||
| }); | ||
|
|
||
| test('writes multiple options at once', () => { | ||
| writeSentryOptions(tempDir, { | ||
| dsn: 'https://key@sentry.io/123', | ||
| debug: true, | ||
| tracesSampleRate: 0.5, | ||
| environment: 'production', | ||
| }); | ||
|
|
||
| const filePath = path.join(tempDir, 'sentry.options.json'); | ||
| const content = JSON.parse(fs.readFileSync(filePath, 'utf8')); | ||
| expect(content).toEqual({ | ||
| dsn: 'https://key@sentry.io/123', | ||
| debug: true, | ||
| tracesSampleRate: 0.5, | ||
| environment: 'production', | ||
| }); | ||
| }); | ||
| }); |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,9 +13,7 @@ | |
| "resizeMode": "contain", | ||
| "backgroundColor": "#ffffff" | ||
| }, | ||
| "assetBundlePatterns": [ | ||
| "**/*" | ||
| ], | ||
| "assetBundlePatterns": ["**/*"], | ||
| "ios": { | ||
| "supportsTablet": true, | ||
| "bundleIdentifier": "io.sentry.expo.sample", | ||
|
|
@@ -46,6 +44,24 @@ | |
| "project": "sentry-react-native", | ||
| "organization": "sentry-sdks", | ||
| "useNativeInit": true, | ||
| "options": { | ||
| "dsn": "https://1df17bd4e543fdb31351dee1768bb679@o447951.ingest.sentry.io/5428561", | ||
| "debug": true, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q: What if the user sets
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of removing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think the native SDK would still be running (initialized by the native entry point), but JS wouldn't talk to it. That's the same outcome you'd get by manually putting enableNative: false in sentry.options.json today.
Good idea 👍 |
||
| "environment": "dev", | ||
| "enableUserInteractionTracing": true, | ||
| "enableAutoSessionTracking": true, | ||
| "sessionTrackingIntervalMillis": 30000, | ||
| "enableTracing": true, | ||
| "tracesSampleRate": 1.0, | ||
| "attachStacktrace": true, | ||
| "attachScreenshot": true, | ||
| "attachViewHierarchy": true, | ||
| "enableCaptureFailedRequests": true, | ||
| "profilesSampleRate": 1.0, | ||
| "replaysSessionSampleRate": 1.0, | ||
| "replaysOnErrorSampleRate": 1.0, | ||
| "spotlight": true | ||
| }, | ||
| "experimental_android": { | ||
| "enableAndroidGradlePlugin": true, | ||
| "autoUploadProguardMapping": true, | ||
|
|
@@ -90,4 +106,4 @@ | |
| "url": "https://u.expo.dev/00000000-0000-0000-0000-000000000000" | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
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.
I wonder why each CI decides to change this format every run
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.
This is an irrelevant formatting thing after running yarn fix locally. I can probably revert it but I guess it will come back
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.
No worries about that, maybe we can set some flag so yarn fix knows how to format these files.
But super low priority for doing that