Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 08:37
    outsideris labeled #4127
  • 08:20
    outsideris labeled #4129
  • 07:52
    khg0712 synchronize #4127
  • 07:50
    khg0712 synchronize #4127
  • 07:46
    SaeromB opened #4129
  • 07:28
    syeutyu opened #4128
  • 07:25
    outsideris unlabeled #4076
  • 07:25
    outsideris labeled #4076
  • 06:08
    khg0712 opened #4127
  • 02:39
    outsideris labeled #4054
  • 02:39
    outsideris labeled #4054
  • 02:39
    outsideris unlabeled #4054
  • Dec 13 11:41

    craigtaub on master

    Type "rs\n" to restart tests, f… (compare)

  • Dec 13 11:41
    craigtaub milestoned #3979
  • Dec 13 11:41
    craigtaub closed #3979
  • Dec 13 11:34
    craigtaub labeled #3979
  • Dec 13 11:34
    craigtaub labeled #3979
  • Dec 13 11:33
    craigtaub labeled #3979
  • Dec 13 00:01
    plasticrake labeled #4126
  • Dec 13 00:01
    plasticrake opened #4126
Beka Iglesias
@geekshabeka_twitter
I use mocha before but it's the first time that I need to indicate parameters because in this case part of the endpoints are a wrapper for another java server
Craig Taub
@craigtaub
@geekshabeka_twitter if mocha is launching the app, you can pass params to mocha like env KEY=MINE mocha and use process.env.KEY from inside your test code. Hope that helps
Beka Iglesias
@geekshabeka_twitter
Thanks for the answer.I will try it
Veera Subba Reddy
@subbulomada_twitter
Hi All, Can some help on the below issue. I am seeing TypeError: $(..).waitForExist
setValue is not a function.
I am using JavaScript with mocha framework
Jacob Bogers
@Jacob_Bogers_twitter
hi
is setup(...)function part of the mocha test library, I am looking at some code 4yo, and It seems this is part of mocha?
Peter Müller
@Munter
@Jacob_Bogers_twitter It's part of the TDD interface. https://mochajs.org/#tdd
Jacob Bogers
@Jacob_Bogers_twitter
Hi @Munter thanks for answering, just figured it out
my real problem was the my IDE (vscode) was marking "suite" as unknown global, I just had the add { "env":"mocha"} and plugins: ["mocha"] to the eslintrc file
now my IDE isn't screaming anymore
Armin Ayari
@mrastiak
Hello everyone
How can I skip all the remaining test cases in a test suite after one of the test cases fails
Craig Taub
@craigtaub
@mrastiak test cases should really work in isolation and not depend on each others results. So they should be put into the state they require in order to run your tests.
Peter Müller
@Munter
Someone has made a library that gives you this functionality. https://www.npmjs.com/package/mocha-steps
But generally I agree with @craigtaub . Wouldn't recommend using it
Armin Ayari
@mrastiak
@craigtaub Thank you for the fast reply
What I'm testing is the procedure of buying a product and if a step fails the rest of the steps will fail too
Every step here is a test case and creating a test suite for each step with one test case looks like a bad idea to me
Peter Müller
@Munter
You might want to look into other test runners that are purpose-built for this. Like Selenium, Cypress and other browser runners
raghanag
@raghanag
Hi @craigtaub i am using mocha with ts-node to test the spec files written in typescript, i am getting the cannot find module errors when my source file is importing some modules. can you help me here
i am using the below command to run the mocha
    "test:unit": "TS_NODE_PROJECT='components/src/tsconfig.mocha.json' mocha -r ts-node/register components/src/**/*.spec.ts"
and the error
components/src/list-filter/list-filter-viewModel.ts:6:35 - error TS2307: Cannot find module 'ojL10n!./resources/nls/list-filter-strings'.

6 import * as componentStrings from 'ojL10n!./resources/nls/list-filter-strings';
Dave Chappelle
@davidchappelle
Looking for some insights into a problem I have run into several times now. The project that I am working on has a fairly large and growing number of test suites. Occasionally, tests get checked in that cause things like timers and the like to be armed leaving the event loop in a state where it won't exit cleanly. After thousands of tests run, mocha is just left hung at the end of its execution. I typically use wtfnode to track these issues down. However, it would be handy if mocha provided a mechanism by which you could enforce that every test or test suite finished without leaving crap on the event loop. Does such a mechanism exist? Ideally I wouldn't have to litter a bunch of boilerplate around.
Gil Tayar
@giltayar
Hi everybody. I've been wanting to add support for native Node ESM modules in Mocha for quite some time, but the experimental support wasn't very stable (in terms of spec). Now that it's stabilizing, I've started working on a PR for this. Is this something y'all would like to see? This is not a trivial change, as it means turning loadFiles into an async (promise returning) function, and, from what I'm seeing, all the run* stack too. This shouldn't be a problem, as Mocha supports Node>=8, which even has async/await support, but it is a significant change (which I would be glad to implement). Not sure about browser support for this, though. (does Mocha support IE?)
Peter Müller
@Munter
@giltayar mocha does support ie. But I think we could probably roll things up in a node and a browser build. Since the browser build will not be the one loading files it might just work. I don't have much experience with building separate esm, commonjs and browser builds though, do I don't know the potential problems
Gil Tayar
@giltayar
Hmm... I'll have to look at the browser build then. Currently, from what I'm seeing, broeserify
From what I'm seeing, browserify
Is definitely trying to read the loadFiles method. Maybe I can separate that somehow. (sorry For the multiple messages. Mobile...)
But it's not a small endavour, and I'd like to know whether I will be getting any basic objections to node ESM support, before I start working on this.
Peter Müller
@Munter
Not from me. But I'm not the biggest proponent of the conservative browser support range we keep. Would you mind joining mochajs/contributors for this discussion?
Gil Tayar
@giltayar
Would love to. Just join the room and ask? (not sure about the etiquette...)
Peter Müller
@Munter
Yeah, I'm pretty sure it's open for all that want to join.
Craig Taub
@craigtaub
@raghanag is ojL10n!./resources/.. definitely the right path name? ojL10n!. does not look right as a lib.
Perhaps setup and supply us an MCVE (https://stackoverflow.com/help/minimal-reproducible-example).
raghanag
@raghanag
@craigtaub i figured out that I have to use @modulealiases package to resolve the paths when using typescript in node
after this, i was now able to run, but sadly the modules i am using are in amd and node is not able to laod them, even though i am using the amd-loader
Aryan Raj
@aryan000
Object #<Object> has no method 'createHTMLDocument'
I am getting this error while running a test case in html.
I am trying to upgrade jQuery from 1.7 to 3.4.2
any help is appreciated
Peter Müller
@Munter
@aryan000 TRy a channel related to jquery
TC-jPham
@TC-jPham
has anyone seen this error? '(0 , _config.executeHooksWithArgs) is not a function' , on 6.2.0 with webdriverio
aliber4079
@aliber4079
I'm new to testing, is there a human that can walk me thru how this is all supposed to work
Michael Brian Eliot
@michaeleliot
For the --compilers deprecation, I am getting an ERROR: Cannot find module 'coffee-coverage/register'. coffee-coverage is a dev dependency, and per the tutorial I changed --compilers coffee:coffee-script/register to --require coffeescript/register. Any help is appreciated!
Daniel
@Daniel19128708_twitter

Hello everyone,

Can anyone explain to me how can I use a config.file to control some variables outside my Mocha file?
I saw the example on github - https://github.com/mochajs/mocha-examples/tree/master/async-setup-with-file
It seems really simple to build the config.file, but i want to be able to use the variables in my Mocha test.

Craig Taub
@craigtaub
@Daniel19128708_twitter currently config file will not be able to help. However you can set an env var when you run mocha i.e. env KEY=MINE mocha and use it inside the code via process.env.KEY. Hope that helps
Craig Taub
@craigtaub
@Daniel19128708_twitter added a page to the docs for this. pls let me know if doesnt make sense https://github.com/mochajs/mocha/wiki/HOW-TO:-use-environment-variables
thanks
Harry Cameron
@hcphoon01

I am trying to get some unit tests set up, one of the tests I am trying to make is to check to see if a json file has been created after a class in an external file is called.

const chai = require('chai');
chai.use(require('chai-json'));
const DataHandler = require('../handler');
const expect = require('chai').expect;
const path = require('path')

const handler = new DataHandler();

describe('#json handling', function(){
    it('should create a testData.json file', function(){
        const json = path.basename('../testData.json');
        expect(json).to.be.a.jsonFile();
    })
})

The tests are successful if I run them a second time as the testData.json file is created after the first tests are completed. This however shouldn't be the case and the json file should be created even before the test is run when new DataHandler is initialised

This is the first part of my DataHandler class that creates/updates the json file is as follows

class DataHandler{

    constructor(){
        if(this.shouldUpdate()) {this.update()};
    }

    shouldUpdate(){
        if(!fs.existsSync("testData.json")) {return true};

        const file = fs.readFileSync("testData.json");
        const parsed = JSON.parse(file)
        const oldDT = Date.parse(parsed['updated_date']);

        const dateDifference = Date.now() - oldDT;
        const minutes = Math.floor(dateDifference / 60000);

        if (minutes > 2) {return true};
    }

    async update(){
        const body = await this.downloadFile();
        const parsedJSON = JSON.parse(body);
        parsedJSON['updated_date'] = new Date();
        const json = JSON.stringify(parsedJSON);
        fs.writeFileSync("testData.json", json);
    }

    downloadFile(){
        return new Promise((resolve, reject) => {
            request("someurl/data.json", (error, response, body) => {
                if (error) reject(error);
                if (response.statusCode != 200) {
                    reject('Invalid status code <' + response.statusCode + '>');
                }
                resolve(body);
            });
        });
    }
}
Peter Müller
@Munter
@hcphoon01 Your json file creating is async and you are not waiting for it to finish before you run your tests
Harry Cameron
@hcphoon01
Yeh how can I wait for it to finish @Munter
Peter Müller
@Munter
You'll need to expose a promise for it. I'm unsure why you are using a Class instead of just a function that returns a promise
You don't seem to be storing any state on the class at all. Only using methods. This could be entirely functional, and thus easier to expose the promises
Harry Cameron
@hcphoon01
There are more methods in the class than the ones I have included