Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Sep 20, 2022
1 parent 105d99f commit 45bc37b
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/e2e/app-dir/app-alias.test.ts
@@ -0,0 +1,37 @@
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { renderViaHTTP } from 'next-test-utils'
import path from 'path'

describe('app-dir alias handling', () => {
if ((global as any).isNextDeploy) {
it('should skip next deploy for now', () => {})
return
}

if (process.env.NEXT_TEST_REACT_VERSION === '^17') {
it('should skip for react v17', () => {})
return
}

let next: NextInstance

beforeAll(async () => {
next = await createNext({
files: new FileRef(path.join(__dirname, 'app-alias')),
dependencies: {
react: 'experimental',
'react-dom': 'experimental',
typescript: 'latest',
'@types/react': 'latest',
'@types/node': 'latest',
},
})
})
afterAll(() => next.destroy())

it('should handle typescript paths alias correctly', async () => {
const html = await renderViaHTTP(next.url, '/button')
expect(html).toContain('<button>click</button>')
})
})
5 changes: 5 additions & 0 deletions test/e2e/app-dir/app-alias/app/button/page.tsx
@@ -0,0 +1,5 @@
import Button from '@/ui/button'

export default function page() {
return <Button>click</Button>
}
8 changes: 8 additions & 0 deletions test/e2e/app-dir/app-alias/next.config.js
@@ -0,0 +1,8 @@
module.exports = {
experimental: {
appDir: true,
serverComponents: true,
legacyBrowsers: false,
browsersListForSwc: true,
},
}
24 changes: 24 additions & 0 deletions test/e2e/app-dir/app-alias/tsconfig.json
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "ES6",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"baseUrl": ".",
"paths": {
"@/ui/*": ["ui/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/app-alias/ui/button.tsx
@@ -0,0 +1,3 @@
export default function Button(props: any) {
return <button {...props} />
}

0 comments on commit 45bc37b

Please sign in to comment.