rsnext/test/integration/relay-analytics/test/index.test.js
Prateek Bhatnagar 1fe6e9bb1c switches analytics relay test from dev to prod (#10017)
* switches analytics relay test from dev to prod

* Update test/integration/relay-analytics/test/index.test.js

Co-Authored-By: Joe Haddad <joe.haddad@zeit.co>

Co-authored-by: Joe Haddad <timer150@gmail.com>
2020-01-09 20:40:26 +01:00

42 lines
1.3 KiB
JavaScript

/* eslint-env jest */
/* global jasmine */
import { join } from 'path'
import webdriver from 'next-webdriver'
import { killApp, findPort, nextBuild, nextStart } from 'next-test-utils'
const appDir = join(__dirname, '../')
let appPort
let server
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
describe('Analytics relayer', () => {
beforeAll(async () => {
appPort = await findPort()
await nextBuild(appDir)
server = await nextStart(appDir, appPort)
})
afterAll(() => killApp(server))
it('Relays the data to user code', async () => {
const browser = await webdriver(appPort, '/')
await browser.waitForElementByCss('h1')
const h1Text = await browser.elementByCss('h1').text()
const data = parseFloat(
await browser.eval('localStorage.getItem("Next.js-hydration")')
)
const firstPaint = parseFloat(
await browser.eval('localStorage.getItem("first-paint")')
)
const firstContentfulPaint = parseFloat(
await browser.eval('localStorage.getItem("first-contentful-paint")')
)
expect(h1Text).toMatch(/Hello!/)
expect(data).not.toBeNaN()
expect(data).toBeGreaterThan(0)
expect(firstPaint).not.toBeNaN()
expect(firstPaint).toBeGreaterThan(0)
expect(firstContentfulPaint).not.toBeNaN()
expect(firstContentfulPaint).toBeGreaterThan(0)
await browser.close()
})
})