Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 17:05
    stale[bot] closed #4098
  • 11:07
    New Donation: CodeFund gave USD 6.91 to MochaJS! [Thank that person on Twitter]
  • 09:19
    giltayar synchronize #4038
  • 08:31
    giltayar synchronize #4038
  • 08:09
    giltayar synchronize #4038
  • Dec 04 18:44
    JosejeSinohui synchronize #4112
  • Dec 04 18:08
    TheRoSS opened #4119
  • Dec 04 18:08
    TheRoSS labeled #4119
  • Dec 04 17:52
    kylef opened #4118
  • Dec 04 15:53
    giltayar synchronize #4038
  • Dec 04 15:04
    giltayar synchronize #4038
  • Dec 04 14:50
    giltayar synchronize #4038
  • Dec 04 14:41
    giltayar synchronize #4038
  • Dec 04 14:31
    giltayar synchronize #4038
  • Dec 04 12:53
    giltayar synchronize #4038
  • Dec 04 12:36
    giltayar synchronize #4038
  • Dec 04 10:05
    giltayar synchronize #4038
  • Dec 04 09:48
    giltayar synchronize #4038
  • Dec 04 06:25
    giltayar edited #4038
  • Dec 04 03:59
    New Donation: Crossword King gave USD 2 to MochaJS!
Khai Chang
@kchang4
Yo was wondering if i could get some quick tips on my configuration file. it looks correct but seems not correct. Also is there a config file example that contains all the options and their correct value formats??
any help wold be nice. I wanna just run mocha in the cmd line and have it work. it seems like my --ignore and --spec options aren't working?
Alexandrith C Sharron
@asharron
@kchang4 Are you getting an error when running your mocha command, or is it just that the functionality is not working as expected?
Khai Chang
@kchang4
not wokring as expected
especially my ignore option
its testing files that are in my node_modules.... that match my --spec options
running mocha 6
is there a good example config file i can look at? the ones provided by mocha only have a couple options
i wanna see a full config example file so i can the format of all the values
see*
the docs are nice, but they dont show much details on the actual config file
Alexandrith C Sharron
@asharron

Hmmm, I don't know one off hand nor do I have one for any of my current projects. Maybe someone else can point you in the right direction.

One idea may be that your ignore may need beginning slash to indicate its a directory

 "ignore": ["/node_modules"]

Another workaround would be to just point mocha to your tests directory, if you keep all of your tests under one directory that is:

  "spec": ["./src/tests/**/*.spec.js"],
Khai Chang
@kchang4
We like our tests to sit right next to the actual files, easier to grab and use and visualize
hmm nvm i got it, ignore needed to be ["./node_modules/**"]
i guess because of the recursive option?
weird
ty guys
Alexandrith C Sharron
@asharron
Glad you got it!
Khai Chang
@kchang4
no complete config file example anywhere?
Craig Taub
@craigtaub
@kchang4 couple of config examples here https://github.com/mochajs/mocha/tree/master/example/config. Plus some simple ones at https://github.com/mochajs/mocha-examples/ .
Khai Chang
@kchang4
yeah those were the first ones i used/erefenced
they're nice but too simple in that they dont include all the options
Sam Tietze
@samtietze

Hello all! I have been running around SO, mocha source, issues, and any other tutorials I can find, but I am still doing something wrong...
I'm executing mocha programmatically, within node, so I know this is atypical. However, I must be missing something someone with more experience than me knows about. Suffice it to say, in one file I want to export a describe block with a couple of its inside. In another file I want to export another describe block (or maybe just a solo it test).
At my entrypoint I instantiate:

const mocha = new Mocha({
    delay: true,
    timeout: 30000,
    ui: 'bdd',
});

mocha.suite.addSuite(someSuite);

and in the same file I execute mocha.run(). When I run my script, (node src/index.ts), I get the following error:

TypeError: mocha_1.describe is not a function
I've seen a lot of folks respond to this sort of issue with "you must run mocha with mocha /tests/**.spec.js", or similar approaches where the goal was to run a test multiple times from a file (and the resulting solution involved clearing the require cache). Nobody has really offered any kind of tips or ideas on how to run with node :/
Sam Tietze
@samtietze

Whoops. Neglected to mention in my last message, my script does include node -r ts-node/register src/index.ts
Does thists-node/register requirement mean I'm suffering from the same require cache not-bug that other folks have discussed??

Here's an example of a describe that is failing:

import { expect } from 'chai';
import { describe } from 'mocha';

export default describe('this is a parent test suite', function () {
    it (`does something`, () => {
        expect(true).to.be.true;
    });

    it (`does another thing`, () => {
        expect(1).to.equal(1);
    });
});

I assume my index's import Mocha from 'mocha'; is causing some kind of issue with accessing these interface functions appropriately. I see that describe was given the warning:
Only available when invoked via the mocha CLI.
but... that's gotta be baloney

is the only possible way to operate this sort of dynamic adding of suites to root suite, or tests to suites, within the spec files? And we can only run mocha.addFiles(myspecs);?
note that I've tried exporting that describe wrapped in a func as well
There are definitely advanced JS/TS concepts that escape me, but if anyone has a tip, I will do the legwork!
Khai Chang
@kchang4
If you're using a mocharc file it could be that. I ran into this once when i had some bad values in my mocharc. Was using "ui": "tdd", and got the same error, removed that and it worked. Otherwise, good luck.
José Jesús Sinohui Fernández
@JosejeSinohui
Hi everyone, i made a pull request to solve an issue about handling BigInts in the stringify util, (#4112) however, it fails the build for node version 8 because BigInt is not defined (used for the unit test) on that version, is there a workaround for this?
Sam Tietze
@samtietze
@kchang4 ah, I've seen a lot of folks with this issue deriving from ui: 'tdd' vs. 'bdd' in their mocha options. In the examples I've seen, the object within the new Mocha() constructor should be acceptable as well
I don't get it...
Nimdim
@Nimdim

Hello to all! Yesterday I asked a question about configuring mocha to use two compilers: coffeescript and babel (for ES6 features). With help of @craigtaub the solution was found. It was to require a setup file written in JS via command line argument:

mocha --require ./setup.js test_file_ES6.coffee

setup.js is

const register = require('@babel/register').default;
require('coffeescript/register');
register({ extensions: ['.coffee', '.js'] });

This worked perfectly and my test_file_ES6.coffee was executed.
Now there is another problem: when in test_file_ES6.coffee I'm importing a nodejs module my_common_package it is not compiled by babel: in command line I see error like:

/home/name/work/projects/alpha/my_common_package/src/coffee/file.coffee:3
import * as translations from './translations.coffee';
^^^^^^

SyntaxError: Unexpected token import

Could someone help with this?

Craig Taub
@craigtaub
@Nimdim so does your test_file_ES6.coffee file use import and work?
Nimdim
@Nimdim

@craigtaub yes. test_file_ES6.coffee has import statement. It looks like this:

import pkg from "my_common_package"
...

and this works

Nimdim
@Nimdim

I have built a chain of imports to check if importcommand failed immedeately after the first import.
it looks like this:
test_file_ES6.coffee imports test_import1.coffee
test_import1.coffee imports test_import2.coffee
and the last file does the import of my_common_package

and the error was at the same place as above: /home/name/work/projects/alpha/my_common_package/src/coffee/file.coffee:3
pretty strange

there is a kind of a solution. to use this setup.js which required by mocha:

var defaultOptions;

defaultOptions = {
  sourcemap: true,
  transpile: {
    env: {
      development: {
          sourceMaps: 'inline',
          plugins: ['source-map-support']
      }
    },
    presets: ["@babel/preset-env"]
  }
};

require('module').prototype.options = defaultOptions;
require('source-map-support/register');
require('coffeescript/register');

module.exports = function(options) {
  require('module').prototype.options = options != null ? options : {};
  require('source-map-support/register');
  return require('coffeescript/register');
};

with this config there are no errors with import keyword but the sourcemaps became broken and the bugsearching in tests' source code become a real headache

Nimdim
@Nimdim
Hello all again! So there are two options: the first have source maps but fail to build a npm module which included by a test, the second which builds all but have broken sourcemaps
It would be great to union features of both methods. If someone have any ides it would be great. Thanks for attention
DJ Tinkers
@TinkersDj_twitter

Anyone interested in an opensource project?

Spec oriented development speeds up programming by generating code based on tests/specs. Tests required will be the same or less specs as a normal developer writes.

https://github.com/Neur0plasticity/spec-dev

MSG me if interested

SandeepNS12
@SandeepNS12
Hey, Do anyone have any kind of docs or related stuffs about API testing interview questions? And I can I prepare on that?
larry kirschner
@beatthat
anyone use circleci with the --delay option? I need delay to perform setup for mongo-unit. My setup works in a local env, but in circleci it doesn't find any tests when delay is set. Have played with it a bit on circleci via ssh, I can see that my init.spec.js is executing but the callback from the async call therein (to start mongo-unit) never fires. The call to mocha::run is in that callback so I guess that's why it's not running any tests. Wondering if anyone has encountered similar?
Dzanan91
@Dzanan91

Hey guys I have started using mocha with selenium and when I try to click on certain element I get this error:

ElementNotInteractableError: element not interactable
(Session info: chrome=78.0.3904.108)
at Object.throwDecodedError (node_modules\selenium-webdriver\lib\error.js:550:15)
at parseHttpResponse (node_modules\selenium-webdriver\lib\http.js:563:13)
at Executor.execute (node_modules\selenium-webdriver\lib\http.js:489:26)
at process.internalTickCallback (internal/process/next_tick.js:77:7)

halp plez :D
Peter Müller
@Munter
@Dzanan91 That's unrelated to mocha. Try asking in a selenium or webdriver related channel
Craig Taub
@craigtaub
@Dzanan91 fyi we have a working configuration (u can clone from https://github.com/mochajs/mocha-examples/tree/master/packages/selenium) if you want to try anything out with it
Gary Schwartzbard
@gschwa
Hi. Has anyone found a way to define suite level retries?
I was looking for an approach to either create a custom UI or somehow extend the runner