-1

I have a nestjs backend api server within a monorepo. I want to do integration test using supertest. I have currently configured e2e against jest --env=node --verbose command in package.json. For example, check if http://localhost:8112/health return OK.

  it('should pass', async () => {
    const res = await request(http://localhost:8112/health)
    .get('/health')
    .expect(200);
     expect(res.text).toEqual('OK');
 });

I want the api url endpoint to be dynamic. If its staging stg-xyz.com/health or if prod prod-xyz.com. How do i achieve the same?

SMJ
  • 716
  • 1
  • 9
  • 23
  • Option 1. environment variables Option 2. Get the API endpoint from some kind of configuration center service – Lin Du Sep 20 '22 at 04:52

1 Answers1

1

Create two separate ts files where two different environment variables are specified like below:

process.env = Object.assign(process.env, {
  SERVICE_API_TEST_URL: 'http://localhost:8112',
  DEFAULT_TIMEOUT: 60000,
}); 

we can switch the file passing as cli agrument setupfile

nx run api-server:e2e --setupFile=apps/api-server/e2e-test-stg-environment.ts

nx run api-server:e2e --setupFile=apps/api-server/e2e-test-dev-environment.ts
SMJ
  • 716
  • 1
  • 9
  • 23