Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 24 2020 17:07
    nicojs synchronize #4234
  • Apr 24 2020 16:55
    juergba unlabeled #4251
  • Apr 24 2020 15:47
    Daniel0113 edited #4219
  • Apr 24 2020 15:45
    Daniel0113 edited #4219
  • Apr 24 2020 15:11
    Daniel0113 synchronize #4219
  • Apr 24 2020 14:01
    juergba labeled #4227
  • Apr 24 2020 14:01
    juergba unlabeled #4227
  • Apr 24 2020 14:01
    juergba unlabeled #4227
  • Apr 24 2020 13:58
    juergba edited #4251
  • Apr 24 2020 13:33
    juergba labeled #4251
  • Apr 24 2020 12:52
    juergba milestoned #4251
  • Apr 24 2020 12:52
    juergba labeled #4251
  • Apr 24 2020 12:52
    juergba labeled #4251
  • Apr 24 2020 12:52
    juergba labeled #4251
  • Apr 24 2020 12:51
    juergba assigned #4251
  • Apr 24 2020 12:51
    juergba review_requested #4251
  • Apr 24 2020 12:51
    juergba opened #4251
  • Apr 24 2020 12:37

    juergba on karma

    type check before calling retriโ€ฆ (compare)

  • Apr 24 2020 06:26
    juergba labeled #4250
  • Apr 24 2020 06:26
    juergba labeled #4250
Juerg B.
@juergba
@iapazmino we have a react setup sample in our sample repo. Maybe that helps.
falconwoods
@falconwoods
Hi there, can anyone tell me how to output log in mocha, like console.log
it really drives me crazy :(
ashkank83
@ashkank83

Hi All, Basic question!
I need to develop end2end testing for a series of softwares that we have developed in house and I wonder if Mocha is the right tool for it?
A typical test scenario in our case consists of following steps (which is done manually at the moment)

  1. Invoke a Soap API to create an object (Soap call)
  2. Check MS SQL to make sure records are created (MS SQL statement)
  3. Wait for an in house developed software to move the record to Oracle DB and verify
  4. Verify Oracle DB to make sure synchroniser passes the test (Oracle statement)
  5. Invoke XML over http API and verify the result (invoke API and check XML)

Ideally I want to be able to let testers to write these test scenarios and add to the list of tests to be performed with every new version released. Would you recommend Mocha?

Andrey Nalivaiko
@Andrei1982
Hi. How to specify target directory in mocharc.js file for allure results?
reporterOption: {
targetDir: "./testing/allure/allure-results",
} - doesn't work
mocha v.8
Anyone can help me?
Juerg B.
@juergba
@Andrei1982 reporterOption is an array => see .mocharc.js
Andrey Nalivaiko
@Andrei1982
@juergba reporterOption: ["targetDir=./testing/allure/allure-results"] - doesn't work too
Andrey Nalivaiko
@Andrei1982
Anyone else can help? No one doesn't use a custom directory for allure result reports?
Russell Anthony
@russell-dot-js
๐Ÿ‘‹
I'm trying to resolve some flakey integration tests I'm not particular proud of. The problem is that a lot of our assertions require waiting for side effects (up to a threshold), but when running large #'s of tests in parallel, that data pipeline can take a little bit longer than we expect. So this can resolve in 1/1000 tests failing due to a condition not being met in a beforeEach hook. I'd like to quickly hack to stop the bleeding and prevent all the lost time of a single test "failing" despite increasing timeout (it only needs to go up and up as the number of tests and amount of data goes up, resulting in tests that could be fast becoming slow to accomodate the one that will fail). What's the best way to monkeypatch beforeEach so that it follows mocha's retry logic? I'm not talking about adding a custom beforeEach, because I don't want to impact developer QOL or have to enforce "you must use this special beforeEach!" when in reality all tests work perfectly on their own and to the individual developer, it's only when running large numbers of tests in parallel (CI) that we see issues
Miguel Ike A. Dumancas
@ikedumancas
Hello. Why is it that ctx is missing when running parallel?
Eric Scaglioni Ferreira
@ericscaglioni
Hi guys.
Is there a way to 'pass with no tests' like Jest does?
I mean, I'm setting up a new app with mocha and I added a testing validation on pre-push hook. The problem is that at this moment I still have no tests. I'm on the beginning, just want to let the project ready for when it starts. Any thoughts?
Boone Ferry
@ChandlerFerry
How do I convert CLI ran mocha into new Mocha()? There are no "require" or "extension" options for TypeScript.
Ghost
@ghost~608ee9066da03739847b92c1
Hello! I trying to run mocha tests written in Typescript but --require ts-node/register does not help - obscure error happens at absurd line
Anybody here?
The Grand Poobah
@TheGrandPB

Hello~ could someone guide me on how to properly unit test console output? My tests are being written in Mocha Chai on Node.js. For example:

const signers = await hre.ethers.getSigners();

console.log("Current signer:" + JSON.stringify(signers.toString()));

doesn't seem to spit anything out; i've also tried console.log("Current signer:" + JSON.stringify(signers[0].toString())); and nothing

Smart QA Lead
@chan90git
Hi, Im new to Mocha and im trying to implement global hooks and call it via this command in shell -> "PARAM1=value1 PARAM2=value2 yarn run parallel --require tests/hooks.js tests/sometest.js --reporter mochawesome". But the hooks methods are not invoked. In package.json, this is the value "parallel": "mocha-parallel-tests"... in my case I need to use only parallel.So pls help me out here, im struck.
Juerg B.
@juergba
@chan90git mocha and mocha-parallel-tests are two distinct packages. global hook is a Mocha feature, but you are running mocha-parallel-tests.
Smart QA Lead
@chan90git
Thanks for your reply. so no global hooks for 'mocha-parallel-tests'?
chanchow88
@chanchow88
hi, I am having problem with mocha latest version for accessing global variables inside forEach loop. Could some one plz help https://stackoverflow.com/questions/67527885/unable-to-access-global-variables-inside-foreach-on-mocha-framework-v8-4-0
Juerg B.
@juergba
@chanchow88 there are various synthax errors in your file. Missig paranthesis, this dot in your first line, where does login.loginUser function come from?
chanchow88
@chanchow88
@juergba loginUser is a method being called. I just added for example to make a point that I am trying to use that variable on that method.
Juerg B.
@juergba
@chanchow88 Your example is weird.
global.testuser1 = testuser1: is testuser1 a variable?
otherwise, if string put double quotes: global.testuser1 = "testuser1"
1 reply
petrhribal
@petrhribal:matrix.org
[m]

Hi guys. I'm currently struggling with mocha configuration in our gitlab-ci file. We have one general build pipeline that is used for all our javascript projects. Some of them might, some of them might not have .spec.js tests in it.
The problem I'm currently facing is, that for projects with no .spec.js files (no tests) the build pipeline fails all the time with

Error: No test files found: "dist/src/test/ts/**/*.spec.js"

I tried to find any configuration parameter in the docu (https://mochajs.org/#configuring-mocha-nodejs). But seems, there is no way, how to tell mocha, that if there are no "tests" - then it should return exit 0.
Does anyone have an idea, how to deal with it?
Attaching also my .mocharc.json file

{
        "diff": true,
    "check-leaks": true,
    "exit": true,
    "recursive": true,
    "require": [
        "source-map-support/register"
    ],
    "reporter": "xunit",
    "reporter-option": "output=/project_working_dir/report.xml",
    "spec": "dist/src/test/ts/**/*.spec.js",
    "sort": true,
    "ui": "bdd"
}

Any hints appreciated.

Juerg B.
@juergba
@petrhribal:matrix.org you could check with lookupFiles wether tests exists. You could also switch to .mocharc.js, check with lookupFiles and then exit with code 0.
1 reply
meet
@meetmangukiya:matrix.org
[m]
Is it possible to set test / mocha context from root hook plugins? Also, if you want to store the server from the global fixture to test context is it possible with some hacky way? docs say its not possible to set test context from global fixtures
Bryce Carr
@bdcarr

hello hello

Do you think async callbacks will be supported in ESM test files at some point? Having to move all async calls to the top of the script, instead of just the ones required to generate dynamic test cases, limits the usefulness for my team.

Sorry I'm sure this has been asked before, I didn't have much luck searching the Issues
Juerg B.
@juergba
@bdcarr No, there are no plans to make describe async, neither in ESM nor in CommonJS test files.
You can declare async before/beforeAll hooks for your async task within your suites though.
Bryce Carr
@bdcarr
Oh! So async calls inside before() still works? I didn't try myself but I thought my teammate had trouble with it
I'll give it a whirl, thanks
Bryce Carr
@bdcarr
Oh it totally works, nice! Can do async it() callbacks too, even
Thanks mate!
Klaxon
@passle__twitter

Hey gang, running into something weird. Im writing node ESM, so I've got "type": "module" in my package.json, and I'm using .mjs as my file extensions. When I run my test with mocha test/*.test.mjs, my test runs successfully and passes. When I run the same command but with the --watch flag, I get the following error:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/au87xu/cem/test/integration.test.mjs

Anybody have any idea what I could be doing wrong? ๐Ÿค”

Juerg B.
@juergba
@passle__twitter Mocha's watch mode does not support ESM test files => docs
Klaxon
@passle__twitter
Ah. Right, well that would explain it ๐Ÿ˜„ Thanks!
Miguel Marques
@munerf
hey guys, I'm having a strange behavior here and I don't even know where the issue is... I have two tests, AComponent.spec.tsx and AViewComponent.spec.tsx. The tests that I have in AViewComponent all pass if I run only these tests. But I run all tests ( from both files ) it fails. It seems that some kind of garbage is left behind, any clues on this?
Darin Hensley
@dman777
Hello.... how can I keep the browser from closing after a test has ran or breaks?
I mean from command line
Rajmond Xhaferi
@rajmondx
How does mocha actually find its tests, does it just list "*.js" files and require them (as they get listed by fs)?
Juerg B.
@juergba
@rajmondx per default Mocha searches for files in "./test/*.{js,cjs,mjs}".
It loads them depending on wether its CJS or ESM file.
Osman Zakir
@DragonOsman

Where in the documentation is there info on how to write a unit test for specific functions? I currently have this:

const chai = require("chai");
let assert = chai.assert;
const ConvertHandler = require("../controllers/convertHandler.js");

let convertHandler = new ConvertHandler();

suite("Unit Tests", () => {

});

and need to write tests inside the suite function for each method on the convertHandler object.

Ray Foss
@FossPrime_gitlab
P.S. Why is gitter not a proper PWA.
dkuznetsov21m
@dkuznetsov21m

Hi all !

in my root hooks, beforeAll tests, a request is made to the TestRail with unloading all test cases, how can I make the tests start only after receiving a response from the test rail in my root hooks ?

Andrei Arlou
@Captain1653

Hi Community! I have some question about mocha root hook. How can I prepare some data (for example Page from Playwright) and use the page in my each test?

beforeEach: async () => {
       page = await context.newPage(); // 
}
afterEach: async () => {
      await page.close();
}

I don't want to duplicate my code. Are there any possibilities?

Juerg B.
@juergba
@Captain1653 beforeEach and afterEach hooks share the same this. So using this.page should work.
2 replies
Love Mayrhofer
@love-expressen

Hey! I've got a question about the --ui option in parallel mode. After quite a bit of reading I'm still not 100% sure if the current (9.0) behaviour is by design:

It seems like mocha will silently ignore any third party UI being set when running tests files using the worker pool. This is caused by ignoring serialization of function references here https://github.com/mochajs/mocha/blob/b20f3c953d21540ed6846feb060638f36cb48cac/lib/nodejs/buffered-worker-pool.js#L146

I'd be happy to submit a proper issue and PR, but if the current behaviour is by design, that seems like a waste of time :)

2 replies