question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to add ENV variables to the extension?

See original GitHub issue

Environment

  1. node -v: v12.6.0

  2. npm -v: 6.9.0

  3. npm ls jest or npm ls react-scripts (if you haven’t ejected): jest@24.8.0 & ts-jest@24.0.2

  4. your vscode-jest settings if customized:

    • jest.pathToJest? none
    • jest.pathToConfig? none
    • anything else that you think might be relevant? none
  5. Operating system: Ubuntu 18.04

Prerequisite

  • are you able to run jest test from command line? Yes
  • how do you run your tests from command line? (for example: npm run test or node_modules/.bin/jest) npm run test

Problem

Hi, I’m trying to use the extension, but all my tests fails because there’s missing ENV variables required to make my tests work. My test script looks like this dotenv -e .env.test jest and it works fine, but not with the extension. I tried using jest.pathToJest and set it to npm run test --, but I run into the #316 issue, because I’m using ts-jest. Is there another alternative to my problem?

Thank you.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:9
  • Comments:16

github_iconTop GitHub Comments

27reactions
ejose19commented, Sep 9, 2019

You can set environment variables in jest.config.js

ie:

process.env.YOUR_VARIABLE = "here";

module.exports = {
  preset: "ts-jest",
  testEnvironment: "node"
};

I didn’t found any direct way to set the env variables directly within the extension.

5reactions
nublsoncommented, Jan 24, 2020

I had the same problem, when saving the test file it used .env instead of .env.testing, all I did was import the variables from this file before anything in my test file.

require('dotenv').config({
	path: '.env.testing'
})

const request = require('supertest')
const app = require('../src/app')

test('Should sign up a new user', async () => {
	await request(app)
		.post('/users')
		.send({
			name: 'myName',
			email: 'myemail@email.com',
			password: '12345678'
		})
		.expect(201)
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set environment variables for system extension
Hi Experts, I knew there is LSEnvironment for defining environment variables to be set before launching. e.g. <key>LSEnvironment</key>
Read more >
How to set environment variables for system extension
I knew the LSEnvironment is for defining environment variables to be set before launching the App. <key>LSEnvironment</key> <dict> ...
Read more >
Environment Variables - Visual Studio Marketplace
To use the task, go to your pipeline -> build definition and add "Environment Variables" to your build definition. Config. Environment Variables ......
Read more >
Environment variables in Compose | Docker Documentation
If you have multiple environment variables, you can substitute them by adding them to a default environment variable file named .env or by...
Read more >
Environment variables and program arguments - JetBrains
Add environment variables ... Type the variable name and value: <name>=<value> . If you add several variables, they should be separated with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found