005b13f1ac
* Move unit tests to one folder * Migrate unit tests to TypeScript * add test types to lint * Ensure ts(x) tests are run with util * Add tsx extension to jest config * bump
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
/* eslint-env jest */
|
|
import { findPageFile } from 'next/dist/server/lib/find-page-file'
|
|
import { normalizePagePath } from 'next/dist/server/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'])
|
|
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'])
|
|
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'])
|
|
expect(result).toMatch(/^[\\/]prefered\.js/)
|
|
})
|
|
})
|