import path from 'path' import fs from 'fs-extra' import stripAnsi from 'strip-ansi' import resolveFrom from 'resolve-from' import { NextInstance, createNext } from 'e2e-utils' type File = { filename: string content: string } const appDirFiles: File[] = [ { filename: 'app/page.js', content: ` export default function Page() { return
hello world
} `, }, { filename: 'app/layout.js', content: ` export default function Layout({ children }) { return ( {children} ) } `, }, ] const pagesFiles: File[] = [ { filename: 'pages/another.js', content: ` export default function Page() { return (another page
) } `, }, ] let next: NextInstance describe('build-spinners', () => { beforeAll(async () => { next = await createNext({ skipStart: true, files: {}, dependencies: { 'node-pty': '0.10.1', }, packageJson: { pnpm: { onlyBuiltDependencies: ['node-pty'], }, }, }) }) afterAll(() => next.destroy()) beforeEach(async () => { await fs.remove(path.join(next.testDir, 'pages')) await fs.remove(path.join(next.testDir, 'app')) }) it.each([ { name: 'app dir - basic', files: appDirFiles }, { name: 'app dir - (compile workers)', files: [ ...appDirFiles, { filename: 'next.config.js', content: ` module.exports = { experimental: { webpackBuildWorker: true, } } `, }, ], }, { name: 'page dir', files: [ ...pagesFiles, { filename: 'next.config.js', content: ` module.exports = { experimental: { webpackBuildWorker: true, } } `, }, ], }, { name: 'page dir (compile workers)', files: pagesFiles }, { name: 'app and pages', files: [...appDirFiles, ...pagesFiles] }, ])('should handle build spinners correctly $name', async ({ files }) => { for (const { filename, content } of files) { await next.patchFile(filename, content) } const appDir = next.testDir const ptyPath = resolveFrom(appDir, 'node-pty') const pty = require(ptyPath) const output = [] const ptyProcess = pty.spawn('pnpm', ['next', 'build'], { name: 'xterm-color', cols: 80, rows: 30, cwd: appDir, env: process.env, }) ptyProcess.onData(function (data) { stripAnsi(data) .split('\n') .forEach((line) => output.push(line)) process.stdout.write(data) }) await new Promise