Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
/**
|
|
* @jest-environment @edge-runtime/jest-environment
|
|
*/
|
|
|
|
import { userAgentFromString, userAgent, NextRequest } from 'next/server'
|
|
|
|
const UA_STRING =
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36'
|
|
|
|
it('parse an user agent', () => {
|
|
const parser = userAgentFromString(UA_STRING)
|
|
expect(parser.ua).toBe(
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36'
|
|
)
|
|
expect(parser.browser).toStrictEqual({
|
|
name: 'Chrome',
|
|
version: '89.0.4389.90',
|
|
major: '89',
|
|
})
|
|
expect(parser.engine).toStrictEqual({
|
|
name: 'Blink',
|
|
version: '89.0.4389.90',
|
|
})
|
|
expect(parser.os).toStrictEqual({ name: 'Mac OS', version: '11.2.3' })
|
|
expect(parser.cpu).toStrictEqual({ architecture: undefined })
|
|
expect(parser.isBot).toBe(false)
|
|
})
|
|
|
|
it('parse empty user agent', () => {
|
|
expect.assertions(3)
|
|
for (const input of [undefined, null, '']) {
|
|
expect(userAgentFromString(input)).toStrictEqual({
|
|
ua: '',
|
|
browser: { name: undefined, version: undefined, major: undefined },
|
|
engine: { name: undefined, version: undefined },
|
|
os: { name: undefined, version: undefined },
|
|
device: { vendor: undefined, model: undefined, type: undefined },
|
|
cpu: { architecture: undefined },
|
|
isBot: false,
|
|
})
|
|
}
|
|
})
|
|
|
|
it('parse user agent from a NextRequest instance', () => {
|
|
const request = new NextRequest('https://vercel.com', {
|
|
headers: {
|
|
'user-agent': UA_STRING,
|
|
},
|
|
})
|
|
|
|
expect(userAgent(request)).toStrictEqual({
|
|
ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36',
|
|
browser: { name: 'Chrome', version: '89.0.4389.90', major: '89' },
|
|
engine: { name: 'Blink', version: '89.0.4389.90' },
|
|
os: { name: 'Mac OS', version: '11.2.3' },
|
|
device: { vendor: 'Apple', model: 'Macintosh', type: undefined },
|
|
cpu: { architecture: undefined },
|
|
isBot: false,
|
|
})
|
|
})
|