Skip to content
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

Error: Body Already Used in github function CD #125

Open
lomithrani opened this issue Aug 24, 2024 · 1 comment
Open

Error: Body Already Used in github function CD #125

lomithrani opened this issue Aug 24, 2024 · 1 comment

Comments

@lomithrani
Copy link

lomithrani commented Aug 24, 2024

I have trouble in my CD since last update (0.7.2 to 1.1.2) , bun test works fine locally but wont pass in github. I have another old branch on 0.7.16 that doesn't have this issue either.
Link to action :

Run cd server
  cd server
  bun install
  bun test
  shell: /usr/bin/bash -e {0}
  env:
    PORT: 3000
    MONGO_URL: mongodb://localhost:3[2](https://github.com/lomithrani/portfolio/actions/runs/10538541982/job/29201159241?pr=56#step:5:2)768/mytestdb
    JWT_SECRET: JWT_SECRET
    ALLOWED_DOMAINS: ["http://localhost:417[3](https://github.com/lomithrani/portfolio/actions/runs/10538541982/job/29201159241?pr=56#step:5:3)"]
bun install v1.1.26 (0a37[4](https://github.com/lomithrani/portfolio/actions/runs/10538541982/job/29201159241?pr=56#step:5:4)23b)

+ typescript@[5](https://github.com/lomithrani/portfolio/actions/runs/10538541982/job/29201159241?pr=56#step:5:5).5.4
+ @elysiajs/[email protected]
+ [email protected]
+ @elysiajs/[email protected]
+ @elysiajs/[email protected]
+ @elysiajs/[email protected]
+ [email protected]
+ portfolio-common@workspace:common

3[6](https://github.com/lomithrani/portfolio/actions/runs/10538541982/job/29201159241?pr=56#step:5:6)2 packages installed [954.00ms]

Blocked 1 postinstall. Run `bun pm untrusted` for details.
bun test v1.1.26 (0a3[7](https://github.com/lomithrani/portfolio/actions/runs/10538541982/job/29201159241?pr=56#step:5:7)423b)

tests/auth.test.ts:
  Running at http://:::3000 CORS allowed: "[\"http://localhost:4173\"]"
  (pass) login > Should create new user [150.26ms]
  (pass) login > Should return existing user [3.49ms]
  

tests/eden.test.ts:
  Service is healthy!
  (pass) edenTreaty > edenTreaty should have correct methods [1.1[8](https://github.com/lomithrani/portfolio/actions/runs/10538541982/job/29201159241?pr=56#step:5:8)ms]
  
  Error: 
        at /home/runner/work/portfolio/portfolio/node_modules/@elysiajs/eden/dist/index.js:1:[9](https://github.com/lomithrani/portfolio/actions/runs/10538541982/job/29201159241?pr=56#step:5:9)150
  1 | "use strict";var P=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var ae=(e,t)=>{for(var n in t)P(e,n,{get:t[n],enumerable:!0})},ie=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of re(t))!se.call(e,s)&&s!==n&&P(e,s,{get:()=>t[s],enumerable:!(r=ne(t,s))||r.enumerable});return e};var oe=e=>ie(P({},"__esModule",{value:!0}),e);var be={};ae(be,{edenFetch:()=>te,edenTreaty:()=>ee,treaty:()=>z});module.exports=oe(be);var T=class extends Error{constructor(n,r){super(r+"");this.status=n;this.value=r}};var ce=/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/,fe=/(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT(?:\+|-)\d{4}\s\([^)]+\)/,de=/^(?:(?:(?:(?:0?[1-9]|[[12](https://github.com/lomithrani/portfolio/actions/runs/10538541982/job/29201159241?pr=56#step:5:13)][0-9]|3[01])[/\s-](
  
  error: Body already used
   code: "ERR_BODY_ALREADY_USED"
  
        at /home/runner/work/portfolio/portfolio/node_modules/@elysiajs/eden/dist/index.js:1:9150
  (fail) edenTreaty > edentTreaty should return correct responses [1.12ms]
  

 3 pass
 1 fail
 [14](https://github.com/lomithrani/portfolio/actions/runs/10538541982/job/29201159241?pr=56#step:5:15) expect() calls
Ran 4 tests across 2 files. [675.00ms]

Actual test :

import { test, expect, describe, beforeAll, afterAll } from 'bun:test'
import { edenTreaty } from '@elysiajs/eden'
import type { Portfolio } from '..'
import { ErrorLike, Subprocess, fetch } from 'bun';

let appInstance: Subprocess<"ignore", "inherit", "inherit"> | undefined = undefined;

const api = edenTreaty<Portfolio>("http://localhost:3000");

describe("edenTreaty", () => {
  beforeAll(async () => {
    appInstance = Bun.spawn({
      cmd: ['bun', 'run', 'index.ts'],
      env: process.env,
      stdout: 'inherit',
      stderr: 'inherit',
    });
    await waitForHealthCheck()
  });

  afterAll(() => {
    if (appInstance) {
      appInstance.kill();
    }
  });

  test("edenTreaty should have correct methods", async () => {
    expect(api).toBeDefined()
    expect(api.login.post).toBeDefined()
    expect(api.domain[':name'].get).toBeDefined()
  })

  test("edentTreaty should return correct responses", async () => {
    const mySelfDomainResponse = await api.domain['louis.gentil'].get()
    expect(mySelfDomainResponse).toBeDefined()
    expect(mySelfDomainResponse.status).toBe(200)
    expect(mySelfDomainResponse.data).toBeDefined()
    expect(mySelfDomainResponse.data).toBeObject()
  })

})

async function waitForHealthCheck(url = "http://localhost:3000/health", maxAttempts = 10, interval = 1000) {
  for (let attempt = 1; attempt <= maxAttempts; attempt++) {
    try {
      const response = await fetch(url);

      if (response.status === 200) {
        console.log("Service is healthy!");
        return true;
      } else {
        console.log(`Attempt ${attempt}: Received status ${response.status}. Retrying in ${interval / 1000} seconds...`);
      }
    } catch (error) {
      console.log(`Attempt ${attempt}: Error occurred - ${error}. Retrying in ${interval / 1000} seconds...`);
    }

    if (attempt < maxAttempts) {
      await new Promise(resolve => setTimeout(resolve, interval));
    }
  }

  console.log("Failed to receive a 200 status after max attempts.");
  return false;
}
@kravetsone
Copy link

Yeah! I receive it in tests with eden too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants