Skip to content

Commit

Permalink
fix integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
suejung-sentry committed Sep 4, 2024
1 parent 70cb9b7 commit 8498786
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 252 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Bun Snapshot v1, https://goo.gl/fbAQLP

exports[`Standalone Analyzer Integration Tests should generate a report and match the snapshot 1`] = `
{
"assets": ExpectArrayContaining {},
"builtAt": Any<Number>,
"bundleName": StringContaining "standalone",
"chunks": ExpectArrayContaining {},
"duration": Any<Number>,
"modules": ExpectArrayContaining {},
"plugin": {
"name": StringMatching "@codecov/standalone-analyzer",
"version": Any<String>,
},
"version": "2",
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ describe("Standalone Analyzer Integration Tests", () => {

it("should generate a report and match the snapshot", async () => {
const id = `standalone-analyzer-${Date.now()}`;
const API_URL = `http://localhost:8000/test-url/${id}/200/false`;

// prepare, build, and run
await $`cd ${standaloneAnalyzerApp} && pnpm run build`;
const { stdout, stderr } =
await $`cd ${standaloneAnalyzerApp} && pnpm run analyze`;
await $`cd ${standaloneAnalyzerApp} && API_URL=${API_URL} pnpm run analyze`;

expect(stdout.toString()).toContain(
"Report successfully generated and handled.",
Expand All @@ -30,7 +31,7 @@ describe("Standalone Analyzer Integration Tests", () => {

// fetch stats from the server
const res = await fetch(
`http://localhost:3000/get-stats-by-bundle-name/${id}/standalone`,
`http://localhost:8000/get-stats-by-bundle-name/${id}/standalone`,
);
const data = (await res.json()) as { stats: string };
const stats = JSON.parse(data.stats) as unknown;
Expand All @@ -39,10 +40,10 @@ describe("Standalone Analyzer Integration Tests", () => {
expect(stats).toMatchSnapshot({
builtAt: expect.any(Number),
duration: expect.any(Number),
outputPath: expect.stringContaining(`build`),
bundleName: expect.stringContaining("standalone"),
plugin: {
name: expect.stringMatching("@codecov/standalone-analyzer"),
version: expect.any(String),
},
assets: expect.arrayContaining([
{
Expand Down
12 changes: 10 additions & 2 deletions integration-tests/test-api/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
```
npm install
npm run dev
pnpm install
pnpm run run
```

```
open http://localhost:3000
```

OR

```
docker compose up
```

open https://localhost:8000
15 changes: 15 additions & 0 deletions integration-tests/test-api/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.8"

services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "8000:8000"
environment:
- PORT=8000
restart: unless-stopped
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
11 changes: 1 addition & 10 deletions integration-tests/test-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ app.all("/ping", (c) => {
app.all(
"/test-url/:id/:status/:badPUT{true|false}/upload/bundle_analysis/v1",
(c) => {
console.log("hitting", c.req.url, "to fetch presigned url");
const id = c.req.param("id");
const status = parseInt(c.req.param("status"));
const badPUT = c.req.param("badPUT") === "true";
Expand Down Expand Up @@ -121,14 +122,4 @@ app.all("/get-stats-by-bundle-name/:id/:bundleName", (c) => {
return c.text("Not found", { status: 404 });
});

app.all("/upload/bundle_analysis/v1", (c) => {
console.log("getting presigned url");
return c.json({ url: "https://localhost:3000/presigned" }, { status: 200 });
});

app.all("/presigned", (c) => {
console.log("hitting presigned url");
return c.json({}, { status: 200 });
});

export default app;
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { CreateAndHandleReport } from "@codecov/standalone-analyzer";
const buildDir =
"../../../integration-tests/test-apps/standalone/dotenv-vercel/dist";

const apiUrl = process.env.API_URL || "https://api.codecov.io";

const coreOpts = {
dryRun: false,
uploadToken: "your-upload-token",
retryCount: 3,
apiUrl: "https://localhost:3000",
bundleName: "my-bundle", // bundle identifier in Codecov
apiUrl: apiUrl,
bundleName: "standalone",
enableBundleAnalysis: true,
debug: true,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "vercel",
"name": "test-apps-standalone-dotenv-vercel",
"private": true,
"version": "0.0.0",
"type": "module",
Expand Down
Loading

0 comments on commit 8498786

Please sign in to comment.