Skip to content

Commit 3c837ed

Browse files
ctjlewissokrastyfle
authored
test(next): add tests for Node-like hashbang support (#27906)
* update to webpack 5.50.0 * feat: use shebang loader shim for now * chore: snapshot formatting change * chore: remove unneeded SSR test * chore: test all file extensions * chore: remove shebang loader from Webpack config * chore: revert unnecessary changes * Update test/integration/hashbang/test/index.test.js Co-authored-by: Steven <[email protected]> * chore: revert changes to yarn.lock Co-authored-by: Tobias Koppers <[email protected]> Co-authored-by: Steven <[email protected]>
1 parent 12eb812 commit 3c837ed

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/env node
2+
3+
module.exports = 789
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/env node
2+
3+
module.exports = 123
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/env node
2+
3+
export default 456
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Import hashbang modules.
3+
*/
4+
import js from '../cases/js.js'
5+
import cjs from '../cases/cjs.cjs'
6+
import mjs from '../cases/mjs.mjs'
7+
8+
const jsMsg = `JS: ${js}`
9+
const mjsMsg = `MJS: ${mjs}`
10+
const cjsMsg = `CJS: ${cjs}`
11+
12+
const Page = () => (
13+
<div>
14+
<h3>{jsMsg}</h3>
15+
<h3>{mjsMsg}</h3>
16+
<h3>{cjsMsg}</h3>
17+
</div>
18+
)
19+
20+
export default Page
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* eslint-env jest */
2+
3+
import { join } from 'path'
4+
import fs from 'fs-extra'
5+
import {
6+
renderViaHTTP,
7+
findPort,
8+
launchApp,
9+
killApp,
10+
nextBuild,
11+
nextStart,
12+
} from 'next-test-utils'
13+
14+
jest.setTimeout(1000 * 60 * 2)
15+
16+
let app
17+
let appPort
18+
const appDir = join(__dirname, '../')
19+
20+
function runTests() {
21+
describe('first-line hashbang (#!) parse', () => {
22+
it('should work for .js files', async () => {
23+
const html = await renderViaHTTP(appPort, '/')
24+
expect(html).toMatch('JS: 123')
25+
})
26+
27+
it('should work for .mjs files', async () => {
28+
const html = await renderViaHTTP(appPort, '/')
29+
expect(html).toMatch('MJS: 456')
30+
})
31+
32+
it('should work for .cjs files', async () => {
33+
const html = await renderViaHTTP(appPort, '/')
34+
expect(html).toMatch('CJS: 789')
35+
})
36+
})
37+
}
38+
39+
const nextConfig = join(appDir, 'next.config.js')
40+
41+
describe('Hashbang', () => {
42+
describe('dev mode', () => {
43+
beforeAll(async () => {
44+
appPort = await findPort()
45+
app = await launchApp(appDir, appPort)
46+
})
47+
afterAll(() => killApp(app))
48+
49+
runTests(true)
50+
})
51+
52+
describe('production mode', () => {
53+
beforeAll(async () => {
54+
await fs.remove(nextConfig)
55+
await nextBuild(appDir)
56+
appPort = await findPort()
57+
app = await nextStart(appDir, appPort)
58+
})
59+
afterAll(() => killApp(app))
60+
61+
runTests()
62+
})
63+
})

0 commit comments

Comments
 (0)