Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 16:16

    Munter on transpilation

    Polyfill global to check if IE1… (compare)

  • 13:41

    Munter on transpilation

    Replace browserify with rollup … (compare)

  • Mar 29 21:45
    boneskull synchronize #4198
  • Mar 29 21:45

    boneskull on issue

    fix stack prop access on custom… add --parallel test for ESM (compare)

  • Mar 29 21:30
    boneskull synchronize #4198
  • Mar 29 21:30

    boneskull on issue

    fix some flaky tests when run i… integration test helper: add `c… tweak a couple debug statements and 3 more (compare)

  • Mar 29 14:31

    Munter on transpilation

    Extract lookupFiles from utils … (compare)

  • Mar 29 11:14

    Munter on transpilation

    Remove unnessessary browserify … (compare)

  • Mar 29 10:51

    Munter on transpilation

    Make browser specific TTY inter… (compare)

  • Mar 28 05:01
    New Donation: Gavin Mogan gave USD 2 to MochaJS! [Thank that person on Twitter]
  • Mar 27 21:06
    boneskull synchronize #4198
  • Mar 27 21:06

    boneskull on issue

    increase default test timeout t… (compare)

  • Mar 27 00:31
    boneskull synchronize #4198
  • Mar 27 00:31

    boneskull on issue

    add some assertions for RawRunR… add assertion to check exit cod… add a debug stmt to Buffered re… and 5 more (compare)

  • Mar 26 21:46
    boneskull edited #4198
  • Mar 26 21:45
    boneskull synchronize #4198
  • Mar 26 21:45

    boneskull on issue

    WIP: concurrency based on worke… somewhat reasonable re-implemen… revert refactor of setting test… and 14 more (compare)

  • Mar 26 21:44
    boneskull synchronize #4198
  • Mar 26 21:44

    boneskull on issue

    remove useless calls to rewirem… ignoring some missed coverage add unit-ish tests for worker … (compare)

  • Mar 26 00:38
    boneskull synchronize #4198
Lukas Wilkeer
@lukaswilkeer

Hi guys, I'm running through a error on running my test suite.
It said:

Duplicate parameter name not allowed in this context
npm ERR! Test failed. See above for more details.

On npm err, none info. I googgled for some responses but achieves nothing. What could be happen?

Lukas Wilkeer
@lukaswilkeer
Solved. It's a duplicated variable name on a function call.
deepa02
@deepa02
Hi am trying to add mocha retries in our wdio tests. using wdio4 due to some dependency.
below is the sample test :
describe('retries exmple',function() {
this.retries(2);
it (test1, () =>{
});
it (test2, () =>{
});
});
if test1 fails, it only retries test1. I want the complete test suite to run rather.
can somebody suggest if this can be achieved ?
Juerg B.
@juergba
@deepa02 this.retries() re-runs only failing tests (and its corresponding beforeEach/afterEach hooks) . Mocha does not have a feature to re-run entire suite's.
deepa02
@deepa02
Thanks @juergba for clarifying
Simon G.
@SimonGrn

Hello guys, i'm trying to wrap my head around something happening in my test campaign. We use .skip() in some describe() to skip some tests which appear as pending in the final JSON report by mochawesome. No problem here.
Recently, we started seeing some tests marked as skipped in the report, randomly. One full describe() was skipped 2 weeks ago during the nightly run, no modification added, it worked the day before, it worked the day after. We thought it was just a hiccup but it started again yesterday, another test showed up as skipped and I can't for the life of me find why it is skipped and how this works. Everything about "skipped" tests in the documentation refers to using skip() or alone() or stuff like that, stuff you control or add yourself in your code, not Mocha deciding it doesn't want to run a test. Tests we marked as skip ourselves still appear as pending.
Can somebody help me on this one, please ?

Thanks in advance

Simon G.
@SimonGrn
(only(), not alone() obviously, my bad)
Juerg B.
@juergba
@SimonGrn Mochawesome is a third party reporter, not Mocha core. Mocha does not label tests as skipped, so this parts originates from Mochawesome. Maybe re-running failed tests by this.retries()?
But with your fuzzy information it's difficult to give you any further support.
Simon G.
@SimonGrn
ok, thanks for the feedback, we'll try to understand on our side
Meem0
@Meem0
Hi, I'm trying to use mocha from node, and my project uses AngularJS, which to my understanding needs to be included with a <script> tag. Is it possible to have mocha use an index.html (like https://mochajs.org/#running-mocha-in-the-browser ) while I'm calling it from node? Or are they two different paradigms?
Liang
@liangway
Hello Mocha pros, it seems we cannot send http request on exit event, as exit is an sync operation? could someone suggests is there a method that can send http request to other system when mocha test is done?
Peter Müller
@Munter
@Meem0 egen tuning browser code in node, people usually mock a browser on the node environment and require their frontend code through the normal means in node. I bet angular has a bunch of examples of this in their test setup
Yuri Gor
@YuriGor
Hi all! How to run mocha with node profiling enabled?
I try this:
./node_modules/.bin/mocha --prof
but see no profiling output..
swinSpo
@swinSpo
hi, i have a very simple test
describe('#catalogSearch(subjects)', function () {
    this.timeout(30000);

    before(async () => {
      try{
        cache.catalog = await banner.catalogSearch(term, 'CIS');
      }catch (e) {
        console.error("error in before", e)
      }
    });

    it('Should throw an error when a term and subject are not passed', function () {
      assert.rejects(async () => await banner.catalogSearch(""), Error, 'Must provide term and subject');
    });
  });
    async catalogSearch(term, subject, offset=0, pageSize=-1){
        console.error("being called", term, subject)
        console.error("logging args", arguments, arguments.length)
        if (arguments.length < 2){
            console.error("throwing error")
            throw new Error('Must provide term and subject');
        }
}
it doesnt seem to call my catalogSearch twice
being called 202003 CIS
logging args [Arguments] { '0': 202003, '1': 'CIS' } 2
      5) "before all" hook for "catalogSearch Should throw an error when a term and subject are not passed"
I am getting this error
but here is the weird part, if i comment out the before code, i get this output (as expected)
being called  undefined
logging args [Arguments] { '0': '' } 1
throwing error
      √ Should throw an error when a term and subject are not passed
Juerg B.
@juergba
@swinSpo when a before/beforeEach hook fails, its corresponding tests are not executed. Hooks are meant for setting up and tearing down the test environment.
swinSpo
@swinSpo
@juergba are you saying that the before code fails`?
because there is no error it doesnt look like its failing
Daulet Amirkhanov
@daukadolt
Hi everyone! I've got a quick question. Mocha seems to ignore my .mocharc.js config file. Has anyone come across the same problem?
I've already asked the question on stackoverflow, so the details are there https://stackoverflow.com/questions/60855347/mocha-ignores-existing-mocharc-js-config-file
Juerg B.
@juergba
@daukadolt No, we don't have reports about this topic.
But: you have to use the watch option with watch-files. And please use watch-files (not watchFiles), we have problems with parsing camel-cased options in config files.
LightWrath
@lightwrath
Hello, hoping I can quickly ask. If I have a test case within an it(). If there a way in which I can return a var to the text string of the it statement?
Peter Müller
@Munter
@lightwrath You can dynamically create tests. But you'll have to use a delayed root suite
Actually you only need the delayed root suite if the data you need to create the test cases is asyncnronous
LightWrath
@lightwrath
Thank you, in terms of dynamically generated tests - will this also work with having a function call it's self to create a loop with the it() statement inside the function?
Peter Müller
@Munter
Yes
Think of the it function as a call to queue a test. The runner hasn't started running tests yet, and until it does you can queue up new suites and tests
Daulet Amirkhanov
@daukadolt
@juergba still not working(
is there any example project out there that I could look at?
would be a lifesaver
Juerg B.
@juergba
@daukadolt I just tested with Mocha v7.1.1 and watch option in .mocharc.js (project root). It works correctly. What does not work? Try using --config option otherwise.
Lina Larionova
@Ravekeeper
Hi there, I have a question about the programmatic use of mocha. I have a sample project that has two test files, one of them uses axiom to get data inside the test, the other one - to generate data-driven tests on the fly. Exploring my options I've noticed the difference between mocha.loadFiles() and mocha.run() - being, the file that is generating tests on the fly is not being picked up by mocha.suite. But when I use mocha.run() - both specs are being executed. My question here - is there a way for me to get a list of all the file names within both specs? Example: https://github.com/Ravekeeper/mocha-run-data-driven-tests-programmatically
Juerg B.
@juergba
@Ravekeeper I haven't studied your repo in detail. Just two hints:
describe() does not support async callbacks, only it() and hooks do that.
loadFiles() is a private function, and a sync one. You could try the public async version.
Mocha api
Lina Larionova
@Ravekeeper
@juergba I've tried loadFilesAsync() and looks like I am still not able to get dynamically generated tests in my suite.
Loaded test = /Users/lina/stash/mocha-run-data-driven-tests-programmatically/test/plain.spec.js
Loaded async test = /Users/lina/stash/mocha-run-data-driven-tests-programmatically/test/plain.spec.js
Juerg B.
@juergba
@Ravekeeper loadFiles() / loadFilesAsync() loads the files into the cache, but does not build the test tree runner.
You can try this way: gist. Some of the function used are private, I think.
Or you run your async jobs (eg. axios) in programmatic-test-runner.js and pass the result to your test files, globally or via eg. the root suite mocha.suite. Then you create your test dynamically, see docs.
GCHQDeveloper911
@GCHQDeveloper911
Hi all, I've (fairly!) recently moved from Jasmine to Mocha (using webdriverio). Is there a hook available in Mocha along the lines of afterEach, but that gets called just before the test finishes, and that could be used as a final check in the test ... so it could be common across all tests in the suite, but could impact the result of the test?
Obviously one option is just a function, and insert a call into the end of each test, but I think it would be cleaner if a hook could handler it, and would avoid code duplication
Peter Müller
@Munter
Mocha will fail the suite if your afterEach throws. So In that sense you could indeed use that hook for such an assertion
GCHQDeveloper911
@GCHQDeveloper911
Yeah, but from what I can see, the actual spec would be reported as a pass, with the afterEach reported "separately" as a fail?
I'm trying (as you may have guessed!) to work out the best way to wrap 'genuine' assertions in my tests in try/catch blocks, then throw them all as a single assert at the end...
GCHQDeveloper911
@GCHQDeveloper911

Ahhh hang on, I think I'm getting closer!

    this.afterEach(function () {
        if (browser.config.specErrors.length > 0) {
            var errorMsg = '\n\t\t\t' + browser.config.specErrors.join('\n\t\t\t');
            this.test.error(new Error(errorMsg));
        }
    })

Thanks @Munter - I'm 99% there with what I want to do! Now I just want to move the code above from the afterEach hook in my specs, into the afterTest hook in my webdriverIO conf.js - but that's a question for the wdio folks I suspect :)

GreenMonkeyBoy
@GreenMonkeyBoy

Hello, I'd like to test if a stub has been called in a setInterval():

setInterval(() => {
    this.send();
}, 10000);

Spec:

it(`Should call send()`, () => {
    const clock = sinon.useFakeTimers();
    const send = sinon.stub(MyClass, 'send');

    const class = new MyClass();
    clock.tick(10000);

    expect(send).to.have.been.calledOnce;
}

This test works, but in my real app I have async code in the setInterval(), and it makes the test failed (expect...to have been called once, but it was called 0 times):

setInterval(async () => {
    await new Promise(resolve => resolve());
    this.send();
}, 10000);

I've searched and tested a lot and the best supposed explanation I found is in this answer: https://stackoverflow.com/questions/51526312/testing-setinterval-with-sinon-faketimers-not-working, but the solution does not work for me. I've also tried rxjs instead of setInterval() as well as clock.tickAsync(10000) using sinon/lolex but the problem persists.

So before giving up on the idea of testing this part of my code, does anyone have an idea how can I solve this problem?

Peter Müller
@Munter
@GCHQDeveloper911 after 10000 milliseconds you kick off an async task, which obviously might take another milliseconds or two, or at least wait until next tick. That's why your assertion fails
GreenMonkeyBoy
@GreenMonkeyBoy

Unfortunately it doesn't work even if I add more time (e.g: clock.tick(15000)) or decrease the interval timer.

setInterval(() => {
    this.send();
}, 500);

This example still fails the case with the same error "expect...to have been called once, but it was called 0 times".

And as soon as I remove the line await new Promise(resolve => resolve()); everything is working as expected, the number of calls is correct.