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
Related
I'm making an API using TypeScript, node.
I'm using jest to make some tests
I have two different routes, "/users" and "/authentication", when I run one route at a time it runs ok, but when I run all tests together one of my tests returns me a 500 status code.
I'm running it in node v16.17.0
jest: v29.3.1
When I run $npm run test users
When I run $npm run test authentication
When I run $npm run test
Thats my test scipts:
"test:load-envs": "dotenv -e .env.test", "test": "npm run test:load-envs npx jest",
I've tested it manually throught thunderClient and the error case runs fine...
On thunderClient trying to emulate the error:
I searched for someone with a similar error but I couldn't find an answer to my problem.
I can ignore this since it's a personal project, but I really would like to know how to solve it
I'm trying run Angular's e2e tests against an instance of the application ON A DIFFERENT SERVER than my local machine.
So to be clear, I'm not testing my local code.
I just need to run protractor without the angular build steps because it's a waste of time since the code I'm testing is on another server. Unfortunately, the angular.json file throws an error if i excessively modify/remove the following line:
"builder": "#angular-devkit/build-angular:protractor",
I already have a solution for this, but it's long winded and I'd like to be able to not change how my teammates are running tests from their shells:
node node_modules/protractor/bin/protractor e2e/protractor.conf.js
I have two thoughts:
Write npm script which runs this command (what i'll likely end up doing)
Find out how to overwrite what ng e2e does. If I can run the more complicated command here, it'll save productivity and feedback time.
I'm on Angular V7.
Is overwriting ng e2e so that it executes node node_modules/protractor/bin/protractor e2e/protractor.conf.js instead possible?
Yup. I would do #1. That makes sense to update your package.json
"scripts": {
"protractor": "protractor e2e/protractor.conf.js"
}
and then just run npm run protractor. The e2e command is also downloading chromedriver, the selenium jar file, and maybe geckodriver? with webdriver-manager. If you want that as a pre-step:
"scripts": {
"protractor": "protractor e2e/protractor.conf.js",
// just download chromedriver and the selenium jar
"preprotractor": "webdriver-manager update --gecko false"
}
It also starts your angular application. If you need to do that, I would just call ng serve and run it in a background process. I hope that helps.
While creating package.json from command line using npm init for creating a module in Node.js, there is a test command field that I don't know about. There's no mention of it in the docs too on executing npm help json also in the CLI.
Please explain what it is about.
The test command is the command that is run whenever you call npm test.
This is important when integrating with continuous integration/continuous deployment tools (such as jenkins, codeship, teamcity).
Example:
- say you deploy a project to AWS or some other cloud hosting provider,
- you can set up your infrastructure to automatically run npm test.
- If there are problems within those tests, your ci/cd will automatically rollback before deploying.
To execute tests
You can use karma, jest, or selenium/nightmare/phantomjs or about any other test scripting library/framework that allows you to write and execute tests and then set the required command in scripts.test and finally run it from npm test.
Assuming you mean scripts.test:
"scripts" : {
"test" : "echo \"Error: no test specified\" && exit 1"
}
This field contains the program(/command line) that should run when you call npm test. Typically, that program is a test-runner like mocha, ava, jest, ...
The default value is a placeholder that prints an error message (try running npm test in the same directory as your package.json).
Currently, I have two folders: __tests__ for unit (fast) tests and __integration__ for slow tests.
Then, in package.json:
{
"scripts": {
"test": "jest",
"test:integration": "jest -c '{}'",
...
},
"jest": {
"testPathIgnorePatterns": ["/node_modules/", "__integration__"]
}
}
So, when I want to do TDD, I'm running just npm test and when I want to test the entire project, npm run test:integration.
As Jest is offered as a "no configuration" test framework, I was thinking if there's a better (or proper) way to configure this.
Thank you.
Quoting from this post.
You can try name files like:
index.unit.test.js and api.int.test.js
And with Jest’s pattern matching feature, it makes it simple to run
them separately as well. For unit testing run jest unit and for
integration testing run jest int.
File structure/location you can define based on your preferences as the pattern matching based on the file name is how jest knows what to run.
Also see jest cli documentation about npm scripts:
If you run Jest via npm test, you can still use the command line
arguments by inserting a -- between npm test and the Jest arguments
Have you tried jest --watch for TDD? It runs only files related to your git changes, runs errors first and heavily utilise cache for speed.
Other than that, jest -c accepts a path, not a string. You should be good with jest -c jest-integration-config.json, provided that jest-integration-config.json sits in your project's root.
I have globally installed jasmine by running npm install jasmine -g.
Running jasmine -v gives me
jasmine v2.5.0
jasmine-core v2.5.0
I have then, as per the docs, run
jasmine init
jasmine examples
This created the expected /spec directory and the spec/support/jasmine.json file.
I am under the impression that if I now run jasmine I should see some test output in the console. Instead it simply thinks about it for a second and then does nothing.
I'm running node v4.5.0 on a Windows 7 machine in a Git Bash terminal. I've tried running it from the Windows cmd prompt as well but that doesn't work either.
well jasmine does run, but it doesn't report anything when you run jasmine alone. (you can confirm that by putting console.log inside describe functions and see that indeed it will log.)
download the latest release, it will have an html file that you can run which will do all the work for you.
https://github.com/jasmine/jasmine/releases
basically running jasmine requires a boot.js file for configurations. a jasmine-html.js file for the html reporter. you can figure out everything yourself by running the SpecRunner.html.
my personal preference is to use protractor and have the reporter configured in the protractor.config file.
if you want to run jasmine and have it run, you need to add your own boot.js and reporter, and loading them first thing before the spec in the jasmine.json file.
{
"spec_dir": "spec",
"spec_files": [
"boot.js",
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
],
"stopSpecOnExpectationFailure": false,
"random": false
}
It's a bug in jasmine
https://github.com/jasmine/jasmine-npm/issues/90
Use version 2.4
npm install -g jasmine#~2.4