Unverified Commit efc5ae42 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: app externals test case improvements (#62871)

### What?

* rename test case
* improve error message and handle edge case for require resolving
* fix test case actually testing externals (webpack was silently
bundling, Turbopack showed error that helped to find the broken test
case)

### Why?

### How?


Closes PACK-2662
parent 82dc672a
......@@ -171,10 +171,10 @@ pub async fn get_server_resolve_options_context(
| ServerContextType::PagesApi { .. } => {
vec![
Vc::upcast(module_feature_report_resolve_plugin),
Vc::upcast(external_cjs_modules_plugin),
Vc::upcast(unsupported_modules_resolve_plugin),
Vc::upcast(next_external_plugin),
Vc::upcast(next_node_shared_runtime_plugin),
Vc::upcast(external_cjs_modules_plugin),
Vc::upcast(next_external_plugin),
]
}
ServerContextType::AppSSR { .. }
......@@ -182,10 +182,10 @@ pub async fn get_server_resolve_options_context(
| ServerContextType::AppRoute { .. } => {
vec![
Vc::upcast(module_feature_report_resolve_plugin),
Vc::upcast(server_component_externals_plugin),
Vc::upcast(unsupported_modules_resolve_plugin),
Vc::upcast(next_external_plugin),
Vc::upcast(next_node_shared_runtime_plugin),
Vc::upcast(server_component_externals_plugin),
Vc::upcast(next_external_plugin),
]
}
ServerContextType::Middleware { .. } => {
......@@ -199,8 +199,8 @@ pub async fn get_server_resolve_options_context(
vec![
Vc::upcast(module_feature_report_resolve_plugin),
Vc::upcast(unsupported_modules_resolve_plugin),
Vc::upcast(next_external_plugin),
Vc::upcast(next_node_shared_runtime_plugin),
Vc::upcast(next_external_plugin),
]
}
};
......
......@@ -150,7 +150,7 @@ createNextDescribe(
).toMatch(/^__myFont_.{6}, __myFont_Fallback_.{6}$/)
})
it('should not apply swc optimizer transform for external packages in browser layer', async () => {
it('should not apply swc optimizer transform for external packages in browser layer in web worker', async () => {
const browser = await next.browser('/browser')
expect(await browser.elementByCss('#worker-state').text()).toBe('default')
......
......@@ -11,7 +11,8 @@
"default": "./subpath.js"
},
"./react": {
"import": "./react.js"
"import": "./react.mjs",
"default": "./react.js"
},
"./package.json": "./package.json"
}
......
import React from 'react'
const React = require('react')
export function getReactVersion() {
function getReactVersion() {
return React.version
}
exports.getReactVersion = getReactVersion
import React from 'react'
export function getReactVersion() {
return React.version
}
......@@ -2,7 +2,7 @@
import World1 from 'app-esm-package1/entry'
import World2 from 'app-esm-package2/entry'
import World3 from 'invalid-esm-package/entry'
import World3 from 'app-cjs-esm-package/entry'
export default function Index() {
return (
......
import World1 from 'app-esm-package1/entry'
import World2 from 'app-esm-package2/entry'
import World3 from 'invalid-esm-package/entry'
import World3 from 'app-cjs-esm-package/entry'
export default function Page() {
return (
......
import { nextTestSetup } from 'e2e-utils'
function normalize(str: string) {
return str.replace(/<!-- -->/g, '')
}
describe('esm-externals', () => {
const { next } = nextTestSetup({
const { next, isTurbopack } = nextTestSetup({
files: __dirname,
})
// Pages
{
const expectedHtml =
/Hello <!-- -->World<!-- -->\+<!-- -->World<!-- -->\+<!-- -->World<!-- -->\+<!-- -->World\+World\+World/
const expectedText = /Hello World\+World\+World\+World\+World\+World/
const urls = ['/static', '/ssr', '/ssg']
for (const url of urls) {
// TODO fix webpack behavior
const expectedHtml = isTurbopack
? /Hello World\+World\+World\+World\+World\+World/
: url === '/static'
? /Hello World\+World\+Alternative\+World\+World\+World/
: /Hello World\+World\+Alternative\+World\+World\+Alternative/
// TODO fix webpack behavior
const expectedText =
isTurbopack || url === '/static'
? /Hello World\+World\+World\+World\+World\+World/
: /Hello World\+World\+World\+World\+World\+Alternative/
it(`should return the correct SSR HTML for ${url}`, async () => {
const res = await next.fetch(url)
const html = await res.text()
expect(html).toMatch(expectedHtml)
expect(normalize(html)).toMatch(expectedHtml)
})
it(`should render the correct page for ${url}`, async () => {
......@@ -29,22 +42,20 @@ describe('esm-externals', () => {
{
// TODO App Dir doesn't use esmExternals: true correctly for webpack and Turbopack
// so we only verify that the page doesn't crash, but ignore the actual content
// const expectedHtml =
// /Hello <!-- -->World<!-- -->\+<!-- -->World<!-- -->\+<!-- -->World/
const expectedHtml =
/Hello <!-- -->Wrong<!-- -->\+<!-- -->Wrong<!-- -->\+<!-- -->Wrong/
// const expectedHtml = /Hello World\+World\+World/
const expectedHtml = /Hello Wrong\+Wrong\+Alternative/
// const expectedText = /Hello World\+World\+World/
const urls = ['/server', '/client']
for (const url of urls) {
const expectedText =
url === '/server'
? /Hello Wrong\+Wrong\+Wrong/
? /Hello Wrong\+Wrong\+Alternative/
: /Hello World\+World\+World/
it(`should return the correct SSR HTML for ${url}`, async () => {
const res = await next.fetch(url)
const html = await res.text()
expect(html).toMatch(expectedHtml)
expect(normalize(html)).toMatch(expectedHtml)
})
it(`should render the correct page for ${url}`, async () => {
......
......@@ -8,7 +8,7 @@ module.exports = {
serverComponentsExternalPackages: [
'app-esm-package1',
'app-esm-package2',
'app-invalid-esm-package',
'app-cjs-esm-package',
],
},
webpack(config, { isServer }) {
......
{
"name": "app-invalid-esm-package",
"name": "app-cjs-esm-package",
"exports": {
"./entry": {
"browser": "./browser.js",
"import": "./wrong.js",
"require": "./correct.js"
"import": "./correct.js",
"require": "./alternative.js"
}
}
}
module.exports = 'Alternative'
// ensure it's external
if (Math.random() < 0) require('fail')
module.exports = 'World'
// ensure it's external
if (Math.random() < 0) require('fail')
export default 'World'
......@@ -3,8 +3,8 @@
"exports": {
"./entry": {
"browser": "./browser.js",
"import": "./wrong.js",
"require": "./correct.js"
"import": "./correct.js",
"require": "./alternative.js"
}
}
}
......@@ -2555,6 +2555,7 @@
"app dir - external dependency react in external esm packages should use the same react in server app",
"app dir - external dependency server actions should compile server actions from node_modules in client components",
"app dir - external dependency server actions should not prefer to resolve esm over cjs for bundling optout packages",
"app dir - external dependency should be able to opt-out 3rd party packages being bundled in server components",
"app dir - external dependency should correctly collect global css imports and mark them as side effects",
"app dir - external dependency should emit cjs helpers for external cjs modules when compiled",
"app dir - external dependency should export client module references in esm",
......@@ -2571,8 +2572,7 @@
"app dir - external dependency should use the same export type for packages in both ssr and client"
],
"failed": [
"app dir - external dependency should be able to opt-out 3rd party packages being bundled in server components",
"app dir - external dependency should not apply swc optimizer transform for external packages in browser layer"
"app dir - external dependency should not apply swc optimizer transform for external packages in browser layer in web worker"
],
"pending": [],
"flakey": [],
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment