Unverified Commit 975fb1f4 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix windows unit tests (#53412)

Fixes differences in tests to handle windows now that we've fixed them
not being run.

x-ref:
https://github.com/vercel/next.js/pull/53408/checks?check_run_id=15501915673
parent 8c6da3f7
import { NextTypesPlugin } from '.'
const normalizeSlashes = (p: string) => p.replace(/\\/g, '/')
describe('next-types-plugin', () => {
it('should generate correct base import path', () => {
const plugin = new NextTypesPlugin({
......@@ -13,17 +15,19 @@ describe('next-types-plugin', () => {
originalRewrites: undefined,
originalRedirects: undefined,
})
expect(plugin.getRelativePathFromAppTypesDir('page.tsx')).toEqual(
'../../../app/page.tsx'
)
expect(plugin.getRelativePathFromAppTypesDir('layout.tsx')).toEqual(
'../../../app/layout.tsx'
)
expect(plugin.getRelativePathFromAppTypesDir('test/page.tsx')).toEqual(
'../../../../app/test/page.tsx'
)
expect(
plugin.getRelativePathFromAppTypesDir('deeply/nested/page.tsx')
normalizeSlashes(plugin.getRelativePathFromAppTypesDir('page.tsx'))
).toEqual('../../../app/page.tsx')
expect(
normalizeSlashes(plugin.getRelativePathFromAppTypesDir('layout.tsx'))
).toEqual('../../../app/layout.tsx')
expect(
normalizeSlashes(plugin.getRelativePathFromAppTypesDir('test/page.tsx'))
).toEqual('../../../../app/test/page.tsx')
expect(
normalizeSlashes(
plugin.getRelativePathFromAppTypesDir('deeply/nested/page.tsx')
)
).toEqual('../../../../../app/deeply/nested/page.tsx')
})
......@@ -39,12 +43,12 @@ describe('next-types-plugin', () => {
originalRewrites: undefined,
originalRedirects: undefined,
})
expect(plugin.getRelativePathFromAppTypesDir('layout.tsx')).toEqual(
'../../../../../../apps/myproject/app/layout.tsx'
)
expect(plugin.getRelativePathFromAppTypesDir('test/page.tsx')).toEqual(
'../../../../../../../apps/myproject/app/test/page.tsx'
)
expect(
normalizeSlashes(plugin.getRelativePathFromAppTypesDir('layout.tsx'))
).toEqual('../../../../../../apps/myproject/app/layout.tsx')
expect(
normalizeSlashes(plugin.getRelativePathFromAppTypesDir('test/page.tsx'))
).toEqual('../../../../../../../apps/myproject/app/test/page.tsx')
})
it('should generate correct base import path for custom projects', () => {
......@@ -59,11 +63,11 @@ describe('next-types-plugin', () => {
originalRewrites: undefined,
originalRedirects: undefined,
})
expect(plugin.getRelativePathFromAppTypesDir('layout.tsx')).toEqual(
'../../../../../ui/app/layout.tsx'
)
expect(plugin.getRelativePathFromAppTypesDir('test/page.tsx')).toEqual(
'../../../../../../ui/app/test/page.tsx'
)
expect(
normalizeSlashes(plugin.getRelativePathFromAppTypesDir('layout.tsx'))
).toEqual('../../../../../ui/app/layout.tsx')
expect(
normalizeSlashes(plugin.getRelativePathFromAppTypesDir('test/page.tsx'))
).toEqual('../../../../../../ui/app/test/page.tsx')
})
})
import path from 'path'
import { PagesAPIRouteDefinition } from '../../route-definitions/pages-api-route-definition'
import { RouteKind } from '../../route-kind'
import { DevPagesAPIRouteMatcherProvider } from './dev-pages-api-route-matcher-provider'
import { FileReader } from './helpers/file-reader/file-reader'
const normalizeSlashes = (p: string) => p.replace(/\//g, path.sep)
describe('DevPagesAPIRouteMatcherProvider', () => {
const dir = '<root>'
const extensions = ['ts', 'tsx', 'js', 'jsx']
......@@ -21,41 +24,41 @@ describe('DevPagesAPIRouteMatcherProvider', () => {
route: PagesAPIRouteDefinition
}>([
{
files: [`${dir}/api/other/route.ts`],
files: [normalizeSlashes(`${dir}/api/other/route.ts`)],
route: {
kind: RouteKind.PAGES_API,
pathname: '/api/other/route',
filename: `${dir}/api/other/route.ts`,
filename: normalizeSlashes(`${dir}/api/other/route.ts`),
page: '/api/other/route',
bundlePath: 'pages/api/other/route',
},
},
{
files: [`${dir}/api/other/index.ts`],
files: [normalizeSlashes(`${dir}/api/other/index.ts`)],
route: {
kind: RouteKind.PAGES_API,
pathname: '/api/other',
filename: `${dir}/api/other/index.ts`,
filename: normalizeSlashes(`${dir}/api/other/index.ts`),
page: '/api/other',
bundlePath: 'pages/api/other',
},
},
{
files: [`${dir}/api.ts`],
files: [normalizeSlashes(`${dir}/api.ts`)],
route: {
kind: RouteKind.PAGES_API,
pathname: '/api',
filename: `${dir}/api.ts`,
filename: normalizeSlashes(`${dir}/api.ts`),
page: '/api',
bundlePath: 'pages/api',
},
},
{
files: [`${dir}/api/index.ts`],
files: [normalizeSlashes(`${dir}/api/index.ts`)],
route: {
kind: RouteKind.PAGES_API,
pathname: '/api',
filename: `${dir}/api/index.ts`,
filename: normalizeSlashes(`${dir}/api/index.ts`),
page: '/api',
bundlePath: 'pages/api',
},
......
import path from 'path'
import { PagesRouteDefinition } from '../../route-definitions/pages-route-definition'
import { RouteKind } from '../../route-kind'
import { DevPagesRouteMatcherProvider } from './dev-pages-route-matcher-provider'
import { FileReader } from './helpers/file-reader/file-reader'
const normalizeSlashes = (p: string) => p.replace(/\//g, path.sep)
describe('DevPagesRouteMatcherProvider', () => {
const dir = '<root>'
const extensions = ['ts', 'tsx', 'js', 'jsx']
......@@ -21,41 +24,41 @@ describe('DevPagesRouteMatcherProvider', () => {
route: PagesRouteDefinition
}>([
{
files: [`${dir}/index.ts`],
files: [normalizeSlashes(`${dir}/index.ts`)],
route: {
kind: RouteKind.PAGES,
pathname: '/',
filename: `${dir}/index.ts`,
filename: normalizeSlashes(`${dir}/index.ts`),
page: '/',
bundlePath: 'pages/index',
},
},
{
files: [`${dir}/some/api/route.ts`],
files: [normalizeSlashes(`${dir}/some/api/route.ts`)],
route: {
kind: RouteKind.PAGES,
pathname: '/some/api/route',
filename: `${dir}/some/api/route.ts`,
filename: normalizeSlashes(`${dir}/some/api/route.ts`),
page: '/some/api/route',
bundlePath: 'pages/some/api/route',
},
},
{
files: [`${dir}/some/other/route/index.ts`],
files: [normalizeSlashes(`${dir}/some/other/route/index.ts`)],
route: {
kind: RouteKind.PAGES,
pathname: '/some/other/route',
filename: `${dir}/some/other/route/index.ts`,
filename: normalizeSlashes(`${dir}/some/other/route/index.ts`),
page: '/some/other/route',
bundlePath: 'pages/some/other/route',
},
},
{
files: [`${dir}/some/other/route/index/route.ts`],
files: [normalizeSlashes(`${dir}/some/other/route/index/route.ts`)],
route: {
kind: RouteKind.PAGES,
pathname: '/some/other/route/index/route',
filename: `${dir}/some/other/route/index/route.ts`,
filename: normalizeSlashes(`${dir}/some/other/route/index/route.ts`),
page: '/some/other/route/index/route',
bundlePath: 'pages/some/other/route/index/route',
},
......@@ -65,7 +68,9 @@ describe('DevPagesRouteMatcherProvider', () => {
async ({ files, route }) => {
const reader: FileReader = {
read: jest.fn(() => [
...extensions.map((ext) => `${dir}/api/other/page.${ext}`),
...extensions.map((ext) =>
normalizeSlashes(`${dir}/api/other/page.${ext}`)
),
...files,
]),
}
......
......@@ -40,6 +40,10 @@ const setupTestDir = async (numFiles = 100) => {
}
describe('recursiveCopy', () => {
if (process.platform === 'win32') {
it('should skip on windows to avoid symlink issues', () => {})
return
}
afterAll(() => fs.remove(testDir))
it('should work', async () => {
......
......@@ -10,6 +10,11 @@ const testResolveDataDir = join(__dirname, 'isolated', 'test_resolvedata')
const testpreservefileDir = join(__dirname, 'isolated', 'preservefiles')
describe('recursiveDelete', () => {
if (process.platform === 'win32') {
it('should skip on windows to avoid symlink issues', () => {})
return
}
it('should work', async () => {
expect.assertions(1)
try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment