I am very new to Jest, so I'm trying to run my tests serially using the command yarn jest test -i (same for yarn jest test --runInBand according to Jest documentation).
This is my test files tree:
❯ cd src/test
vipires in scheduling-engine-test/src/test on master
❯ tree
.
├── customer
│ └── clean.test.ts
├── engine
│ └── job.test.ts
└── schedule
├── create.test.ts
└── generateSchedules.test.ts
3 directories, 4 files
The issue is that my project has 4 test files which only one is being tested when I run this command above, it quits occasionally after the first file such as generateSchedules.test.ts
The reason why I need to do it serially is that I'm using Jest for integration tests against an REST API and querying an Oracle Database, so when I run just the command yarn jest test, jest triggers some workers and run all the tests in parallell. It result in some assertion problems because every test file has an beforeAll() and afterAll() methods that delete all my test data generated during test execution.
Below it is my terminal log output for the command I´ve told:
❯ yarn jest test --runInBand
knex:query update "ENGINE_TASK" set "DAT_EXECUTION" = :1 where "IDT_ENGINE_TASK" in (:2, :3, :4, :5, :6) trx1 +0ms
knex:query update "TASK" set "DAT_EXECUTION" = :1 where "IDT_TASK" in (:2, :3, :4, :5, :6) trx1 +63ms
knex:query select * from "ENGINE_TASK" where "IDT_ENGINE_TASK" in (:1, :2, :3, :4, :5) trx3 +165ms
knex:query delete from "ENGINE_TASK" where "IDT_CUSTOMER_ID" = :1 trx5 +6s
knex:query delete from "TASK" "T" where exists (select * from "SCHEDULE" "S" where "IDT_CUSTOMER_ID" = :1 and t.idt_schedule = s.idt_schedule) trx5 +55ms
knex:query delete from "CUSTOMER_EXECUTION_FLAGS" where "IDT_CUSTOMER_ID" = :1 trx5 +70ms
knex:query delete from "SCHEDULE" "S" where "IDT_CUSTOMER_ID" = :1 trx5 +50ms
PASS src/test/schedule/generateSchedules.test.ts (15.647 s)
✓ generate schedules for today (8644 ms)
✓ should block delete on scheduled task (2464 ms)
✓ should permit delete on scheduled task (3173 ms)
RUNS src/test/engine/job.test.ts
vipires in scheduling-engine-test on master took 21s
Notice that the last log line from Jest was RUNS src/test/engine/job.test.ts and then the following line is from my terminal again informing that the execution took 21 seconds.
It was very hard to me to explain that behavior since I wasn't able to find any occurrence of this problem before at Jest documentation nor Stackoverflow. I've tried to discourse about the execution in way to make this post shorten, but anyway if more code is needed to investigate this behavior just let me know.
Node and OS info:
Node version: v14.16.1
Yarn version: v2.4.1
Jest version: 26.6.2
Model Name: MacBook Pro
Model Identifier: MacBookPro 11,4
Processor Name: Quad-Core Intel Core i7
Processor Speed: 2,2 GHz
Number of Processors: 1
Total Number of Cores: 4
L2 Cache (per Core): 256 KB
L3 Cache: 6 MB
Hyper-Threading Technology: Enabled
Memory: 16 GB
Boot ROM Version: 199.0.0.0.0
SMC Version (system): 2.29f24
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
I am trying to run a small test collection with Cypress using the cucumber plugin and the official Circle-ci Orb.
I've been going through the documentation and I've got them running without issues locally. The script I'm using to run them locally is this one:
"test:usa": "cypress-tags run --headless -b chrome -e TAGS='#usa'"
*Note the cypress-tags command and the TAGS option.
For the CI I use the official Circle-ci Orb and have a configuration like this:
- cypress/run:
name: e2e tests
executor: with-chrome
record: true
parallel: true
parallelism: 2
tags: 'on-pr'
group: 2x-chrome
ci-build-id: '${CIRCLE_BUILD_NUM}'
requires:
- org/deployment
As you can read, I want to raise 2 machines where I divide my feature files, setting the tag to 'on-pr' and grouping the run under '2x-chrome' using as well the ci-build-id.
The thing is that the official Orb uses the cypress run command which does not filter scenarios by their tags, so it is of no use here. My options were:
Using the command parameter in the orb to call the required script as I do locally:
command: npm run test:usa
My problem with this option is that the parallel configuration does not work as expected so I discarded it.
I tried to pass the TAGS parameter as an env var within the Circle-ci executor to see if the Orb was able to see it, but it was of no use as the Orb does not use cypress-tags run but cypress run.
environment:
TAGS: '#usa'
At this point my question is, is there a workaround to this (using cypress-tags in the Circle-ci orb) or shall I opt for a different way of testing this?
Thanks in advance
I hope for your help. I installed Cypress in Linux and test successfully runs manually on the command cypress run --record --key *******
However, when I write the command to Cron, the test doesn't run. There are no errors in the console. Cron is working. Other commands, such as date and time output, work fine.
I did this:
Created a bash-script.sh with the following content
#!/bin/bash
cd /home/ubuntu/project-name/cypress
/home/ubuntu/project-name/cypress/node_modules/.bin/cypress run --record --key *****************
Put the bash-script file into the folder /home/ubuntu/. This is now the path to the script /home/ubuntu/bash-script.sh
Via the command 'crontab -l ' scheduled the following command */5 * * * * /home/ubuntu/bash-script.sh >> /home/ubuntu/bash-script-log.log
But the scheduled command is not executed. The logs are empty. Can you tell me what I'm doing wrong?
Try to write the PATH variable at the beginning of the bash script. Just execute echo $PATH; in your terminal/bash and copy the result to make PATH variable as follows.
Let's first make sure that cypress is working in bash and then We will trigger this in crontab.
#!/bin/bash
PATH=/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
## Set your cypress folder
yourfullpathtocypressfolder=/home/ubuntu/project-name/cypress;
## Check that we can echo cypress version
$yourfullpathtocypressfolder/node_modules/.bin/cypress -v >> Iamalive.log
After setting variable yourfullpathtocypressfolder Save your script as myscript.sh. try run this script as bash myscript.sh in your terminal.
As for the complete code to record your project using crontab as follows.
Make sure that you are updated your projectID in cypress.json!
You can also check this gist https://gist.github.com/senniksoft/0e062165fb9121be8d8a0fca4038fbc1
#!/bin/bash
PATH=/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
## Set your cypress folder
yourfullpathtocypressfolder=/home/ubuntu/project-name/cypress;
## Set your project key
yourprojectkey=xxxxxxxx-c69f-4c44-81c9-xxxxxxxxxxxxx;
cd $yourfullpathtocypressfolder;
## Example Code to record
./node_modules/.bin/cypress run --record --key $yourprojectkey --spec "cypress/integration/examples/actions.spec.js" >> RecordLog.log
After that give proper permissions so that crontab can execute the script.
chmod +x /home/ubuntu/myscript.sh;
Add this script to crontab as follows
*/5 * * * * bash /home/ubuntu/myscript.sh
Example output in the log after running this script.
====================================================================================================
(Run Starting)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 5.1.0 │
│ Browser: Electron 83 (headless) │
│ Specs: 1 found (examples/actions.spec.js) │
│ Searched: cypress/integration/examples/actions.spec.js │
│ Params: Tag: false, Group: false, Parallel: false │
│ Run URL: https://dashboard.cypress.io/projects/2bn65e/runs/2 │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: examples/actions.spec.js (1 of 1)
Estimated: 22 seconds
Actions
✓ .type() - type into a DOM element (7441ms)
✓ .focus() - focus on a DOM element (469ms)
✓ .blur() - blur off a DOM element (741ms)
✓ .clear() - clears an input or textarea element (790ms)
✓ .submit() - submit a form (670ms)
✓ .click() - click on a DOM element (2705ms)
✓ .dblclick() - double click on a DOM element (476ms)
✓ .rightclick() - right click on a DOM element (360ms)
✓ .check() - check a checkbox or radio element (1114ms)
✓ .uncheck() - uncheck a checkbox element (1160ms)
✓ .select() - select an option in a <select> element (1068ms)
✓ .scrollIntoView() - scroll an element into view (798ms)
✓ .trigger() - trigger an event on a DOM element (383ms)
✓ cy.scrollTo() - scroll the window or element to a position (2321ms)
14 passing (24s)
I run Appium node.js tests on AWS Device Farm. I would like to get granular Test results shown in Device Farm, but I always get one "Tests Suite" result which inlcudes all tests. So if one small test failes the whole Test Suite fails.
I read in the Device Farm Docs that in a Standard Environment more granular results will be displayed, but I am not sure how to switch or use standard environment. I asume it has something to do with the YAML File as the possibility to select between standard or custom environment is not longer given on the Device Farm UI.
This is my current YAML File:
version: 0.1
# Phases are collection of commands that get executed on Device Farm.
phases:
# The install phase includes commands that install dependencies that your tests use.
# Default dependencies for testing frameworks supported on Device Farm are already installed.
install:
commands:
# By default, Appium server version used is 1.7.2.
# You can switch to an alternate supported version from 1.6.5, 1.7.1, 1.7.2, 1.8.0 , 1.8.1, 1.9.1 by using a command like "avm 1.7.1"
# OR
# To install a newer version of Appium use the following commands:
- export APPIUM_VERSION=1.9.1
- avm $APPIUM_VERSION
- ln -s /usr/local/avm/versions/$APPIUM_VERSION/node_modules/.bin/appium /usr/local/avm/versions/$APPIUM_VERSION/node_modules/appium/bin/appium.js
# By default the node version installed is 11.4.0
# you can switch to an alternate node version using below command.
# - nvm install 10.13.0
# Unpackage and install the node modules that you uploaded in the test phase.
- echo "Navigate to test package directory"
- cd $DEVICEFARM_TEST_PACKAGE_PATH
- npm install *.tgz
# The pre-test phase includes commands that setup your test environment.
pre_test:
commands:
# We recommend starting appium server process in the background using the command below.
# Appium server log will go to $DEVICEFARM_LOG_DIR directory.
# The environment variables below will be auto-populated during run time.
- echo "Start appium server"
- >-
appium --log-timestamp --device-name $DEVICEFARM_DEVICE_NAME
--platform-name $DEVICEFARM_DEVICE_PLATFORM_NAME --app $DEVICEFARM_APP_PATH
--automation-name UiAutomator2 --udid $DEVICEFARM_DEVICE_UDID
--chromedriver-executable $DEVICEFARM_CHROMEDRIVER_EXECUTABLE >> $DEVICEFARM_LOG_DIR/appiumlog.txt 2>&1 &
- >-
start_appium_timeout=0;
while [ true ];
do
if [ $start_appium_timeout -gt 60 ];
then
echo "appium server never started in 60 seconds. Exiting";
exit 1;
fi;
grep -i "Appium REST http interface listener started on 0.0.0.0:4723" $DEVICEFARM_LOG_DIR/appiumlog.txt >> /dev/null 2>&1;
if [ $? -eq 0 ];
then
echo "Appium REST http interface listener started on 0.0.0.0:4723";
break;
else
echo "Waiting for appium server to start. Sleeping for 1 second";
sleep 1;
start_appium_timeout=$((start_appium_timeout+1));
fi;
done;
# The test phase includes commands that run your test suite execution.
test:
commands:
# Go into the root folder containing your source code and node_modules
- echo "Navigate to test source code"
# Change the directory to node_modules folder as it has your test code and the dependency node modules.
- cd $DEVICEFARM_TEST_PACKAGE_PATH/node_modules/*
- echo "Start Appium Node test"
# Enter the command below to start the tests . The comamnd should be similar to what you use to run the tests locally.
# For e.g. assuming you run your tests locally using command "node YOUR_TEST_FILENAME.js.", enter the same command below:
- npm run test:android
# The post test phase includes are commands that are run after your tests are executed.
post_test:
commands:
# The artifacts phase lets you specify the location where your tests logs, device logs will be stored.
# And also let you specify the location of your test logs and artifacts which you want to be collected by Device Farm.
# These logs and artifacts will be available through ListArtifacts API in Device Farm.
artifacts:
# By default, Device Farm will collect your artifacts from following directories
- $DEVICEFARM_LOG_DIR```
AWS Device Farm's standard mode is independent of YAML file. It's a setting that is configured in the "Configure" step when you schedule a run through the console or via CLI through the ScheduleRun API. Currently, AWS Device Farm does not support Appium Node in standard mode, which means that the granular reporting you are seeking is not available.
If you have further questions, you can head over to the AWS Device Farm Forums for additional assistance from their engineering team.
Andy
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