-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(astro): Fix import path when using external init files with defau…
…lt path (#10214) Fix a bug in the Astro SDK where specifying an external `sentry.(client|server).config.js` in the default location file would cause a build error. Previously, we checked for a supported file extension and instead of adding an import statement for the path to the file, we'd only add the file extension. So ```js import 'mjs'; // instead of import 'path/to/sentry.client.config.mjs' ``` Fix the filename lookup function and adds a test to cover regressions.
- Loading branch information
Showing
5 changed files
with
51 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
File renamed without changes.
This file contains 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 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,41 @@ | ||
import { vi } from 'vitest'; | ||
|
||
import { sentryAstro } from '../../src/integration'; | ||
|
||
vi.mock('fs', async () => { | ||
const actual = await vi.importActual('fs'); | ||
return { | ||
// @ts-expect-error - just mocking around | ||
...actual, | ||
existsSync: vi.fn(p => p.endsWith('js')), | ||
}; | ||
}); | ||
|
||
const updateConfig = vi.fn(); | ||
const injectScript = vi.fn(); | ||
const config = { | ||
root: new URL('file://path/to/project'), | ||
outDir: new URL('file://path/to/project/out'), | ||
}; | ||
|
||
describe('sentryAstro integration', () => { | ||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('injects client and server init scripts from default paths if they exist', () => { | ||
const integration = sentryAstro({}); | ||
|
||
expect(integration.hooks['astro:config:setup']).toBeDefined(); | ||
|
||
// @ts-expect-error - the hook exists and we only need to pass what we actually use | ||
integration.hooks['astro:config:setup']({ updateConfig, injectScript, config }); | ||
|
||
expect(injectScript).toHaveBeenCalledTimes(2); | ||
expect(injectScript).toHaveBeenCalledWith('page', expect.stringMatching(/^import ".*\/sentry.client.config.js"/)); | ||
expect(injectScript).toHaveBeenCalledWith( | ||
'page-ssr', | ||
expect.stringMatching(/^import ".*\/sentry.server.config.js"/), | ||
); | ||
}); | ||
}); |
This file contains 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