-
Notifications
You must be signed in to change notification settings - Fork 27.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
216 additions
and
1 deletion.
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
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,15 @@ | ||
/* global localStorage */ | ||
/* eslint-disable camelcase */ | ||
import App from 'next/app' | ||
|
||
export default class MyApp extends App {} | ||
|
||
/* | ||
Method is experimental and will eventually be handled in a Next.js plugin | ||
*/ | ||
export function reportWebVitals(data) { | ||
localStorage.setItem( | ||
data.name || data.entryType, | ||
data.value !== undefined ? data.value : data.startTime | ||
) | ||
} |
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,25 @@ | ||
if (typeof navigator !== 'undefined') { | ||
window.__BEACONS = window.__BEACONS || [] | ||
|
||
navigator.sendBeacon = async function () { | ||
const args = await Promise.all( | ||
[...arguments].map((v) => { | ||
if (v instanceof Blob) { | ||
return v.text() | ||
} | ||
return v | ||
}) | ||
) | ||
|
||
window.__BEACONS.push(args) | ||
} | ||
} | ||
|
||
export default () => { | ||
return ( | ||
<div> | ||
<h1>Foo!</h1> | ||
<h2>bar!</h2> | ||
</div> | ||
) | ||
} |
72 changes: 72 additions & 0 deletions
72
test/integration/relay-analytics-disabled/test/index.test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* eslint-env jest */ | ||
|
||
import fs from 'fs-extra' | ||
import { findPort, killApp, nextBuild, nextStart } from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
import path, { join } from 'path' | ||
|
||
const appDir = join(__dirname, '../') | ||
let appPort | ||
let server | ||
jest.setTimeout(1000 * 60 * 2) | ||
|
||
let buildManifest | ||
|
||
describe('Analytics relayer (disabled)', () => { | ||
let stdout | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
;({ stdout } = await nextBuild(appDir, [], { | ||
stdout: true, | ||
})) | ||
buildManifest = require(path.join( | ||
appDir, | ||
'.next/build-manifest.json' | ||
), 'utf8') | ||
server = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(server)) | ||
|
||
it('Does not relay any data', async () => { | ||
const browser = await webdriver(appPort, '/') | ||
await browser.waitForElementByCss('h1') | ||
const h1Text = await browser.elementByCss('h1').text() | ||
const firstContentfulPaint = parseFloat( | ||
await browser.eval('localStorage.getItem("FCP")') | ||
) | ||
|
||
expect(h1Text).toMatch(/Foo!/) | ||
|
||
expect(firstContentfulPaint).not.toBeNaN() | ||
expect(firstContentfulPaint).toBeGreaterThan(0) | ||
|
||
const beacons = (await browser.eval('window.__BEACONS')).map(([, value]) => | ||
Object.fromEntries(new URLSearchParams(value)) | ||
) | ||
|
||
expect(beacons.length).toBe(0) | ||
|
||
expect(stdout).not.toMatch('Next.js Analytics') | ||
|
||
await browser.close() | ||
}) | ||
|
||
it('Does not include the code', async () => { | ||
const pageFiles = [ | ||
...new Set([ | ||
...buildManifest.pages['/'].filter((file) => file.endsWith('.js')), | ||
...buildManifest.pages['/_app'].filter((file) => file.endsWith('.js')), | ||
]), | ||
] | ||
|
||
expect(pageFiles.length).toBeGreaterThan(1) | ||
|
||
for (const pageFile of pageFiles) { | ||
const content = await fs.readFile( | ||
path.join(appDir, '.next', pageFile), | ||
'utf8' | ||
) | ||
expect(content).not.toMatch('vercel-analytics') | ||
} | ||
}) | ||
}) |
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