-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(web): injectSpeedInsights requires a parameter value (#38)
- Loading branch information
Showing
10 changed files
with
732 additions
and
610 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
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import '@testing-library/jest-dom'; | ||
|
||
beforeEach(() => { | ||
// reset dom before each test | ||
document.getElementsByTagName('html')[0].innerHTML = ''; | ||
if ('document' in global) { | ||
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- there is an HTML element */ | ||
document.querySelector('html')!.innerHTML = ''; | ||
} | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** @jest-environment node */ | ||
import { injectSpeedInsights } from './generic'; | ||
|
||
describe('injectSpeedInsights()', () => { | ||
it('does nothing in a server environment', () => { | ||
expect(injectSpeedInsights({})).toBe(null); | ||
}); | ||
}); |
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,33 @@ | ||
import { injectSpeedInsights } from './generic'; | ||
|
||
describe('injectSpeedInsights()', () => { | ||
it('allows no parameters', () => { | ||
expect(injectSpeedInsights()).toEqual({ | ||
setRoute: expect.any(Function) as () => void, | ||
}); | ||
expectInjectedScript(); | ||
}); | ||
|
||
it('can set framework', () => { | ||
const framework = 'sveltekit'; | ||
expect(injectSpeedInsights({ framework })).toEqual({ | ||
setRoute: expect.any(Function) as () => void, | ||
}); | ||
expectInjectedScript({ framework }); | ||
}); | ||
}); | ||
|
||
function expectInjectedScript({ | ||
src = 'https://va.vercel-scripts.com/v1/speed-insights/script.debug.js', | ||
framework = '', | ||
} = {}): void { | ||
const candidateScript = document.querySelector('script'); | ||
expect(candidateScript).toBeDefined(); | ||
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- the previous assertion fails otherwise */ | ||
const script = candidateScript!; | ||
expect(script.defer).toBe(true); | ||
expect(script.src).toBe(src); | ||
expect(script.dataset.sdkn).toBe( | ||
`@vercel/speed-insights${framework ? `/${framework}` : ''}`, | ||
); | ||
} |
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
Oops, something went wrong.
2435e08
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:
speed-insights-vue – ./apps/vue
speed-insights-vue.vercel.app
speed-insights-vue-vercel-analytics.vercel.app
speed-insights-vue-git-main-vercel-analytics.vercel.app
2435e08
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:
speed-insights-nuxt – ./apps/nuxt
speed-insights-nuxt.vercel.app
speed-insights-nuxt-git-main-vercel-analytics.vercel.app
speed-insights-nuxt-vercel-analytics.vercel.app
2435e08
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:
speed-insights-remix – ./apps/remix
speed-insights-remix-git-main-vercel-analytics.vercel.app
speed-insights-remix.vercel.app
speed-insights-remix-vercel-analytics.vercel.app
2435e08
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:
speed-insights-astro – ./apps/astro
speed-insights-astro-git-main-vercel-analytics.vercel.app
speed-insights-astro-vercel-analytics.vercel.app
speed-insights-astro.vercel.app
2435e08
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:
speed-insights-sveltekit – ./apps/sveltekit
speed-insights-sveltekit-git-main-vercel-analytics.vercel.app
speed-insights-sveltekit-vercel-analytics.vercel.app
speed-insights-sveltekit.vercel.app