-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from axiomhq/avoid-logging-network-errors
fix: avoid network errors if envVars are not set
- Loading branch information
Showing
9 changed files
with
56 additions
and
10 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
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,27 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
|
||
// clear Axiom env vars | ||
process.env.AXIOM_INGEST_ENDPOINT = ''; | ||
process.env.NEXT_PUBLIC_AXIOM_INGEST_ENDPOINT = ''; | ||
import { NextWebVitalsMetric } from 'next/app'; | ||
import { log } from '../src/logger'; | ||
import { reportWebVitals } from '../src/webVitals'; | ||
|
||
global.fetch = jest.fn() as jest.Mock; | ||
const mockedLog = jest.spyOn(global.console, 'log').mockImplementation(); | ||
|
||
test('sending logs on localhost should fallback to console', () => { | ||
log.info('hello, world!'); | ||
jest.advanceTimersByTime(1000); | ||
expect(fetch).toHaveBeenCalledTimes(0); | ||
expect(mockedLog).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('webVitals should not be sent when envVars are not set', () => { | ||
const metric: NextWebVitalsMetric = { id: '1', startTime: 1234, value: 1, name: 'FCP', label: 'web-vital' }; | ||
reportWebVitals(metric); | ||
jest.advanceTimersByTime(1000); | ||
expect(fetch).toHaveBeenCalledTimes(0); | ||
}); |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
56db98c
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.
Successfully deployed to the following URLs:
next-axiom-example – ./
next-axiom-example-git-main-axiomhq.vercel.app
next-axiom-example-lemon.vercel.app
next-axiom-example-axiomhq.vercel.app