Skip to content

Commit

Permalink
Test imports of all file types (#43751)
Browse files Browse the repository at this point in the history
Test imports of `.js`, `.jsx`, `.ts` and `.tsx` from all file types.

Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
  • Loading branch information
jankaifer and timneutkens committed Dec 8, 2022
1 parent 8da43b1 commit c341c76
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/e2e/app-dir/import.test.ts
@@ -0,0 +1,38 @@
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,
},
}

0 comments on commit c341c76

Please sign in to comment.