Have you already seen this? My colleague with an Intel mac is able to run test with the same command but my m1 complains it doesn't find any test although it clearly says that it matched 10 files
> jest --setupFiles dotenv/config
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /folder
505 files checked.
testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 10 matches
testPathIgnorePatterns: .d.ts, .js - 0 matches
testRegex: - 0 matches
Pattern: - 0 matches
ELIFECYCLE Test failed. See above for more details.
I should add that running the same command in a node docker container (just mounting the folder) works as expected
Related
I am trying to run a script which needs node. I have node installed in my machine.
I can run sh_binary by bazel run //:sh_bin and the script runs node just fine:
sh_binary(
name = "sh_bin",
data = [
],
srcs = [":script.sh"],
)
script.sh:
node -v
bazel run //:sh_bin:
v14.17.6
Now I want to convert this to sh_test:
sh_test(
name = "sh_bin",
data = [
],
srcs = [":script.sh"],
)
but now bazel test //:sh_bin cannot find node:
node: command not found
I also tried to add local = True to the test and still the same issue.
Bazel tests are run in a more controlled environment than application run via bazel run. One of the initial conditions that the test runner establishes is the value of $PATH: https://docs.bazel.build/versions/main/test-encyclopedia.html#initial-conditions
If you are working with remote execution, another problem could be that your test is executed on a machine that does not have node installed.
It's always a great idea to strive for a hermetic build that runs and tests independent of the host's state. That means you'd need to make the node program available to your binary or test as a data dep.
A good alternative is to build on existing work such as https://github.com/bazelbuild/rules_nodejs.
That being said, your example actually works for me.
cd `mktemp -d`
touch WORKSPACE
echo "node -v" > script.sh
chmod +x script.sh
cat <<EOF > BUILD
sh_test(
name = "sh_bin",
srcs = [":script.sh"],
)
EOF
bazel test --test_output=all -- //:sh_bin
Starting local Bazel server and connecting to it...
INFO: Analyzed target //:sh_bin (24 packages loaded, 282 targets configured).
INFO: Found 1 test target...
INFO: From Testing //:sh_bin:
==================== Test output for //:sh_bin:
v17.1.0
================================================================================
Target //:sh_bin up-to-date:
bazel-bin/sh_bin
INFO: Elapsed time: 6.895s, Critical Path: 0.10s
INFO: 5 processes: 3 internal, 2 linux-sandbox.
INFO: Build completed successfully, 5 total actions
//:sh_bin PASSED in 0.0s
Executed 1 out of 1 test: 1 test passes.
INFO: Build completed successfully, 5 total actions
Jest is throwing an error stating it cannot find the module specified by path in jest.mock()
> jest
FAIL test/userSelect.test.ts
● Test suite failed to run
Cannot find module '../src/actions/selectUserById' from 'test/userSelect.test.ts'
8 |
9 | jest.mock('mysql');
> 10 | jest.mock('../src/actions/selectUserById');
11 |
12 | const mockSelectUserById = selectUserById as jest.MockedFunction<
13 | typeof selectUserById
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:306:11)
00:00
at Object.mock (test/userSelect.test.ts:10:6)
The strangest part is this:
this test passes on my local machine, but it fails in the CI service we are using.
In case anyone else is troubleshooting a similar issue,
I finally realized the root-cause of the failing test was a difference in case-sensitivity of the specified path.
In my case the true filename is src/actions/selectUserByID (notice the uppercase letter 'D'),
but the string I passed to Jest.mock() is selectUserById.
At some point, I renamed the file locally, which is why the test passes as expected on my machine. However, I learned a case-sensitive change to a filename is not detected as a change by git, which is why the CI service still had the erroneous filename.
I used git mv to commit the case-sensitive filename, and this resolved my issue.
I am using JHipster v5.8.2 on Windows operating system and I am trying to run Jest client side tests by running the command:
npm test
But I get an error that says:
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In C:\IdeaProjects\pomzen
274 files checked.
testMatch:
C:/IdeaProjects/pomzen/src/test/javascript/spec/**\+(*.)+(spec.ts) - 0
matches
testPathIgnorePatterns: \\node_modules\\ - 274 matches
testRegex: - 0 matches
Pattern: - 0 matches
npm ERR! Test failed. See above for more details.
I recently also had this problem. I used workaround from here:
https://github.com/DorianGrey/ng-webpack-template/pull/22/commits/fe95926607ed8bd01476c7d04b5b930a965ad282
Fix:
Open jest.conf.js file
Replace
testMatch: ['<rootDir>/src/test/javascript/spec/**/+(*.)+(spec.ts)']
with
testMatch: ['**/*.spec.ts']
I am running my protractor tests in PhpStorm 8.0.1. The issue is despite of providing the parameter correctly in Application parameters section, the script does not run, and even then it outputs a success run in the console. Here is the output.
[12:45:30] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[12:45:30] I/launcher - Running 1 instances of WebDriver
Started
1..0 # All tests disabled
# 0 specs, 0 failures, 0 skipped, 0 disabled in 0.014s.
# NOTE: disabled specs are usually a result of xdescribe.
SUCCESS: 0 specs, 0 failures, 0 skipped, 0 disabled in 0.015s.
No specs found
Finished in 0.016 seconds
[12:45:34] I/launcher - 0 instance(s) of WebDriver still running
[12:45:34] I/launcher - chrome #01 passed
Process finished with exit code 0
My application parameter is configured like this.
http://screencast.com/t/HOqAW6ya4oe
And here is my folder structure which accordingly is correctly configured.
http://screencast.com/t/xK98JrDlc2a
This was working earlier fine and now all of a sudden I get this output. Any suggestions on how to resolve this would be of great help.
specs: [ '../specs/WP-lam_spec.js' ], I think it is a couse change it to :
specs: ['spec/**/*[sS]pec.js'],
so it will start all your specs you got in your spec folder, also i think it might be problem with lack of '' in parameter from screenshot so just change to:
protractor --specs='path\to\file.spec.js'
My spec.js file was in src.com.sam.scriptjs package so giving like below in config.js was solved my issue .
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['src/com/sam/scriptjs/firstScript.js']
}
If the tests are in the same folder as the config file, you can try to add ./ before your spec:
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['./helloWorld.js']
}
How do I run Jasmine tests on Node.js from command line? I have installed jasmine-node via npm and written some tests. I want to run tests inside the spec directory and get results in the terminal, is this possible?
This should get you going quickly:
install Node.js (obviously).
Next install Jasmine. Open a command prompt and run:
npm install -g jasmine
Next, cd to any directory and set up an example 'project':
jasmine init
jasmine examples
Now run your unit tests:
jasmine
If your jasmine.json file is somewhere else besides spec/support/jasmine.json, simply run:
jasmine JASMINE_CONFIG_PATH=relative/path/to/your/jasmine.json
For more info see:
https://www.npmjs.com/package/jasmine
http://jasmine.github.io/2.2/node.html
EDIT
It seems this is no longer the current best answer as the package is unmaintained. Please see the answer below
You can do this
from your test directory
sudo npm install jasmine-node
This installs jasmine into ../node_modules/jasmine-node
then
../node_modules/jasmine-node/bin/jasmine-node --verbose --junitreport --noColor spec
which from my demo does this
Player - 5 ms
should be able to play a Song - 2 ms
when song has been paused - 1 ms
should indicate that the song is currently paused - 0 ms
should be possible to resume - 0 ms
tells the current song if the user has made it a favorite - 1 ms
#resume - 0 ms
should throw an exception if song is already playing - 0 ms
Player - 5 ms
should be able to play a Song - 2 ms
when song has been paused - 1 ms
should indicate that the song is currently paused - 0 ms
should be possible to resume - 0 ms
tells the current song if the user has made it a favorite - 1 ms
#resume - 0 ms
should throw an exception if song is already playing - 0 ms
Finished in 0.01 seconds
5 tests, 8 assertions, 0 failures, 0 skipped
The easiest way is to run the command in your project root:
$ npx humile
It founds all your specs which name ends with .spec.js.
If you think humile is fine for your project, just install it as dev dependency. It speeds up the command.
$ npm install -D humile
Try Karma (formerly Testacular), it is a testing library agnostic test runner done by Angular.js team
http://karma-runner.github.io/0.12/index.html
Jasmine support is well baked.
http://karma-runner.github.io/0.12/intro/how-it-works.html