Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <steven@ceriously.com> * chore: revert changes to yarn.lock Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com> Co-authored-by: Steven <steven@ceriously.com>
- Loading branch information
1 parent
12eb812
commit 3c837ed
Showing
5 changed files
with
92 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,3 @@ | ||
#!/usr/env node | ||
|
||
module.exports = 789 |
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 @@ | ||
#!/usr/env node | ||
|
||
module.exports = 123 |
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 @@ | ||
#!/usr/env node | ||
|
||
export default 456 |
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,20 @@ | ||
/** | ||
* Import hashbang modules. | ||
*/ | ||
import js from '../cases/js.js' | ||
import cjs from '../cases/cjs.cjs' | ||
import mjs from '../cases/mjs.mjs' | ||
|
||
const jsMsg = `JS: ${js}` | ||
const mjsMsg = `MJS: ${mjs}` | ||
const cjsMsg = `CJS: ${cjs}` | ||
|
||
const Page = () => ( | ||
<div> | ||
<h3>{jsMsg}</h3> | ||
<h3>{mjsMsg}</h3> | ||
<h3>{cjsMsg}</h3> | ||
</div> | ||
) | ||
|
||
export default Page |
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,63 @@ | ||
/* eslint-env jest */ | ||
|
||
import { join } from 'path' | ||
import fs from 'fs-extra' | ||
import { | ||
renderViaHTTP, | ||
findPort, | ||
launchApp, | ||
killApp, | ||
nextBuild, | ||
nextStart, | ||
} from 'next-test-utils' | ||
|
||
jest.setTimeout(1000 * 60 * 2) | ||
|
||
let app | ||
let appPort | ||
const appDir = join(__dirname, '../') | ||
|
||
function runTests() { | ||
describe('first-line hashbang (#!) parse', () => { | ||
it('should work for .js files', async () => { | ||
const html = await renderViaHTTP(appPort, '/') | ||
expect(html).toMatch('JS: 123') | ||
}) | ||
|
||
it('should work for .mjs files', async () => { | ||
const html = await renderViaHTTP(appPort, '/') | ||
expect(html).toMatch('MJS: 456') | ||
}) | ||
|
||
it('should work for .cjs files', async () => { | ||
const html = await renderViaHTTP(appPort, '/') | ||
expect(html).toMatch('CJS: 789') | ||
}) | ||
}) | ||
} | ||
|
||
const nextConfig = join(appDir, 'next.config.js') | ||
|
||
describe('Hashbang', () => { | ||
describe('dev mode', () => { | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests(true) | ||
}) | ||
|
||
describe('production mode', () => { | ||
beforeAll(async () => { | ||
await fs.remove(nextConfig) | ||
await nextBuild(appDir) | ||
appPort = await findPort() | ||
app = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
runTests() | ||
}) | ||
}) |