Skip to content

Commit

Permalink
fix test for pages
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Oct 31, 2022
1 parent e6f1b5a commit 055e7e4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
13 changes: 4 additions & 9 deletions packages/next/build/webpack/config/blocks/css/index.ts
Expand Up @@ -274,6 +274,7 @@ export const css = curry(async function css(
// CSS Modules support must be enabled on the server and client so the class
// names are available for SSR or Prerendering.
if (ctx.hasAppDir && !ctx.isProduction) {
// CSS modules
fns.push(
loader({
oneOf: [
Expand All @@ -285,10 +286,6 @@ export const css = curry(async function css(
sideEffects: false,
// CSS Modules are activated via this specific extension.
test: regexCssModules,
// Match CSS modules that are used by the app dir.
issuerLayer: (layer: string) =>
layer === WEBPACK_LAYERS.server ||
layer === WEBPACK_LAYERS.client,
use: [
require.resolve('../../../loaders/next-flight-css-dev-loader'),
...getCssModuleLoader(ctx, lazyPostCSSInitializer),
Expand All @@ -297,10 +294,12 @@ export const css = curry(async function css(
],
})
)

// Opt-in support for Sass (using .scss or .sass extensions).
fns.push(
loader({
oneOf: [
// Opt-in support for Sass (using .scss or .sass extensions).
// For app dir, we match both server and client layers.
markRemovable({
// Sass Modules should never have side effects. This setting will
// allow unused Sass to be removed from the production build.
Expand All @@ -309,10 +308,6 @@ export const css = curry(async function css(
sideEffects: false,
// Sass Modules are activated via this specific extension.
test: regexSassModules,
// Match CSS modules that are used by the app dir.
issuerLayer: (layer: string) =>
layer === WEBPACK_LAYERS.server ||
layer === WEBPACK_LAYERS.client,
use: [
require.resolve('../../../loaders/next-flight-css-dev-loader'),
...getCssModuleLoader(
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/app-dir/rsc-external.test.ts
Expand Up @@ -145,4 +145,14 @@ describe('app dir - rsc external dependency', () => {
)
).toBe('rgb(255, 0, 0)')
})

it('should handle external css modules in pages', async () => {
const browser = await webdriver(next.url, '/test-pages')

expect(
await browser.eval(
`window.getComputedStyle(document.querySelector('h1')).color`
)
).toBe('rgb(255, 0, 0)')
})
})
2 changes: 1 addition & 1 deletion test/e2e/app-dir/rsc-external/next.config.js
Expand Up @@ -3,6 +3,6 @@ module.exports = {
experimental: {
appDir: true,
serverComponentsExternalPackages: ['conditional-exports-optout'],
transpilePackages: ['untranspiled-module'],
transpilePackages: ['untranspiled-module', 'css'],
},
}
5 changes: 5 additions & 0 deletions test/e2e/app-dir/rsc-external/pages/test-pages.jsx
@@ -0,0 +1,5 @@
import Foo from 'css/module'

export default function Page() {
return <Foo />
}

0 comments on commit 055e7e4

Please sign in to comment.