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
88 lines
3.2 KiB
TypeScript
88 lines
3.2 KiB
TypeScript
/* eslint-env jest */
|
|
import {
|
|
findPageFile,
|
|
createValidFileMatcher,
|
|
} from 'next/dist/server/lib/find-page-file'
|
|
import { normalizePagePath } from 'next/dist/shared/lib/page-path/normalize-page-path'
|
|
import { join } from 'path'
|
|
|
|
const resolveDataDir = join(__dirname, 'isolated', '_resolvedata')
|
|
const dirWithPages = join(resolveDataDir, 'readdir', 'pages')
|
|
|
|
describe('findPageFile', () => {
|
|
it('should work', async () => {
|
|
const pagePath = normalizePagePath('/nav/about')
|
|
const result = await findPageFile(
|
|
dirWithPages,
|
|
pagePath,
|
|
['jsx', 'js'],
|
|
false
|
|
)
|
|
expect(result).toMatch(/^[\\/]nav[\\/]about\.js/)
|
|
})
|
|
|
|
it('should work with nested index.js', async () => {
|
|
const pagePath = normalizePagePath('/nested')
|
|
const result = await findPageFile(
|
|
dirWithPages,
|
|
pagePath,
|
|
['jsx', 'js'],
|
|
false
|
|
)
|
|
expect(result).toMatch(/^[\\/]nested[\\/]index\.js/)
|
|
})
|
|
|
|
it('should prefer prefered.js before preferred/index.js', async () => {
|
|
const pagePath = normalizePagePath('/prefered')
|
|
const result = await findPageFile(
|
|
dirWithPages,
|
|
pagePath,
|
|
['jsx', 'js'],
|
|
false
|
|
)
|
|
expect(result).toMatch(/^[\\/]prefered\.js/)
|
|
})
|
|
})
|
|
|
|
describe('createPageFileMatcher', () => {
|
|
describe('isAppRouterPage', () => {
|
|
const pageExtensions = ['tsx', 'ts', 'jsx', 'js']
|
|
const fileMatcher = createValidFileMatcher(pageExtensions, '')
|
|
|
|
it('should determine either server or client component page file as leaf node page', () => {
|
|
expect(fileMatcher.isAppRouterPage('page.js')).toBe(true)
|
|
expect(fileMatcher.isAppRouterPage('./page.js')).toBe(true)
|
|
expect(fileMatcher.isAppRouterPage('./page.jsx')).toBe(true)
|
|
expect(fileMatcher.isAppRouterPage('/page.ts')).toBe(true)
|
|
expect(fileMatcher.isAppRouterPage('/path/page.tsx')).toBe(true)
|
|
expect(fileMatcher.isAppRouterPage('\\path\\page.tsx')).toBe(true)
|
|
expect(fileMatcher.isAppRouterPage('.\\page.jsx')).toBe(true)
|
|
expect(fileMatcher.isAppRouterPage('\\page.js')).toBe(true)
|
|
})
|
|
|
|
it('should determine other files under layout routes as non leaf node', () => {
|
|
expect(fileMatcher.isAppRouterPage('./not-a-page.js')).toBe(false)
|
|
expect(fileMatcher.isAppRouterPage('not-a-page.js')).toBe(false)
|
|
expect(fileMatcher.isAppRouterPage('./page.component.jsx')).toBe(false)
|
|
expect(fileMatcher.isAppRouterPage('layout.js')).toBe(false)
|
|
expect(fileMatcher.isAppRouterPage('page')).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('isMetadataRouteFile', () => {
|
|
it('should determine top level metadata routes', () => {
|
|
const pageExtensions = ['tsx', 'ts', 'jsx', 'js']
|
|
const fileMatcher = createValidFileMatcher(pageExtensions, 'app')
|
|
expect(fileMatcher.isMetadataFile('app/route.js')).toBe(false)
|
|
expect(fileMatcher.isMetadataFile('app/page.js')).toBe(false)
|
|
expect(fileMatcher.isMetadataFile('pages/index.js')).toBe(false)
|
|
|
|
expect(fileMatcher.isMetadataFile('app/robots.txt')).toBe(true)
|
|
expect(fileMatcher.isMetadataFile('app/path/robots.txt')).toBe(false)
|
|
|
|
expect(fileMatcher.isMetadataFile('app/sitemap.xml')).toBe(true)
|
|
expect(fileMatcher.isMetadataFile('app/path/sitemap.xml')).toBe(true)
|
|
})
|
|
})
|
|
})
|