vscode-testcafe icon indicating copy to clipboard operation
vscode-testcafe copied to clipboard

Setting up environment variables

Open ArisuRen opened this issue 6 years ago • 2 comments

Hello, it might be will be beneficial to add possibility to setup environment variable before running testCafe runner extension? If you have different production environments, Tester can test it in development, on staging or live. Please let me know if it can be added there, thank you a lot in advance.

PS. I have found workaround so if this is not needed, please delete/close this issue. thank you

ArisuRen avatar Jan 20 '20 11:01 ArisuRen

@ArisuRen - Could you explain your workaround that you figured out?

I have code in my files that dynamically edits teh URL of pages depending on an ENV variable. I'd like to define this using the Extension

Tall-KU-RideOn avatar May 04 '22 21:05 Tall-KU-RideOn

Hello, unfortunatly this was 2 years ago, and I do not remember for 100% but I think at that time I did this workaround: In .ts file used this code

//chooses which config to use
var config = (process.env.DEV_MODE === "true" || process.env.DEV_MODE === undefined) ? require("../config.json") : require("../config.prod.json")

and in package.json when starting script I had this

    "test": "set DEV_MODE=true&& node ./testcafe.config.js",
    "test_prod": "set DEV_MODE=false&& node ./testcafe.config.js",

Right now I do it a little bit differently since I have more then 2 env versions:

//chooses which config to use
let env = process.env.ENV;
let config;
switch (env) {
    case "STAG": {
        config = require('../config/config.stag.json');
        break;
    }
    case "PROD": {
        config = require("../src/config/config.prod.json");
        break;
    }
    case "UAT": {
        config = require("../src/config/config.uat.json");
        break;
    }
    case "AWS": {
        config = require("../src/config/config.aws.json");
        break;
    }
    default: {
        console.log('config file not defined');
    }
}

and package.json

    "test-stag": "export ENV=STAG && npx codeceptjs run --steps",
    "test-uat": "export ENV=UAT && npx codeceptjs run --steps",
    "test-prod": "export ENV=PROD && npx codeceptjs run --steps",
    "test-aws": "export ENV=AWS && npx codeceptjs run --steps",

I hope my answer will help you.

ArisuRen avatar May 05 '22 07:05 ArisuRen