Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test imports of all file types (#43751)
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
1 parent
8da43b1
commit c341c76
Showing
11 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react' | ||
|
||
export default function Layout({ children }: { children: React.ReactNode }) { | ||
return <>{children}</> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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), | ||
]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function CompJs() { | ||
return <div id="js">CompJs</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function CompJsx() { | ||
return <div id="jsx">CompJsx</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react' | ||
|
||
export default function CompTs() { | ||
return React.createElement('div', { id: 'ts' }, 'CompTs') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from 'react' | ||
|
||
export default function CompTsx() { | ||
return <div id="tsx">CompTsx</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
strictMode: true, | ||
experimental: { | ||
appDir: true, | ||
}, | ||
} |