Why does running `jasmine` after `jasmine init` and `jasmine examples` do nothing? - node.js

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

Related

Run E2E tests in IDE or command line

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

How to set karma config entry through command-line?

I have an automated process to do the following (I have a Jenkins setup to do the following):
clone project
npm install
grunt
The grunt execution fails because of the following error
[PhantomJS 2.1.1 (Windows 8 0.0.0)]: Disconnected (1 times), because no message in 10000 ms.
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR
I found that setting browserNoActivityTimeout: 10000 in karma.conf.js file I solved the problem. But I did it manually (edited the conf file and added an entry).
As I have an automated process, I want to be able to set browserNoActivityTimeout: 10000 through command-line (example like npm config set registry= so that grunt executes properly.
Is there any way to do this?
Copy your original karma.conf.js into a separate karma-no-act-timeout.conf.js file (probably name it better than I did here), drop browserNoActivityTimeout: 10000 in there and then bootstrap the command lines in your package.json file like this:
"scripts": {
"unit-test": "karma start ./config/karma.conf.js",
"unit-test-no-timeout": "karma start ./config/karma-no-act-timeout.conf.js",
},
Now you can call either the original script using:
npm run unit-test
or call the one with browserNoActivityTimeout using
npm run unit-test-no-timeout in the command line.
As you noticed, these karma.conf files are in config folder. If your structure differs, update your npm script commands.

Configure Mocha / NodeJS within VS Code - location of test folder - test files(s) undefined

Mocha is installed and runs fine through Terminal, Mocha Sidebar extension added in VS Code, however when using within VS Code it doesn't appear to find any tests within either a test folder I have set up, or a test folder I navigate to within VS Code
How do you alter the Mocha settings within VS Code to point it to a different/ correct location for the /test folder?
Is it possible to run tests on a folder you navigate to within VS code explorer and how to config that?
In the Output I am currently seeing the below:
Finding tests with Mocha on Node.js at "/usr/local/bin/node"
Running Mocha with Node.js at "/usr/local/bin/node"
No Mocha options are configured. You can set it under File > Preferences > Workspace Settings.
Test file(s):
undefined
I had this issue, and a couple of things solved it:
npm install -g glob
npm install -g mocha
npm install -g bluebird
Add "mocha.options": {} to the workspace configuration.
Add a glob option to the workspace configuration.
Restart VSCode.
Apparently not having global glob, mocha, and bluebird installed will cause it to fail on this.

Cucumber Js - How to run the features [Windows]

I'm trying to learn cucumber and so far got a grip on installing nodejs, cucumber, creating package.json, storing features files and steps. But when I'm trying to run using windows command prompt, I'm getting the below shown error.
project structure
features
- example.feature
- step_definitions
- steps.js
- support (nothing here yet)
node_modules (cucumber installed locally)
package.json
I started executing commands from the bin folder to ensure cucumberjs works and it echo'd out the version number 3.1.0
C:\Test Project\node_modules\.bin>cucumberjs -v
and then began to run the feature file
C:\Test Project\node_modules\.bin>cucumberjs "C:\Test Project\features\example.feature"
and it errors here
Note: If i install the cucumber globally then it works, this error happens when I install cucumber locally
Any help pointing out where I'm going wrong will be much appreciated
I haven't figured out what's the reason behind the error but managed to run the features files by adding the following to the project package.json and running cli npm run cucumber
"scripts": {
"cucumber": "cucumberjs ./features"
},

atom + mocha on windows = spawn mocha ENOENT

My goal is to run mocha unit tests by Atom, which is installed on Windows and also my src code resides. this should work independently from my Meteor App which is running on a different (Linux) machine.
Basically my setup is like this:
I have my repo and sourcecode:
c:\Users\Me\repos\meteor
My tests are inside:
c:\Users\Me\repos\meteor\tests
I have Node:
c:\Program Files\nodejs
installed with "npm i -g mocha --save-dev"
And i try to use this package https://github.com/Tabcorp/atom-mocha-test-runner but i can switch to another package if necessary.
What I've tried so far:
I edited my settings for the atom-mocha-test-runner:
Mocha command: C:\Program Files\nodejs\node_modules\mocha\.bin\mocha
Mocha command: C:\Program Files\nodejs\npm mocha
But each time i try to run my test via dropdown menu (Run Mocha Test), i get this error:
Mocha Test Results:
Node binary: C:\Program Files\nodejs\node.exe
Root folder: C:\Source\Repos
Mocha command: undefined
Path to mocha: mocha
Debug-Mode: false
Test file: tests\unit\first.js
Selected test: should return url
Failed to run Mocha
spawn mocha ENOENT
Anyone know what i miss or do wrong?
Still having no idea about why the package isn't working, I'm going to give a cop-out answer. If we figure out how to make it work, you can accept that answer instead. process-palette gives you the ability to run highly specific command-line instructions from Atom commands. Here's an example of a command that runs mocha in the project path for the current file with the same hotkey and also conveniently organized into its own menu item:
The disadvantage of this approach is that you have to know how to use the external program yourself. Packages like mocha-test-runner are designed to remove that need from the user, but as we can see here, sometimes the package doesn't know what it needs to be doing. The disadvantage is mitigated by the fact that you only have to learn the command for long enough to set up the configuration to run it, and from that point on it's very easy.
Advantages versus other packages include the ability to precisely control what's going on. Say you have multiple top-level folders in the current project, and they have different test suites. A package like mocha-test-runner can get the path from the active file, or from the project. If the developer chose to grab the project path, then you're going to have trouble running individual test suites. With the configuration I've shared, the command will always be run in the absolute path of the current file's project folder, so the tests will be run for whichever file you're working on at the time.

Resources