-
-
Notifications
You must be signed in to change notification settings - Fork 359
feat(core): Add environment option to Expo config plugin
#5796
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
8 commits
Select commit
Hold shift + click to select a range
9fd70e2
feat(core): Add `environment` option to Expo config plugin
antonis 0f2c0a8
docs: Add changelog for environment config plugin option
antonis 1e4276a
feat(core): Support SENTRY_ENVIRONMENT env variable in Expo config pl…
antonis de127d0
docs: Simplify changelog entry
antonis 11d7d1a
docs: Add example to changelog entry
antonis f2ac306
Merge branch 'main' into antonis/sentry-options-env
antonis 1e22837
fix(core): Address review feedback for environment config plugin option
antonis caeb51e
Lint: remove uneeded line
antonis 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
60 changes: 60 additions & 0 deletions
60
packages/core/test/expo-plugin/writeSentryOptionsEnvironment.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,60 @@ | ||
| import * as fs from 'fs'; | ||
| import * as os from 'os'; | ||
| import * as path from 'path'; | ||
| import { writeSentryOptionsEnvironment } from '../../plugin/src/utils'; | ||
|
|
||
| jest.mock('../../plugin/src/logger'); | ||
|
|
||
| describe('writeSentryOptionsEnvironment', () => { | ||
| 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 with environment when file does not exist', () => { | ||
| writeSentryOptionsEnvironment(tempDir, 'staging'); | ||
|
|
||
| const filePath = path.join(tempDir, 'sentry.options.json'); | ||
| const content = JSON.parse(fs.readFileSync(filePath, 'utf8')); | ||
| expect(content).toEqual({ environment: 'staging' }); | ||
| }); | ||
|
|
||
| test('sets environment in 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' })); | ||
|
|
||
| writeSentryOptionsEnvironment(tempDir, 'staging'); | ||
|
|
||
| const content = JSON.parse(fs.readFileSync(filePath, 'utf8')); | ||
| expect(content.environment).toBe('staging'); | ||
| expect(content.dsn).toBe('https://key@sentry.io/123'); | ||
| }); | ||
|
|
||
| test('adds environment to existing sentry.options.json without environment', () => { | ||
| const filePath = path.join(tempDir, 'sentry.options.json'); | ||
| fs.writeFileSync(filePath, JSON.stringify({ dsn: 'https://key@sentry.io/123' })); | ||
|
|
||
| writeSentryOptionsEnvironment(tempDir, 'staging'); | ||
|
|
||
| const content = JSON.parse(fs.readFileSync(filePath, 'utf8')); | ||
| expect(content.environment).toBe('staging'); | ||
| expect(content.dsn).toBe('https://key@sentry.io/123'); | ||
| }); | ||
|
|
||
| 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{{{'); | ||
|
|
||
| writeSentryOptionsEnvironment(tempDir, 'staging'); | ||
|
|
||
| expect(warnOnce).toHaveBeenCalledWith(expect.stringContaining('Failed to parse')); | ||
| // File should remain unchanged | ||
| expect(fs.readFileSync(filePath, 'utf8')).toBe('invalid json{{{'); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.