How can I pass in custom Node process.env variables on the protractor command line when I run my tests?
My protractor E2E tests using Angular work great from IntelliJ. In my IntelliJ Run/Debug configuration, I provide environment variables, such as USER_EMAIL, USER_PASSWORD, APP_URL and some others. I want to do this with the protractor cli so I can run these tests from terminal.
I can run tests from terminal only when I edit the protractor.conf.js file. I am not sure of how to specify the process.env variables on the command line. I do not want to edit protractor.conf.js as it is shared by many engineers.
Is there a way to pass in these process.env variables using the protractor cli?
This is the cli command I am running.
protractor protractor.conf.js --specs ./test/ui/my-tests/myspec.ts
use cross-env, you can set the environment variable in one command line together with actual command to execute, no need to export/set environment varaible ahead actual command. And cross-env is cross platform.
Example:
cross-env USER_EMAIL=abc#123.com APP_URL=http://abc.123.com protractor protractor.conf.js --specs ./test/ui/my-tests/myspec.ts
Related
I am trying to add the environment variables to the node process on start using CMD. I want achieve this without using the script in package.json & not using the dotenv package
I'm going through one of the node.js lectures & found the below command which will set the environment variables to the node process as below :
NODE_ENV=development nodemon server.js
After some research I found that it is different for windows & as below :
SET NODE_ENV=development&&nodemon server.js
I tried the same in the cmd but got the error message NODE_ENV is not recognized as an internal or external command.
Just wanted to know how in CMD this adding environment variables works
I am getting an error message:
"C:\Program Files\nodejs\node.exe" C:\Users\keechan\Desktop\NodeJS\my-module\tests\sample.test.js
ReferenceError: describe is not defined
This issue only happens when I run via Run (ctrl+shift+F10).
When I run via the Debug Configuration I created, it works okay.
But considering if I have many test.js files and I want to be able to run each individual test suite, I do not want to have to make a debug configuration for each one of them.
I already tried:
installing #types/jest library under settings (Languages & Frameworks > JavaScript > Libraries)
added #types/jest as well as jest in my package.json
Also, I noticed that it is calling node.exe in:
"C:\Program Files\nodejs\node.exe" C:\Users\keechan\Desktop\NodeJS\my-module\tests\sample.test.js
Maybe this is the reason why? So how do I change it to use jest?
Thank you so much!
You are not running Jest, you run your spec file by passing it directly to Node.js using Node.js run configuration. Make sure to use Jest run configuration to start your spec
I'm using Stencil.js to create a web component library and I'm heavily relying on E2E tests. As they're rather slow it becomes more and more cumbersome to run the entire test suite (using the Stencil.js CLI) while developing new components.
However, I'm not able to run single tests in my IDE (IntelliJ IDEA) or via command line. It works perfectly fine for unit tests though.
My Jest config looks like this:
module.exports = {
"roots": [
"<rootDir>/src"
],
"preset": "#stencil/core/testing"
}
When I try to run tests in a single file (jest --config jest.config.js --testPathPattern src/components/button/button.e2e.ts$)
it fails, because
newE2EPage() is only available from E2E tests, and ran with the --e2e cmd line flag.
newE2EPage() comes with Stencil.js and I don't know what Stencil.js's CLI does in the background. Furthermore, I cloned the Stencil.js repository, just to see if it is working with their E2E tests (https://github.com/ionic-team/stencil/tree/master/test/end-to-end) but it doesn't work either.
Any idea how I can configure Jest so that it's able to run Stencil.js-E2E tests from the command line?
The --e2e flag is used for the npm script in the package.json. To start e2e tests, you can add this in your package.json:
"scripts": {
"test:e2e": "stencil test --e2e"
}
And run npm run test:e2e. For a specific file, you add it at the end like this:
npm run test:e2e src/components/button/button.e2e.ts
For more info, see the StencilJS doc: https://stenciljs.com/docs/end-to-end-testing
i have the same problem. IntelliJ and 'Run' single 'it' didnt work.
newE2EPage() is only available from E2E tests, and ran with the --e2e cmd line flag.
when i run 'npm run test' everything will work fine. the difference is that npm run stencil before and only jest dont work.
here is the stencil jest dir https://github.com/ionic-team/stencil/tree/master/src/testing/jest aswell a config.
i found in here https://stenciljs.com/docs/testing-overview a VS-CODE run jest code but no Intellij setup.
im on the run to get the path of the current file to run stencil via npm and the path the e2e file. but i cant find the correct variable for the run config.
i hope we got this solved soon.
cheers
I am not a VS Code user, but in contrast to IntelliJ there is a launch.json for VSC to run single tests: https://github.com/ionic-team/stencil-site/pull/480
I've written a Casperjs script to do some scraping, however, after running into memory exhaustion issues, I've now written a node script to turn Phantom off and on via exec. I can run this with no issues locally, however when I deploy to heroku I get the following error
Error: Command failed: casperjs turnitoffandon.js
ERROR: stderr was:/bin/sh 1: casperjs: not found
I used the nodejs buildpack and have Phantom and Casper defined in my dependencies. In the heroku bash, running phantomjs --version returns 2.1.1 and casperjs --version returns 1.1.4.
Do I need to define where Casper is? If so how? I have set my PATH variable as /usr/local/bin:/usr/bin:/bin:/app/vendor/phantomjs/bin:/app/vendor/casperjs/bin:/node_module/casperjs/bin , like in this SO question
The issue actually had nothing to do with Heroku. As noted in this SO answer, using exec and providing any environmental variables in the options parameter replaces the entire set of environment variables. This includes the path, effectively overwriting any paths already specified to Heroku in the buildpack and npm modules.
You can create a copy of process.env and pass that along in the parameters in addition to other environmental parameters needed to be passed.
I have node project that contains .bat file to set all the env variables & then it run my server.js .
How can i achieve the same using IDE?
Currently when i am trying to run the code from atom ide its giving error for those environment variables not set as they are required to run my project.
While running from command prompt i can simply run the .bat file which sets all the environment variables required for my project followed by "node server.js" command to run my project.
But from atom IDE when i run server.js it is not able to find the environment variables. How can i define/set these environment variables so that the atom IDE can read it & use them when i run server.js.??
Install XAtom NodeJS Debugger: apm install xatom-debug-nodejs
Toolbar will be shown,
Choose your project,
click on Node.js button and in the popup shown configure your project setting and
environment variables.