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
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?
zeus_
@zeus_:matrix.org
[m]

I have a file ConvertAnyToNotificationItems.test.ts, which exports a method that converts notifications:

import { INotificationItem } from "@ln/notification-abstractions";

export function ConvertAnyToNotificationItems(items: any[]) : INotificationItem[] {

    let result: INotificationItem[] = [];

    items.forEach((item) => {
        result.push({
            id: item.id,
            topic: item.displayText,
            status: item.status
        });
    });

    return result;

}

I'm getting SyntaxError: Unexpected token 'export' when I try to run the test:

import { INotificationItem } from '@ln/notification-abstractions';
import * as Chai from 'chai';
import * as ConvertAnyToNotificationItems from "../../src/Converters/ConvertAnyToNotificationItems";
import * as TypeMoq from "typemoq";

let notificationsItems: TypeMoq.IMock<INotificationItem[]>;
let returnedNotificationsItems, emptyReturnedNotificationsItems: INotificationItem[];

describe("ConvertAnyToNotificationItemsTests", () => {    

    beforeEach(() => {
        // Arrange
        notificationsItems = TypeMoq.Mock.ofType<INotificationItem[]>();
        returnedNotificationsItems = ConvertAnyToNotificationItems.ConvertAnyToNotificationItems(notificationsItems.object);
        emptyReturnedNotificationsItems = [];
    });
});

Can you please help me out?

delthas
@delthas
Hi, does Mocha support async functions in custom reporters .on .once event handlers?
Darin Hensley
@dman777
Does mocha have the ability to record a video on failure?
Rabave3
@Rabave3
How to use the dependent method in mocha.
Example: If the 2nd test dependents on the 1st test case, how to use the dependent method in the 1st test case.
Armando Jose Peña Mujica
@apenaCondorLabs
hello, how i can to set a env varaibles using mocharc.yml?
Scott Casey
@Kurohyou
Hi all, wondering if those more experienced with Mocha/Chai might know what is happening in this stack overflow question I posted. https://stackoverflow.com/questions/73157095/mocha-fails-if-i-change-describe-text
Shivani kushwaha
@Shivani67640697_twitter
How we can add tag in mochajs
Shivani kushwaha
@Shivani67640697_twitter
?
faenqvi
@faenqvi
hi
ieow
@ieow

Hi, I am having issue running mocha test with typescript importing svg file

TSError: ⨯ Unable to compile TypeScript:
src/test.ts:6:25 - error TS2307: Cannot find module '@/assets/logo.svg' or its corresponding type declarations

Anyone hit this issue before?
any solution?

I did declare the .d.ts file

declare module "*.svg" {
  const url: string;
  export default url;
}
ieow
@ieow
Does mocha has Jest's transform feature ?
I would like to mock the svg
https://stackoverflow.com/questions/55169259/how-can-i-manually-mock-svgs-in-my-tests
Wesley Rast
@wsrast
Anyone know why mocha won't show console.logs inside an it() function?
Tashi D. Gyeltshen
@jsassassin:matrix.org
[m]
Hello, I'm trying to update Yargs and Yargs parser to resolve mochajs/mocha#4903. I'm a first time contributor and don't really know what i'm doing but I managed to clone the project and update the node dependency. However what I noticed is that some of the tests fail because it seems that Yargs may have made some changes between 16 and 17 which change the behavior of some of the exit codes specifically there seems to be a change in behavior when using process.exitCode = 1; here https://github.com/mochajs/mocha/blob/77c18d29c565e68a0d487e357765acb5ec776cc6/lib/cli/cli.js#L62. What I noticed is that changing this to process.exit(1) fixes some issues but breaks others. Would anyone happen to know why process.exitCode is used this way. I'm happy to try to solve my own problem but some guidance would be helpful.