gulp-npm-test running Jest tests (all passing), but claiming to fail - npm

I've installed gulp-npm-test following their documentation, that is, in my gulp directory I've got a file test.js that looks like this:
var gulp = require('gulp')
require('gulp-npm-test')(gulp)
var gulp = require('gulp-npm-test')(gulp, {
withoutNpmRun: false
})
But when I run gulp test I get the output like the following:
[17:12:41] Using gulpfile ~/my-project/gulpfile.js
[17:12:41] Starting 'test'...
> my-project#0.0.1 test /Users/wogsland/my-project
> jest
PASS frontend/tests/components/atoms/InputText.test.js
.
.
(many more Jest test passes, no fails)
.
.
FAIL gulp/tasks/test.js
● Test suite failed to run
Your test suite must contain at least one test.
at onResult (node_modules/jest/node_modules/jest-cli/build/TestRunner.js:192:18)
Test Suites: 1 failed, 135 passed, 136 total
Tests: 135 passed, 135 total
Snapshots: 209 passed, 209 total
Time: 92.237s
Ran all test suites.
npm ERR! Test failed. See above for more details.
What am I missing here? I've go a bunch of tests

Looks like the matcher that figures out which files are tests, matches everything that includes in the filename test.js. The default is [ '**/__tests__/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)' ]. So either adapt this one, its testMatch in your jest settings. Or use testPathIgnorePatterns to exclude the /gulp folder.

Related

Cypress E2E Testing VueJS with GitLab Runner returns 404 not found

I have the following simple GitLab CI file
stages:
- e2e_test
e2e_test:
stage: e2e_test
tags:
- test
script:
- npm config set strict-ssl false
- npm install
- npm run test:e2e:ci
I am running the above script in a shell runner for very specific corporate reasons.
This script results in a 404 error with the following log
npm run test:e2e:ci
> todo-app#0.1.0 test:e2e:ci /home/gitlab-runner/builds/UHz6XzwM/0/microservices-and-cognitive-solutions/demos/microservice-concept/todo-app
> vue-cli-service test:e2e --headless
INFO Starting e2e tests...
INFO Starting development server...
DONE Compiled successfully in 8865ms6:51:36 PM
App running at:
- Local: http://localhost:8083/
- Network: http://10.108.201.150:8083/
App is served in production mode.
Note this is for preview or E2E testing only.
====================================================================================================
(Run Starting)
tput: No value for $TERM and no -T specified
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 3.8.3 │
│ Browser: Electron 78 (headless) │
│ Specs: 1 found (test.js) │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: test.js (1 of 1)
Browserslist: caniuse-lite is outdated. Please run the following command: `npm update`
My First Test
1) Visits the app root url
0 passing (341ms)
1 failing
1) My First Test Visits the app root url:
CypressError: cy.visit() failed trying to load:
http://localhost:8083/
The response we received from your web server was:
> 404: Not Found
This was considered a failure because the status code was not '2xx'.
If you do not want status codes to cause failures pass the option: 'failOnStatusCode: false'
at Object.cypressErr (http://localhost:8083/__cypress/runner/cypress_runner.js:86207:11)
at Object.throwErr (http://localhost:8083/__cypress/runner/cypress_runner.js:86162:18)
at Object.throwErrByPath (http://localhost:8083/__cypress/runner/cypress_runner.js:86194:17)
at http://localhost:8083/__cypress/runner/cypress_runner.js:71493:31
at visitFailedByErr (http://localhost:8083/__cypress/runner/cypress_runner.js:71006:12)
at http://localhost:8083/__cypress/runner/cypress_runner.js:71474:22
at tryCatcher (http://localhost:8083/__cypress/runner/cypress_runner.js:120203:23)
at Promise._settlePromiseFromHandler (http://localhost:8083/__cypress/runner/cypress_runner.js:118139:31)
at Promise._settlePromise (http://localhost:8083/__cypress/runner/cypress_runner.js:118196:18)
at Promise._settlePromise0 (http://localhost:8083/__cypress/runner/cypress_runner.js:118241:10)
at Promise._settlePromises (http://localhost:8083/__cypress/runner/cypress_runner.js:118316:18)
at Async../node_modules/bluebird/js/release/async.js.Async._drainQueue (http://localhost:8083/__cypress/runner/cypress_runner.js:114928:16)
at Async../node_modules/bluebird/js/release/async.js.Async._drainQueues (http://localhost:8083/__cypress/runner/cypress_runner.js:114938:10)
at Async.drainQueues (http://localhost:8083/__cypress/runner/cypress_runner.js:114812:14)
If I clone the same repository on the same server and manually run the following commands in the terminal it works fine.
npm install
npm run test:e2e:ci
Any idea why the same commands would fail in a GitLab runner shell but working in a user shell
I found the problem to fix my issue. I needed to set a no_proxy environment entry in my gitlab-runner config.toml file. This won't affect everyone, but since i am behind a corporate proxy, I needed it.
export no_proxy="localhost"

getting test failed on typing command npm test

I am getting an error which in turns return test failed. Not able to find out the solution to it. Have checked but did not found an appropriate answer for it
I have tried following things:
1. Check babel version :using 7.5.5
2. https://github.com/GeekyAnts/NativeBase/issues/977
3. https://gist.github.com/iamvery/4d4b0ef68cd1f2de81b858fe3a2d08c5
4. https://github.com/GeekyAnts/NativeBase/issues/2579
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import connectStyle, { clearThemeCache } from "./src/connectStyle";
SyntaxError: Unexpected identifier
at ScriptTransformer._transformAndBuildScript (../../node_modules/#jest/transform/build/ScriptTransformer.js:471:17)
at ScriptTransformer.transform (../../node_modules/#jest/transform/build/ScriptTransformer.js:513:25)
at Object.<anonymous> (../../node_modules/native-base/src/index.js:1:1)
Test Suites: 1 failed, 1 passed, 2 total
Tests: 4 passed, 4 total
Snapshots: 1 passed, 1 total
Time: 2.022s
Ran all test suites.
npm ERR! Test failed. See above for more details.
Actual result is test failed as have shown above
Expected result is test should pass
you can add this to your jest config file
"transformIgnorePatterns": [ "node_modules/(?!react-native|#shoutem|react-clone-referenced-element|native-base-shoutem-theme)" ]

How to customize botium mocha timeout

I am trying to connect to directline using the following setup:
botium_directline.json:
{
"botium": {
"Capabilities": {
"PROJECTNAME": "botium-sample1",
"CONTAINERMODE": "directline3",
"DIRECTLINE3_SECRET": "<BOTIUM_SECRET>",
"DIRECTLINE3_WEBSOCKET": true
},
"Sources": {},
"Envs": {
"NODE_TLS_REJECT_UNAUTHORIZED": 0
}
}
}
Folder structure:
If I run:
botium-cli emulator browser --convos ./spec/convos --config ./botium_directline.json
I am able to "communicate with the bot" within the new conversation.
If I wanna run the tests I prepared I get the following timeouts:
botium-cli run --convos ./spec/convos/ --config ./botium_directline.json
user # /Users/username/workspace/testing/botium
~~ npm test
> botium#1.0.0 test /Users/username/workspace/testing/botium
> botium-cli run --convos ./spec/convos/ --config ./botium_directline.json
Botium Test-Suite
1) Test One
2) Test Two
0 passing (4s)
2 failing
1) Botium Test-Suite
Test One:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
2) Botium Test-Suite
Test Two:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
The error is similar to a standard mocha timeout error, but I do not know where to put a .js file to increase the timeout in a beforeEach.
I attempted to add both BOTIUM_TIMEOUT or a TIMEOUT properties into the botium_directline.json but this did not do anything.
Any ideas how to increase the timeout?
Botium automated tests have default timeout of 60000 milliseconds, but you can customize it by passing the --timeout flag at the end of your CLI command.
To do that, just add the flag --timeout followed by the time in milliseconds you'd like to set it up for. For instance, for 100000 milliseconds, your command should be like this: botium-cli emulator browser --convos ./spec/convos --config ./botium_directline.json --timeout 100000
The "BOTIUM_TIMEOUT" environment variable is the correct choice, or you can use the "--timeout" command line switch for botium-cli. This is only available since some days, there was a bug involved which has been fixed. Please get the build 0.0.34 of the botium-cli:
npm install botium-cli#0.0.34

How to force cmake to write test output after make test

I'm building fortran project with cmake and I can't find solution to print to console FRUIT test results, they look something like these:
Test module initialized
. : successful assert, F : failed assert
7.00000000000000 -3.60000000000000 7.00000000000000
FFF
Start of FRUIT summary:
Some tests failed!
-- Failed assertion messages:
[_not_set_]:Expected [7.00000000000000], Got [1.00000000000000]
[_not_set_]:Expected [-3.60000000000000], Got [2.00000000000000]
[_not_set_]:Expected [7.00000000000000], Got [6.00000000000000]
-- end of failed assertion messages.
Total asserts : 3
Successful : 0
Failed : 3
Successful rate: 0.00%
Successful asserts / total asserts : [ 0 / 3 ]
Successful cases / total cases : [ 0 / 0 ]
-- end of FRUIT summary
The output I'm getting with make test looks like:
make test
Running tests...
Test project /home/konrad/Desktop/fortran
Start 1: unit_tests
1/1 Test #1: unit_tests ....................... Passed 0.01 sec
100% tests passed, 0 tests failed out of 1
Total Test time (real) = 0.01 sec
And since passing cmake tests doesn't mean passing FRUIT ones, I want to print FRUIT file everytime I run tests (just for the sake of making it work). I've tried adding printing commands at the end of test command (like this less), adding
-P ${CMAKE_TEST_DIR}/unit_tests.txt
at the end of add_test, building custom after build commands (which I can't make to run after make test so if you knew how to do that would solve it as well, seems like make test or test is not really a target)
Last part of my cmake file with all the testing code:
add_executable(task ${TASK_SOURCES})
add_executable(tests ${TEST_SOURCES})
enable_testing()
set(run_command "${CMAKE_BINARY_DIR}/tests")
set(UNIT_TEST_NAME "unit_tests.txt")
file(MAKE_DIRECTORY ${CMAKE_TEST_DIR})
add_test( NAME unit_tests
COMMAND sh -c
"rm -f ${CMAKE_TEST_DIR}/${UNIT_TEST_NAME} \
&& ${run_command} \
>> ${CMAKE_TEST_DIR}/${UNIT_TEST_NAME} \
&& less ${CMAKE_TEST_DIR}/${UNIT_TEST_NAME}"
)
I have solved a lack of tests output with custom CMake target that will invoke ctest in verbose mode etc.
e.g.
enable_testing()
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
--force-new-ctest-process
--verbose
--output-on-failure
)
The output of cmake tests is captured to a file (Testing/Temporary/LastTest.log in my current project).
cmake tests rely on the return code of the test program, with one test program per test.
If you wish to run a program that is a "driver" for your tests, I recommend to use add_custom_target. This commands will add a target that runs a command of your choice.
For instance:
add_custom_target(Name unit_tests tests)
add_dependencies(unit_tests tests)
I am not sure whether the add_dependencies line is needed in this case though (as tests is a target managed by cmake).
Then, you can run
make unit_tests
and it will run your test driver.

Getting ReferenceError: fetch is not defined when running react native tests in mocha

When running react-native tests in mocha, I'm getting the following error:
> mocha --require test/init.js --compilers js:test/compiler.js 'src/**/*.spec.js'
Initializing tap mocha reporter...
1..7
ok 1 test1
…
not ok 7 test7
ReferenceError: fetch is not defined
at foo (src/foo.js:59:8)
at Context.<anonymous> (src/__specs__/foo.spec.js:9:30)
# tests 7
# pass 6
# fail 1
npm ERR! Test failed. See above for more details.
The problem was that fetch isn't available in a node environment like mocha. I'm not sure why react-native-mock (which I'm also using) doesn't have a mock for it, but the solution was to require isomorphic-fetch when initializing my mocha tests.
Specifically, add an init file to your mocha command-line if you don't have one already:
> mocha --require init.js …
and in init.js, require isomorphic-fetch:
require('isomorphic-fetch')
Then re-run mocha:
> mocha --require test/init.js --compilers js:test/compiler.js 'src/**/*.spec.js' && standard
Initializing tap mocha reporter...
1..7
ok 1 test1
…
ok 7 test7
# tests 7
# pass 7
# fail 0