From 7fd5fa818dbc3751482d378f916486e4eb8e8a85 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Mon, 22 Jul 2024 11:48:15 +0200 Subject: [PATCH] Turbopack build: Properly isolate scss/webpack-error test (#67995) When this test was in `test/integration` it tried to hack around Sass always being installed. By leveraging the test isolation helpers we can just opt to not installing `sass` which ensures it matches reality. This doesn't fix the test with Turbopack enabled yet but it does highlight the real error, instead of showing a strange resolving error about a non-existent sass-begone package. --- test/e2e/app-dir/scss/webpack-error/mock.js | 7 -- .../scss/webpack-error/webpack-error.test.ts | 69 +++++++------------ test/turbopack-build-tests-manifest.json | 2 +- 3 files changed, 27 insertions(+), 51 deletions(-) delete mode 100644 test/e2e/app-dir/scss/webpack-error/mock.js diff --git a/test/e2e/app-dir/scss/webpack-error/mock.js b/test/e2e/app-dir/scss/webpack-error/mock.js deleted file mode 100644 index 2a4d406552f31..0000000000000 --- a/test/e2e/app-dir/scss/webpack-error/mock.js +++ /dev/null @@ -1,7 +0,0 @@ -let originalLoader -const M = require('module') -originalLoader = M._load -M._load = function hookedLoader(request, parent, isMain) { - if (request === 'sass') request = 'sass-begone' - return originalLoader(request, parent, isMain) -} diff --git a/test/e2e/app-dir/scss/webpack-error/webpack-error.test.ts b/test/e2e/app-dir/scss/webpack-error/webpack-error.test.ts index 6078a4cc8d609..a2a98c953047b 100644 --- a/test/e2e/app-dir/scss/webpack-error/webpack-error.test.ts +++ b/test/e2e/app-dir/scss/webpack-error/webpack-error.test.ts @@ -1,49 +1,32 @@ /* eslint-env jest */ - -import { remove } from 'fs-extra' -import { nextBuild } from 'next-test-utils' -import { join } from 'path' -import { quote as shellQuote } from 'shell-quote' -// In order for the global isNextStart to be set -import 'e2e-utils' +import { nextTestSetup } from 'e2e-utils' describe('SCSS Support', () => { - ;(Boolean((global as any).isNextStart) ? describe : describe.skip)( - 'production only', - () => { - describe('Friendly Webpack Error', () => { - const appDir = __dirname - - const mockFile = join(appDir, 'mock.js') + const { next, isNextDev } = nextTestSetup({ + files: __dirname, + skipStart: true, + skipDeployment: true, + }) + // Production only test + ;(isNextDev ? describe.skip : describe)('Friendly Webpack Error', () => { + it('should be a friendly error successfully', async () => { + const { exitCode, cliOutput } = await next.build() + expect(exitCode).toBe(1) - beforeAll(async () => { - await remove(join(appDir, '.next')) - }) - it('should be a friendly error successfully', async () => { - const { code, stderr } = await nextBuild(appDir, [], { - env: { NODE_OPTIONS: shellQuote([`--require`, mockFile]) }, - stderr: true, - }) - let cleanScssErrMsg = - '\n\n' + - './styles/global.scss\n' + - "To use Next.js' built-in Sass support, you first need to install `sass`.\n" + - 'Run `npm i sass` or `yarn add sass` inside your workspace.\n' + - '\n' + - 'Learn more: https://nextjs.org/docs/messages/install-sass\n' + expect(cliOutput).toContain('./styles/global.scss') + expect(cliOutput).toContain( + "To use Next.js' built-in Sass support, you first need to install `sass`." + ) + expect(cliOutput).toContain( + 'Run `npm i sass` or `yarn add sass` inside your workspace.' + ) + expect(cliOutput).toContain( + 'Learn more: https://nextjs.org/docs/messages/install-sass' + ) - // eslint-disable-next-line - expect(code).toBe(1) - // eslint-disable-next-line - expect(stderr).toContain('Failed to compile.') - // eslint-disable-next-line - expect(stderr).toContain(cleanScssErrMsg) - // eslint-disable-next-line - expect(stderr).not.toContain('css-loader') - // eslint-disable-next-line - expect(stderr).not.toContain('sass-loader') - }) - }) - } - ) + expect(cliOutput).toContain('Failed to compile.') + expect(cliOutput).not.toContain('css-loader') + expect(cliOutput).not.toContain('sass-loader') + }) + }) }) diff --git a/test/turbopack-build-tests-manifest.json b/test/turbopack-build-tests-manifest.json index f7b9b03d85479..de8f7aecfbb1e 100644 --- a/test/turbopack-build-tests-manifest.json +++ b/test/turbopack-build-tests-manifest.json @@ -3853,7 +3853,7 @@ "test/e2e/app-dir/scss/webpack-error/webpack-error.test.ts": { "passed": [], "failed": [ - "SCSS Support production only Friendly Webpack Error should be a friendly error successfully" + "SCSS Support Friendly Webpack Error should be a friendly error successfully" ], "pending": [], "flakey": [],