Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test imports of all file types #43751

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions test/e2e/app-dir/import.test.ts
@@ -0,0 +1,39 @@
import path from 'path'
import cheerio from 'cheerio'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { renderViaHTTP } from 'next-test-utils'

describe('app dir imports', () => {
if (process.env.NEXT_TEST_REACT_VERSION === '^17') {
it('should skip for react v17', () => {})
return
}
let next: NextInstance

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

;['js', 'jsx', 'ts', 'tsx'].forEach((ext) => {
it(`we can import all components from .${ext}`, async () => {
const html = await renderViaHTTP(next.url, `/${ext}`)
const $ = cheerio.load(html)
expect($('#js').text()).toBe('CompJs')
})
})
}

runTests()
})
15 changes: 15 additions & 0 deletions test/e2e/app-dir/import/app/js/page.js
@@ -0,0 +1,15 @@
import CompJs from '../../components/compJs'
import CompJsx from '../../components/compJsx'
import CompTs from '../../components/compTs'
import CompTsx from '../../components/compTsx'

export default function Page() {
return (
<>
<CompJs />
<CompJsx />
<CompTs />
<CompTsx />
</>
)
}
15 changes: 15 additions & 0 deletions test/e2e/app-dir/import/app/jsx/page.jsx
@@ -0,0 +1,15 @@
import CompJs from '../../components/compJs'
import CompJsx from '../../components/compJsx'
import CompTs from '../../components/compTs'
import CompTsx from '../../components/compTsx'

export default function Page() {
return (
<>
<CompJs />
<CompJsx />
<CompTs />
<CompTsx />
</>
)
}
5 changes: 5 additions & 0 deletions test/e2e/app-dir/import/app/layout.tsx
@@ -0,0 +1,5 @@
import React from 'react'

export default function Layout({ children }: { children: React.ReactNode }) {
return <>{children}</>
}
14 changes: 14 additions & 0 deletions test/e2e/app-dir/import/app/ts/page.ts
@@ -0,0 +1,14 @@
import React from 'react'
import CompJs from '../../components/compJs'
import CompJsx from '../../components/compJsx'
import CompTs from '../../components/compTs'
import CompTsx from '../../components/compTsx'

export default function Page() {
return React.createElement(React.Fragment, null, [
React.createElement(CompJs, null),
React.createElement(CompJsx, null),
React.createElement(CompTs, null),
React.createElement(CompTsx, null),
])
}
17 changes: 17 additions & 0 deletions test/e2e/app-dir/import/app/tsx/page.tsx
@@ -0,0 +1,17 @@
import React from 'react'

import CompJs from '../../components/compJs'
import CompJsx from '../../components/compJsx'
import CompTs from '../../components/compTs'
import CompTsx from '../../components/compTsx'

export default function Page() {
return (
<>
<CompJs />
<CompJsx />
<CompTs />
<CompTsx />
</>
)
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/import/components/compJs.js
@@ -0,0 +1,3 @@
export default function CompJs() {
return <div id="js">CompJs</div>
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/import/components/compJsx.jsx
@@ -0,0 +1,3 @@
export default function CompJsx() {
return <div id="jsx">CompJsx</div>
}
5 changes: 5 additions & 0 deletions test/e2e/app-dir/import/components/compTs.tsx
@@ -0,0 +1,5 @@
import React from 'react'

export default function CompTs() {
return React.createElement('div', { id: 'ts' }, 'CompTs')
}
5 changes: 5 additions & 0 deletions test/e2e/app-dir/import/components/compTsx.tsx
@@ -0,0 +1,5 @@
import React from 'react'

export default function CompTsx() {
return <div id="tsx">CompTsx</div>
}
6 changes: 6 additions & 0 deletions test/e2e/app-dir/import/next.config.js
@@ -0,0 +1,6 @@
module.exports = {
strictMode: true,
experimental: {
appDir: true,
},
}