-
Notifications
You must be signed in to change notification settings - Fork 6
Fix flaky tests and add typechecking #233
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,73 +1,4 @@ | ||
| import { IncomingMessage, request } from "node:http"; | ||
| import { resolve } from "node:path"; | ||
| import { integrationTest } from "./helpers"; | ||
| import testNextApp from "./nextApp"; | ||
|
|
||
| import { getFreePort, integrationTest, readAppmaps, spawnAppmapNode } from "./helpers"; | ||
|
|
||
| const nextBin = require.resolve("next/dist/bin/next", { | ||
| paths: [resolve(__dirname, "next")], | ||
| }); | ||
|
|
||
| async function spawnNextJsApp(port: number) { | ||
| // On Windows, we give "node" argument explicitly because next is a js file with | ||
| // shebang (#!/usr/bin/env node) which does not work on Windows. | ||
| const app = | ||
| process.platform == "win32" | ||
| ? spawnAppmapNode("node", nextBin, "dev", "-p", String(port)) | ||
| : spawnAppmapNode(nextBin, "dev", "-p", String(port)); | ||
|
|
||
| await new Promise<void>((r) => { | ||
| const onData = (chunk: Buffer) => { | ||
| console.log("CHUNK", chunk.toString()); | ||
| if (chunk.toString().includes("Ready")) { | ||
| app.stdout.removeListener("data", onData); | ||
| r(); | ||
| } | ||
| }; | ||
| app.stdout.on("data", onData); | ||
| }); | ||
| return app; | ||
| } | ||
|
|
||
| integrationTest( | ||
| "mapping a Next.js appmap", | ||
| async () => { | ||
| const port = await getFreePort(); | ||
| const app = await spawnNextJsApp(port); | ||
| const response = await makeRequest(port, "/hello"); | ||
| console.log("Response", response); | ||
| const pid = parseInt((JSON.parse(response) as unknown as { pid: string }).pid); | ||
|
|
||
| await makeRequest(port, "/about"); | ||
|
|
||
| app.kill("SIGINT"); | ||
| await new Promise((r) => app.once("exit", r)); | ||
| const appMaps = readAppmaps(); | ||
| // Delete response body captures because they will be different in every run | ||
| Object.values(appMaps).forEach( | ||
| (a) => | ||
| a.events?.forEach((e) => { | ||
| if ("http_server_response" in e) delete e.http_server_response.return_value; | ||
| if ("http_client_response" in e) delete e.http_client_response.return_value; | ||
| }), | ||
| ); | ||
|
|
||
| expect(appMaps).toMatchSnapshot(); | ||
|
|
||
| // We need to kill the next process explicitly on Windows | ||
| // because it's spawn-ed with "shell: true" and app is the shell process. | ||
| if (process.platform == "win32") process.kill(pid, "SIGINT"); | ||
| }, | ||
| 20000, | ||
| ); | ||
|
|
||
| async function makeRequest(port: number, path: string, method = "GET") { | ||
| const url = new URL(path, `http://localhost:${port}`); | ||
| const response = new Promise<IncomingMessage>((resolve, reject) => { | ||
| const req = request(url, { method }, resolve).once("error", reject); | ||
| req.end(); | ||
| }); | ||
|
|
||
| const chunks: Buffer[] = []; | ||
| for await (const chunk of await response) chunks.push(chunk as Buffer); | ||
| return Buffer.concat(chunks).toString(); | ||
| } | ||
| integrationTest("mapping a Next.js appmap", testNextApp, 60000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,81 +1,12 @@ | ||
| import { IncomingMessage, request } from "node:http"; | ||
| import { resolve } from "node:path"; | ||
|
|
||
| import { getFreePort, integrationTest, readAppmaps, spawnAppmapNode } from "./helpers"; | ||
|
|
||
| const nextBin = require.resolve("next/dist/bin/next", { | ||
| paths: [resolve(__dirname, "next16")], | ||
| }); | ||
|
|
||
| async function spawnNextJsApp(port: number) { | ||
| // On Windows, we give "node" argument explicitly because next is a js file with | ||
| // shebang (#!/usr/bin/env node) which does not work on Windows. | ||
| // Turbopack (the default bundler in Next.js 16) respects webpack loaders configured | ||
| // via next.config turbopack.rules, which we inject in src/hooks/next.ts. | ||
| const app = | ||
| process.platform == "win32" | ||
| ? spawnAppmapNode("node", nextBin, "dev", "-p", String(port)) | ||
| : spawnAppmapNode(nextBin, "dev", "-p", String(port)); | ||
|
|
||
| await new Promise<void>((r) => { | ||
| const onData = (chunk: Buffer) => { | ||
| console.log("CHUNK", chunk.toString()); | ||
| if (chunk.toString().includes("Ready")) { | ||
| app.stdout.removeListener("data", onData); | ||
| r(); | ||
| } | ||
| }; | ||
| app.stdout.on("data", onData); | ||
| }); | ||
| return app; | ||
| } | ||
| import { integrationTest } from "./helpers"; | ||
| import testNextApp from "./nextApp"; | ||
|
|
||
| // Next.js 16 requires Node.js >= 20.9.0 | ||
| const nodeSupported = (() => { | ||
| const [major, minor] = process.versions.node.split(".").map(Number); | ||
| return major > 20 || (major === 20 && minor >= 9); | ||
| })(); | ||
|
|
||
| integrationTest.if(nodeSupported)( | ||
| "mapping a Next.js 16 appmap", | ||
| async () => { | ||
| const port = await getFreePort(); | ||
| const app = await spawnNextJsApp(port); | ||
| const response = await makeRequest(port, "/hello"); | ||
| console.log("Response", response); | ||
| const pid = parseInt((JSON.parse(response) as unknown as { pid: string }).pid); | ||
|
|
||
| await makeRequest(port, "/about"); | ||
|
|
||
| app.kill("SIGINT"); | ||
| await new Promise((r) => app.once("exit", r)); | ||
| const appMaps = readAppmaps(); | ||
| // Delete response body captures because they will be different in every run | ||
| Object.values(appMaps).forEach( | ||
| (a) => | ||
| a.events?.forEach((e) => { | ||
| if ("http_server_response" in e) delete e.http_server_response.return_value; | ||
| if ("http_client_response" in e) delete e.http_client_response.return_value; | ||
| }), | ||
| ); | ||
|
|
||
| expect(appMaps).toMatchSnapshot(); | ||
|
|
||
| // We need to kill the next process explicitly on Windows | ||
| // because it's spawn-ed with "shell: true" and app is the shell process. | ||
| if (process.platform == "win32") process.kill(pid, "SIGINT"); | ||
| }, | ||
| 60000, | ||
| ); | ||
|
|
||
| async function makeRequest(port: number, path: string, method = "GET") { | ||
| const url = new URL(path, `http://localhost:${port}`); | ||
| const response = new Promise<IncomingMessage>((resolve, reject) => { | ||
| const req = request(url, { method }, resolve).once("error", reject); | ||
| req.end(); | ||
| }); | ||
|
|
||
| const chunks: Buffer[] = []; | ||
| for await (const chunk of await response) chunks.push(chunk as Buffer); | ||
| return Buffer.concat(chunks).toString(); | ||
| } | ||
| // Turbopack (the default bundler in Next.js 16) respects webpack loaders configured | ||
| // via next.config turbopack.rules, which we inject in src/hooks/next.ts. | ||
| integrationTest.if(nodeSupported)("mapping a Next.js 16 appmap", testNextApp, 60000); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.