pactum icon indicating copy to clipboard operation
pactum copied to clipboard

`PACTUM_REQUEST_BASE_URL` is not working when adding it on `.env`

Open 2ajh opened this issue 2 years ago • 3 comments

Describe the bug I have tried to add the environment variable in the .env file in the root of the project and it does not work giving the following error:

    TypeError [ERR_INVALID_URL]: Invalid URL: /endpoint

      at setBaseUrl (node_modules/pactum/src/helpers/requestProcessor.js:33:16)
      at Object.process (node_modules/pactum/src/helpers/requestProcessor.js:14:5)
      at Tosser.toss (node_modules/pactum/src/models/Tosser.js:30:39)
      at Spec.toss (node_modules/pactum/src/models/Spec.js:479:19)
      at Spec.then (node_modules/pactum/src/models/Spec.js:483:10)

However if I add it by exporting it it (export PACTUM_REQUEST_BASE_URL=url) does work

Expected behavior Adding the variable on the .env file it works.

Software (please complete the following information):

  • OS: MacOS
  • Test Runner: Jest

2ajh avatar Jan 24 '23 11:01 2ajh

Pactum doesn't read environment variables from .env file. dotenv will help if we place it at the start of test execution.

ASaiAnudeep avatar Jan 24 '23 17:01 ASaiAnudeep

Pactum doesn't read environment variables from .env file. dotenv will help if we place it at the start of test execution.

Thanks for your answer @ASaiAnudeep

In that case I'm a bit confused by this affirmation in the documentation: "PactumJS supports setting default values to configuration parameters via Envrionment variables. ✅ Correct Usage: Adding to .env file"

2ajh avatar Jan 25 '23 09:01 2ajh

Thank you for pointing it out. We will update the docs.

ASaiAnudeep avatar Jan 25 '23 12:01 ASaiAnudeep