Unverified Commit a429e04f authored by OJ Kwon's avatar OJ Kwon Committed by GitHub

test(turbopack) migrate api tests, few image tests (#55552)

### What?

PR migrates next-dev's api tests to use next.js integration tests, as well as enabling few more image tests.

Closes WEB-1599
parent deded850
This diff is collapsed.
......@@ -45,11 +45,11 @@ swc_core = { version = "0.83.12", features = [
testing = { version = "0.34.1" }
# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230917.1" }
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230918.2" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230917.1" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230918.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230917.1" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230918.2" }
# General Deps
......
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'
type Data = {
hello: string
input?: string | string[]
}
export default function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
res.status(200).json({ hello: 'world', input: req.query.input })
}
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextRequest } from 'next/server'
export const config = {
runtime: 'edge',
}
export default function handler(req: NextRequest) {
const { searchParams } = new URL(req.url)
return new Response(
JSON.stringify({ hello: 'world', input: searchParams.get('input') }),
{
status: 200,
headers: {
'content-type': 'application/json',
},
}
)
}
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'
type Data = {
hello: string
input?: string | string[]
}
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
const innerRes = await fetch(
`http://127.0.0.1:${process.env.PORT}/api/basic?input=test`
)
const json = await innerRes.json()
res.status(200).json(json)
}
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'
type Data = {
hello: string
input?: string | string[]
}
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
const innerRes = await fetch(
`http://[::1]:${process.env.PORT}/api/basic?input=test`
)
const json = await innerRes.json()
res.status(200).json(json)
}
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'
type Data = {
hello: string
input?: string | string[]
}
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
const innerRes = await fetch(
`http://localhost:${process.env.PORT}/api/basic?input=test`
)
const json = await innerRes.json()
res.status(200).json(json)
}
import { useTestHarness, Harness } from '@turbo/pack-test-harness'
export default function Page() {
useTestHarness(runTests)
return <h1>Ready</h1>
}
let once = true
function runTests(harness: Harness) {
if (!once) return
once = false
it('should run a basic API request', async () => {
const res = await fetch('/api/basic?input=test')
const json = await res.json()
expect(json).toEqual({ hello: 'world', input: 'test' })
})
it('should run a basic edge API request', async () => {
const res = await fetch('/api/edge?input=test')
const json = await res.json()
expect(json).toEqual({ hello: 'world', input: 'test' })
})
it('should be able to use PORT and fetch from localhost', async () => {
const res = await fetch('/api/localhost')
const json = await res.json()
expect(json).toEqual({ hello: 'world', input: 'test' })
})
it('should be able to use PORT and fetch from 127.0.0.1', async () => {
const res = await fetch('/api/ipv4')
const json = await res.json()
expect(json).toEqual({ hello: 'world', input: 'test' })
})
it('should be able to use PORT and fetch from [::1]', async () => {
const res = await fetch('/api/ipv6')
const json = await res.json()
expect(json).toEqual({ hello: 'world', input: 'test' })
})
}
warning - [parse] [project]/packages/next/dist/server/web/sandbox/context.js /packages/next/dist/server/web/sandbox/context.js:64:56 lint TP1004 fs.readFile(???*0*) is very dynamic
60 | }
61 | async function loadWasm(wasm) {
62 | const modules = {};
63 | await Promise.all(wasm.map(async (binding)=>{
+ v
64 + const module1 = await WebAssembly.compile(await _fs.promises.readFile(binding.filePath));
+ ^
65 | modules[binding.name] = module1;
66 | }));
67 | return modules;
68 | }
- *0* ???*1*["filePath"]
⚠️ unknown object
- *1* binding
⚠️ pattern without value
\ No newline at end of file
warning - [parse] [project]/packages/next/dist/server/web/sandbox/context.js /packages/next/dist/server/web/sandbox/context.js:355:28 lint TP1004 fs.readFileSync(???*0*, "utf-8") is very dynamic
351 | }
352 | const moduleContext = lazyModuleContext;
353 | const evaluateInContext = (filepath)=>{
354 | if (!moduleContext.paths.has(filepath)) {
+ v
355 + const content = (0, _fs.readFileSync)(filepath, "utf-8");
+ ^
356 | try {
357 | (0, _vm.runInContext)(content, moduleContext.runtime.context, {
358 | filename: filepath
359 | });
- *0* filepath
⚠️ pattern without value
\ No newline at end of file
......@@ -112,6 +112,7 @@ const enabledTests = [
'test/e2e/typescript-version-no-warning/typescript-version-no-warning.test.ts',
'test/e2e/typescript-version-warning/typescript-version-warning.test.ts',
'test/e2e/undici-fetch/index.test.ts',
'test/integration/api-support/test/index.test.js',
'test/integration/404-page/test/index.test.js',
'test/integration/404-page-app/test/index.test.js',
'test/integration/404-page-custom-error/test/index.test.js',
......@@ -122,6 +123,8 @@ const enabledTests = [
'test/integration/index-index/test/index.test.js',
'test/integration/next-image-new/middleware/test/index.test.ts',
'test/integration/next-image-new/react-virtualized/test/index.test.ts',
'test/integration/next-image-new/typescript/test/index.test.ts',
'test/integration/next-image-new/unoptimized/test/index.test.ts',
'test/integration/revalidate-as-path/test/index.test.js',
'test/integration/rewrites-destination-query-array/test/index.test.js',
'test/integration/root-optional-revalidate/test/index.test.js',
......
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