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
Nik Omel
@omelnik
yep, thanks @Uzlopak. It's a good idea.
Uzlopak
@Uzlopak
You even could make it more annoying.
it('my temporary disabled test', function () {
if (Date.now() < new Date('03-01-2022').getTime()) {
this.skip();
return;
}
// do the unit test
}
@omelnik i think doing this, you can set a date in the future and skip the unit test conditionally. So in a month you would get again a failing test, if it is not fixed till then...
Koeun Lee
@korany-lee

how to compare with console contents. I try to using sinon js. But even calledOnce not working.

describe('', () => {
  it('' () => {
    const sandbox = sinon.createSandbox();
    sandbox.spy(console, 'log');
    somethingOutputConsoleLogFuc(param); // console.log is output
    expect(console.log.calledOnce).to.be.true; // AssertionError: expected false to be true
    expect(console.log.callWith(testResultConsoleContent)).to.be.true; // this part is what I really want to do

    spy.restore();
  })
})

I using sinon 13.0.1 and mocha is 9.1.4 version.

ssbarnea
@ssbarnea:matrix.org
[m]
Can anyone provide an answer to the timeout and retries dilemma? https://stackoverflow.com/questions/68485310/mocha-retry-after-timeout
current behavior fails to allow using retries with tests that can fail due to timeouts.
i my case I am not using these from cli, but from specific test spec, still same problem.
ssbarnea
@ssbarnea:matrix.org
[m]
Is there a way to make mocha use colors when run under powershell? Under bash it seems to just work fine.
ssbarnea
@ssbarnea:matrix.org
[m]
kinda sorted, setting colors to true in config sorted it, i guess the tty detection is big fauly, especially as see the same problem on GHA.
Now i am wondering if I can make mocha display a very bried summary after run, mentionin number of tests passing/failing, not i have to scroll and have wild guess.
Tiffany Chong
@sciffany
I am new and would like to contribute to Mocha. I just forked and cloned a copy of main, and ran npm start test. But already, there are two failing tests. Is this expected behaviour? Thanks!
4 replies
Lev Khoroshansky
@TmLev
How can I use async for the contract? Here is an example of what I would like to do:
contract("Contract", async (accounts) => {
  const something = await get();
})
1 reply
Kal Sze
@ksze
Is there a way to wrap a Mocha suite (i.e. a describe()) in a Node.js AsyncLocalStorage.run()?
4 replies
Kal Sze
@ksze
Where can I find the complete list of mocha config options and explanation for each option? It doesn't seem to be in the official documentation.
FedeTommi
@FedeTommi
Hello. I've just read through https://github.com/mochajs/mocha/wiki/compilers-deprecation (which seems a bit out of date by the way), which says to reach out here if these instructions are not working. I am having an issue because the components I am testing are importing png files using the webpack file loader. I found a stackoverflow issue providing a fix for this, but it seems to do many deprecated things (--compilers instead of --require, require.extensions). Implementing the stackoverflow solution exactly, I get --compilers is DEPRECATED and no longer supported.. If I replace --compilers png:./mochacfg.js with --require ./mochacfg.js, I get the same error TS2307: Cannot find module '../../media/xxx.png' or its corresponding type declarations. as before. Reading the documentation, it seems that --require can be used to import a transpiler like babel or typescript, or to load a custom file with hooks. However, I fail to see how I can replace png imports with an empty string for example with a hook. I am using node 16.14.0, mocha 9.1.0, babel/register 7.17.0, typescript 4.1.6, and create react app. 5.0.0. Thanks in advance
1 reply
Bryce Carr
@bdcarr

Hey so I ran a mocha test using IntelliJ's debugger, which automatically sets --timeout 0. Left it paused for several minutes while looking at something, and when I resumed it, it timed out. Does setting this.timeout(xxx) inside the script override the timeout set by --timeout now? I don't recall this behaviour happening before I updated from v7 to v9. Previously if I debugged a test, it would ignore all thethis.timeout() calls in the script

Guessing there's a new flag which does that behaviour, and Jetbrains needs to update their test runner? --no-timeouts maybe?

3 replies
pavan kumar
@pavankumar410:matrix.org
[m]
Need help on the mocha-parallel-tests Scenario : I need option to give ‘preserve-symlinks’ in mocha-parallel-testsTried below things —> mocha-parallel-tests --config=./config.js --preserve-symlinks. —> didn’t help means it is executing the original file not the symlink file.Below is my config.js file process.env.ENV_PATH = './env.xml';process.env.BROWSER = 'CH';process.env.MOCHAWESOME_REPORTDIR = './reports/integ-tests/html';module.exports = { reporter: 'mochawesome', recursive: true, timeout: 400000, grep: '@HRHD_Original@', invert: false, require: 'ts-node/register', sort: true, 'max-parallel':10, 'reporter-options': 'reportDir=./reports/integ-tests/html,reportFilename=index,reportTitle="HelpDeskInteg_Functional_Tests_Report",code=true', spec:[ "./faat/fusionapps/crm/selenium/products/HelpDeskInteg/scripts//*.ts" ]};Note : with mocha serial run —> mocha --grep @HRHD_Original@ scripts//*.ts --recursive --require ts-node/register --reporter mochawesome --reporter-options reportDir=C:\Reports,reportFilename=customReport,reportTitle="My Custom",code=true --timeout=1000000 -b --env="C:\helpdesk\HelpDeskIntegTest\env.xml" --browser="chrome" --preserve-symlinksPreserve symlink option is executing the symlink file instead original file.
1 reply
Daniel Wilkowski
@Danon
@pavankumar410:matrix.org Can you format your pasted code?
Bryan
@bryan.bennett:matrix.org
[m]

:point_up: Edit: Hi all. I'm having trouble integrating mocha with a project that's already making heavy use of parcel 1.12, es-modules, and (probably most importantly) flow.

I have:

  • installed mocha, @babel/preset-flow, and @babel/register.
  • ensured that`@babel/preset-flow` is present in my project's .babelrc's "presets" array.
  • created a basic test in thetest/ subdirectory that simply imports code from another subdirectory (no assertions as of yet).
  • attempted to run this with$(npm bin)/mocha --require @babel/register test/

This fails with an "Unexpected identifier" error, which I believe is due to the runner getting the untransformed code.
I believe this because when i comment out the import itself, it runs to completion (but there's obviously nothing to test without the import). The tests contain no flow annotations as of yet.

What else might I check here?

1 reply
Bryan
@bryan.bennett:matrix.org
[m]
@juergba: I must assume that was in response to me and it does look as if it could be related. Thanks for the heads up. I'll check it out.
kot99a
@kot99a

Hi all. Could someone tell me please how I can correctly return and pass something from the "it" block to the afterhook? For example:

it('test', async function () {
const x = await ...
});

3 replies
after('after', async function () {
const deleteSMTH = await delete(x);
});
Tal
@t1a2l
Hello, is there a discord server, or this is the discord?
my tests are broken down into test functions (it) if one "it" didn't finish after a certain time it jumps to the next "it"
atul_kr
@atul_kr:matrix.org
[m]
I am facing issue with mocha while running npm test for node Using node 14
can anyone pls help me with this ?
1 reply
Naor Tedgi (Abu Emma)
@ntedgi
hi can someone please provide me some details about the mocha debug output I am facing very slow startup time on my ci
and after adding DEBUG=mocha:* I saw this line
mocha:cli:run:helpers single run with 70 file(s) +327ms
mocha:mocha set lazy load to true +312ms
[2022-03-31 07:16:13.314911] using filename cache <-- first line of application code
mocha:suite timeout 2000 +32s
I am trying to figure out whats taking this 32 secs?
Shailesh Rasane
@rasane
Hi does anyone have a good tdd setup for Mocha with Typescript to run tests on command line (headless for builds) + browser both? I am looking for a working sample project with those..
Shailesh Rasane
@rasane

Here is my problem; I pushed a setup to github: https://github.com/rasane/html5-dev-setup/blob/master/package.json#L8. in the commands, yarn run testw runs on the console and tests are successful. but when I run those tests in the browser using yarn run testb, I get the following error:

Uncaught TypeError: mocha_1.default.describe is not a function

look at the weird things I had to do here: https://github.com/rasane/html5-dev-setup/blob/master/test/index.spec.ts#L2 to make the tests run in console and browser. I wish that was not necessary.. so if someone has a better setup or can help me fix this setup , I will be greatful

Shailesh Rasane
@rasane
duh.. sorry to disturb everyone, after asking I figured out my setup issue.. thanks .. I am still keen to see if someone has any other setup you use, would love to improve the current setup..
Jeff Tully
@jefftully_gitlab

I am trying to test for the database will not let me enter a duplicate
I expect it to throw error: duplicate key value violates unique constraint "team_per_tbl_pkey"

this indicates a PASS on the test. how do i trap it and assert against it?

  it("will not let a person to be added to the same team twice", async () => {
    try {
      await startTrans(connection);
      await setTestRoles(connection, per_oauth_sub);

      let teamPerData = await connection.query(
        sql.createSql,
        sqlData.createValues
      );

      await endTrans(connection);
    } catch (err) {
      console.log(err.stack);
      await rollBackTrans(connection);
    }
    {
      throw Error;
    }
  });
6 replies
Kyle Merfeld
@kmerfeld
Is there a guide for setting up mocha with flow?
Yadong Zhang
@zhyd1997

Hi, team

new to mocha, is there a way to generate test coverage report with .mjs test files?

Yadong Zhang
@zhyd1997
Alright , I found it: https://github.com/bcoe/c8
an-dutra
@an-dutra
Hello guys, I need to test a method that extracts data from Hbase, It's possible to simulate a scan or get in hbase with mocha? Because my Jenkins can't access the hbase server.
Andrej Leitner
@andrejleitner
Hey folks, what's the best practice of running mocha + ts-node together with some-test-helper.ts files that doesn't contain describe/it statements? It seems to me their are not picked up (Cannot find module: ...).
4 replies
Daniel Bretoi
@danielb2
I can't seem to get code coverage to work with mocha-sidebar. That project seems dead too, and the gitter has been quite since january. I was wondering if I can get help. all it says is that it's enabled, but it doesn't say percentage, and I'm not seeing decorations for uncovered code. Anyone know?
Daniel Bretoi
@danielb2
Sorin Sbarnea
@ssbarnea
I want to fail the test suite if total number of test run is different than a value I expect. How can I do that? From what I seen afterAll() does not receive the results, so it is useless for this purpose.
nkm5133
@mohming

Hello everyone, I am new to mocha. Is there a way to run a dynamic loop? I am trying to do something like the below (no need to be exact)

var testCaseList = [];
describe('dynamic loop', function () {
    it('Obtain test case lists', function (done) {
        getTestCase()
            .then((testcases) => {
                testCaseList = testcases; // this would be JSON array
                done();
            }).catch((error) => { done(error) });
    });
      // run loop that grabs from above method (getTestCase()).
        testCaseList.forEach(({ test_case, version}) => {
            it(`start test for ${test_case}`, function (done) {
                     expect(test_case}.equal(something);
                    }).catch((error) => { done(error) });
            });
});

Basically, I am trying to run the loop test based on the list of test case from server, it is possible for mocha? Or it must be static? I tried to run before() and successfully retrieve the list of test cases but it couldn't run for the forEach.

3 replies
PIPNicolas
@PIPNicolas
Good morning, someone help me configure mocha in my project please
Nicolas Alexis Gonzalez Pedraza
@nicolasgh:matrix.org
[m]
Good morning, someone help me configure mocha in my project please
Ben Marten
@benmarten
Hi, I'm having trouble getting the debugger to break in mocha, i'm using it like this: mocha --inspect-brk dist/test/table.spec.js
but it simply doesn't stop and wait for the debugger, as it would do in a regular node process...
when I run: node --inspect-brk ./node_modules/.bin/mocha dist/test/table.spec.js it does stop and i can attach the debugger, but it does not stop in the mocha test file either...
any ideas?
4 replies
Juha-Jarmo Heinonen
@jammi
Hi, does anyone have suggestions of what output to use for github check_runs / check_suites?
Also, since node 8.2, or by coincidence, there now seems to be some "timing" progress stuff when running mocha via npm test (which just runs mocha test/*-spec.js)
Mubashir hussain
@mubashirhussainkhadim
Error: Timeout of 100000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
ClintonWeeYuan
@ClintonWeeYuan
Hi! I'm trying to create a React page, that can programatically run mocha tests (when I click a button). Does anyone have any idea on how I can do this?