Skip to content

[do-not-merge] Test run fix/turbopack #2988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/build/content/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,10 @@ export const copyNextServerCode = async (ctx: PluginContext): Promise<void> => {
: ctx.nextDistDir
const destDir = join(ctx.serverHandlerDir, nextFolder)

const paths = await glob(
[`*`, `server/*`, `server/chunks/*`, `server/edge-chunks/*`, `server/+(app|pages)/**/*.js`],
{
cwd: srcDir,
extglob: true,
},
)
const paths = await glob([`*`, `server/**/*`], {
cwd: srcDir,
extglob: true,
})

await Promise.all(
paths.map(async (path: string) => {
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/hello-world-turbopack/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
3 changes: 3 additions & 0 deletions tests/fixtures/hello-world-turbopack/app/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <h1>Hello, Next.js!</h1>
}
9 changes: 9 additions & 0 deletions tests/fixtures/hello-world-turbopack/next.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'standalone',
eslint: {
ignoreDuringBuilds: true,
},
}

module.exports = nextConfig
15 changes: 15 additions & 0 deletions tests/fixtures/hello-world-turbopack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "hello-world-app",
"version": "0.1.0",
"private": true,
"scripts": {
"postinstall": "next build --turbopack",
"dev": "next dev --turbopack",
"build": "next build"
},
"dependencies": {
"next": "latest",
"react": "18.2.0",
"react-dom": "18.2.0"
}
}
72 changes: 72 additions & 0 deletions tests/integration/hello-world-turbopack.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { load } from 'cheerio'
import { getLogger } from 'lambda-local'
import { cp } from 'node:fs/promises'
import { HttpResponse, http, passthrough } from 'msw'
import { setupServer } from 'msw/node'
import { v4 } from 'uuid'
import { Mock, afterAll, afterEach, beforeAll, beforeEach, expect, test, vi } from 'vitest'
import { type FixtureTestContext } from '../utils/contexts.js'
import { createFixture, invokeFunction, runPlugin } from '../utils/fixture.js'
import { generateRandomObjectID, startMockBlobStore } from '../utils/helpers.js'

vi.mock('node:fs/promises', async (importOriginal) => {
const fsPromisesModule = (await importOriginal()) as typeof import('node:fs/promises')
return {
...fsPromisesModule,
cp: vi.fn(fsPromisesModule.cp.bind(fsPromisesModule)),
}
})

let server: ReturnType<typeof setupServer>

// Disable the verbose logging of the lambda-local runtime
getLogger().level = 'alert'

const purgeAPI = vi.fn()

beforeAll(() => {
server = setupServer(
http.post('https://api.netlify.com/api/v1/purge', async ({ request }) => {
purgeAPI(await request.json())

return HttpResponse.json({
ok: true,
})
}),
http.all(/.*/, () => passthrough()),
)
server.listen()
})

afterAll(() => {
// Disable API mocking after the tests are done.
server.close()
})

beforeEach<FixtureTestContext>(async (ctx) => {
// set for each test a new deployID and siteID
ctx.deployID = generateRandomObjectID()
ctx.siteID = v4()
vi.stubEnv('SITE_ID', ctx.siteID)
vi.stubEnv('DEPLOY_ID', ctx.deployID)
// hide debug logs in tests
vi.spyOn(console, 'debug').mockImplementation(() => {})

purgeAPI.mockClear()

await startMockBlobStore(ctx)
})

afterEach(() => {
vi.unstubAllEnvs()
})

test<FixtureTestContext>('Test that the hello-world-turbopack next app is working', async (ctx) => {
await createFixture('hello-world-turbopack', ctx)
await runPlugin(ctx)

// test the function call
const home = await invokeFunction(ctx)
expect(home.statusCode).toBe(200)
expect(load(home.body)('h1').text()).toBe('Hello, Next.js!')
})
1 change: 1 addition & 0 deletions tests/utils/create-e2e-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ async function cleanup(dest: string, deployId?: string): Promise<void> {

export const fixtureFactories = {
simple: () => createE2EFixture('simple'),
helloWorldTurbopack: () => createE2EFixture('hello-world-turbopack'),
outputExport: () => createE2EFixture('output-export'),
ouputExportPublishOut: () =>
createE2EFixture('output-export', {
Expand Down
Loading