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 '.' import { NextTypesPlugin } from '.'
const normalizeSlashes = (p: string) => p.replace(/\\/g, '/')
describe('next-types-plugin', () => { describe('next-types-plugin', () => {
it('should generate correct base import path', () => { it('should generate correct base import path', () => {
const plugin = new NextTypesPlugin({ const plugin = new NextTypesPlugin({
...@@ -13,17 +15,19 @@ describe('next-types-plugin', () => { ...@@ -13,17 +15,19 @@ describe('next-types-plugin', () => {
originalRewrites: undefined, originalRewrites: undefined,
originalRedirects: 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( 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') ).toEqual('../../../../../app/deeply/nested/page.tsx')
}) })
...@@ -39,12 +43,12 @@ describe('next-types-plugin', () => { ...@@ -39,12 +43,12 @@ describe('next-types-plugin', () => {
originalRewrites: undefined, originalRewrites: undefined,
originalRedirects: undefined, originalRedirects: undefined,
}) })
expect(plugin.getRelativePathFromAppTypesDir('layout.tsx')).toEqual( expect(
'../../../../../../apps/myproject/app/layout.tsx' normalizeSlashes(plugin.getRelativePathFromAppTypesDir('layout.tsx'))
) ).toEqual('../../../../../../apps/myproject/app/layout.tsx')
expect(plugin.getRelativePathFromAppTypesDir('test/page.tsx')).toEqual( expect(
'../../../../../../../apps/myproject/app/test/page.tsx' normalizeSlashes(plugin.getRelativePathFromAppTypesDir('test/page.tsx'))
) ).toEqual('../../../../../../../apps/myproject/app/test/page.tsx')
}) })
it('should generate correct base import path for custom projects', () => { it('should generate correct base import path for custom projects', () => {
...@@ -59,11 +63,11 @@ describe('next-types-plugin', () => { ...@@ -59,11 +63,11 @@ describe('next-types-plugin', () => {
originalRewrites: undefined, originalRewrites: undefined,
originalRedirects: undefined, originalRedirects: undefined,
}) })
expect(plugin.getRelativePathFromAppTypesDir('layout.tsx')).toEqual( expect(
'../../../../../ui/app/layout.tsx' normalizeSlashes(plugin.getRelativePathFromAppTypesDir('layout.tsx'))
) ).toEqual('../../../../../ui/app/layout.tsx')
expect(plugin.getRelativePathFromAppTypesDir('test/page.tsx')).toEqual( expect(
'../../../../../../ui/app/test/page.tsx' 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 { PagesAPIRouteDefinition } from '../../route-definitions/pages-api-route-definition'
import { RouteKind } from '../../route-kind' import { RouteKind } from '../../route-kind'
import { DevPagesAPIRouteMatcherProvider } from './dev-pages-api-route-matcher-provider' import { DevPagesAPIRouteMatcherProvider } from './dev-pages-api-route-matcher-provider'
import { FileReader } from './helpers/file-reader/file-reader' import { FileReader } from './helpers/file-reader/file-reader'
const normalizeSlashes = (p: string) => p.replace(/\//g, path.sep)
describe('DevPagesAPIRouteMatcherProvider', () => { describe('DevPagesAPIRouteMatcherProvider', () => {
const dir = '<root>' const dir = '<root>'
const extensions = ['ts', 'tsx', 'js', 'jsx'] const extensions = ['ts', 'tsx', 'js', 'jsx']
...@@ -21,41 +24,41 @@ describe('DevPagesAPIRouteMatcherProvider', () => { ...@@ -21,41 +24,41 @@ describe('DevPagesAPIRouteMatcherProvider', () => {
route: PagesAPIRouteDefinition route: PagesAPIRouteDefinition
}>([ }>([
{ {
files: [`${dir}/api/other/route.ts`], files: [normalizeSlashes(`${dir}/api/other/route.ts`)],
route: { route: {
kind: RouteKind.PAGES_API, kind: RouteKind.PAGES_API,
pathname: '/api/other/route', pathname: '/api/other/route',
filename: `${dir}/api/other/route.ts`, filename: normalizeSlashes(`${dir}/api/other/route.ts`),
page: '/api/other/route', page: '/api/other/route',
bundlePath: 'pages/api/other/route', bundlePath: 'pages/api/other/route',
}, },
}, },
{ {
files: [`${dir}/api/other/index.ts`], files: [normalizeSlashes(`${dir}/api/other/index.ts`)],
route: { route: {
kind: RouteKind.PAGES_API, kind: RouteKind.PAGES_API,
pathname: '/api/other', pathname: '/api/other',
filename: `${dir}/api/other/index.ts`, filename: normalizeSlashes(`${dir}/api/other/index.ts`),
page: '/api/other', page: '/api/other',
bundlePath: 'pages/api/other', bundlePath: 'pages/api/other',
}, },
}, },
{ {
files: [`${dir}/api.ts`], files: [normalizeSlashes(`${dir}/api.ts`)],
route: { route: {
kind: RouteKind.PAGES_API, kind: RouteKind.PAGES_API,
pathname: '/api', pathname: '/api',
filename: `${dir}/api.ts`, filename: normalizeSlashes(`${dir}/api.ts`),
page: '/api', page: '/api',
bundlePath: 'pages/api', bundlePath: 'pages/api',
}, },
}, },
{ {
files: [`${dir}/api/index.ts`], files: [normalizeSlashes(`${dir}/api/index.ts`)],
route: { route: {
kind: RouteKind.PAGES_API, kind: RouteKind.PAGES_API,
pathname: '/api', pathname: '/api',
filename: `${dir}/api/index.ts`, filename: normalizeSlashes(`${dir}/api/index.ts`),
page: '/api', page: '/api',
bundlePath: 'pages/api', bundlePath: 'pages/api',
}, },
......
import path from 'path'
import { PagesRouteDefinition } from '../../route-definitions/pages-route-definition' import { PagesRouteDefinition } from '../../route-definitions/pages-route-definition'
import { RouteKind } from '../../route-kind' import { RouteKind } from '../../route-kind'
import { DevPagesRouteMatcherProvider } from './dev-pages-route-matcher-provider' import { DevPagesRouteMatcherProvider } from './dev-pages-route-matcher-provider'
import { FileReader } from './helpers/file-reader/file-reader' import { FileReader } from './helpers/file-reader/file-reader'
const normalizeSlashes = (p: string) => p.replace(/\//g, path.sep)
describe('DevPagesRouteMatcherProvider', () => { describe('DevPagesRouteMatcherProvider', () => {
const dir = '<root>' const dir = '<root>'
const extensions = ['ts', 'tsx', 'js', 'jsx'] const extensions = ['ts', 'tsx', 'js', 'jsx']
...@@ -21,41 +24,41 @@ describe('DevPagesRouteMatcherProvider', () => { ...@@ -21,41 +24,41 @@ describe('DevPagesRouteMatcherProvider', () => {
route: PagesRouteDefinition route: PagesRouteDefinition
}>([ }>([
{ {
files: [`${dir}/index.ts`], files: [normalizeSlashes(`${dir}/index.ts`)],
route: { route: {
kind: RouteKind.PAGES, kind: RouteKind.PAGES,
pathname: '/', pathname: '/',
filename: `${dir}/index.ts`, filename: normalizeSlashes(`${dir}/index.ts`),
page: '/', page: '/',
bundlePath: 'pages/index', bundlePath: 'pages/index',
}, },
}, },
{ {
files: [`${dir}/some/api/route.ts`], files: [normalizeSlashes(`${dir}/some/api/route.ts`)],
route: { route: {
kind: RouteKind.PAGES, kind: RouteKind.PAGES,
pathname: '/some/api/route', pathname: '/some/api/route',
filename: `${dir}/some/api/route.ts`, filename: normalizeSlashes(`${dir}/some/api/route.ts`),
page: '/some/api/route', page: '/some/api/route',
bundlePath: 'pages/some/api/route', bundlePath: 'pages/some/api/route',
}, },
}, },
{ {
files: [`${dir}/some/other/route/index.ts`], files: [normalizeSlashes(`${dir}/some/other/route/index.ts`)],
route: { route: {
kind: RouteKind.PAGES, kind: RouteKind.PAGES,
pathname: '/some/other/route', pathname: '/some/other/route',
filename: `${dir}/some/other/route/index.ts`, filename: normalizeSlashes(`${dir}/some/other/route/index.ts`),
page: '/some/other/route', page: '/some/other/route',
bundlePath: 'pages/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: { route: {
kind: RouteKind.PAGES, kind: RouteKind.PAGES,
pathname: '/some/other/route/index/route', 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', page: '/some/other/route/index/route',
bundlePath: 'pages/some/other/route/index/route', bundlePath: 'pages/some/other/route/index/route',
}, },
...@@ -65,7 +68,9 @@ describe('DevPagesRouteMatcherProvider', () => { ...@@ -65,7 +68,9 @@ describe('DevPagesRouteMatcherProvider', () => {
async ({ files, route }) => { async ({ files, route }) => {
const reader: FileReader = { const reader: FileReader = {
read: jest.fn(() => [ read: jest.fn(() => [
...extensions.map((ext) => `${dir}/api/other/page.${ext}`), ...extensions.map((ext) =>
normalizeSlashes(`${dir}/api/other/page.${ext}`)
),
...files, ...files,
]), ]),
} }
......
...@@ -40,6 +40,10 @@ const setupTestDir = async (numFiles = 100) => { ...@@ -40,6 +40,10 @@ const setupTestDir = async (numFiles = 100) => {
} }
describe('recursiveCopy', () => { describe('recursiveCopy', () => {
if (process.platform === 'win32') {
it('should skip on windows to avoid symlink issues', () => {})
return
}
afterAll(() => fs.remove(testDir)) afterAll(() => fs.remove(testDir))
it('should work', async () => { it('should work', async () => {
......
...@@ -10,6 +10,11 @@ const testResolveDataDir = join(__dirname, 'isolated', 'test_resolvedata') ...@@ -10,6 +10,11 @@ const testResolveDataDir = join(__dirname, 'isolated', 'test_resolvedata')
const testpreservefileDir = join(__dirname, 'isolated', 'preservefiles') const testpreservefileDir = join(__dirname, 'isolated', 'preservefiles')
describe('recursiveDelete', () => { describe('recursiveDelete', () => {
if (process.platform === 'win32') {
it('should skip on windows to avoid symlink issues', () => {})
return
}
it('should work', async () => { it('should work', async () => {
expect.assertions(1) expect.assertions(1)
try { 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