Giter Site home page Giter Site logo

maty21 / mocha-sidebar Goto Github PK

View Code? Open in Web Editor NEW
192.0 192.0 61.0 71.61 MB

Mocha side bar viewer that allows you to run Mocha tests from side bar menu and view results can run each level hierarchy from all tests to a single test(and each describer of course)

License: MIT License

JavaScript 99.91% TypeScript 0.09%

mocha-sidebar's People

Contributors

adenflorian avatar alliesfriel avatar ankon avatar aritheelk avatar celador avatar dfischer avatar eramitmittal avatar immanuel192 avatar kendfrey avatar maty21 avatar pieterwillaert avatar scriptcoded avatar sportnak avatar svennergr avatar tomoyukiaota avatar townbully avatar yehiyam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mocha-sidebar's Issues

mocha.requires (settings.json) is not taken into consideration when debuging a single test

When I run all my tests through a debug configuration like this:

        {
            "type": "node",
            "request": "launch",
            "name": "Debug Mocha Tests",
            "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
            "args": [
                "-u",
                "tdd",
                "--timeout",
                "10000",
                "--colors",
                "${workspaceFolder}/Tests/Mocha/Features",
                "--require",
                "${workspaceFolder}/config/local.js"
            ],
            "internalConsoleOptions": "openOnSessionStart"
        }

THEN the --require option is taken into consideration and I can debug the code inside config/local.js.

BUT when I open a single test file and inside the test I click on "Debug Item", then the config/local.js is not loaded.
How to I get my --require files to load before the test when clicking on "Debug item"?

In .vscode I have a settings.json file that looks like this:

{
    "mocha.files.glob": "tests/mocha/features/*.js",
    "mocha.options": {
        "timeout" : 10000
    },
    "mocha.requires": [
        "config/local.js"
    ]
}

I've read through the Q&A without any luck.

Thanks

How can I pass options to mocha?

Hi,
I have a codebase in typescript so usually I am running mocha with the parameter --compilers ts:ts-node/register

I saw you have a mocha.options parameter in this extension but and I tried a few things but cant get it to work.
"mocha.options": {
"compilers": {
"ts": "ts-node/register"
}
},
^ not working

Are these types of options supported?

mocha-sidebar empty upon startup

Sometimes (not always) when I open vscode absolutely no tests show up in the sidebar. Clicking the refresh button does not help either.

After restarting vscode they show up again.

"Test file(s): undefined"

Hi,

My test files show up in the sidebar, but when I try to Run All Tests I get the same type of error as in #13:

Running Mocha with Node.js at /Users/jeff/.nvm/versions/node/v8.9.1/bin/node

Applying Mocha options:
  {
    "ui": "bdd",
    "timeout": 10000,
    "recursive": true
  }

Test file(s):
  undefined
module.js:538
    throw err;
    ^

Error: Cannot find module '/Users/jeff/VSCode/api/src/undefined'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at /Users/jeff/.vscode/extensions/maty.vscode-mocha-sidebar-0.13.5/node_modules/mocha/lib/mocha.js:220:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/Users/jeff/.vscode/extensions/maty.vscode-mocha-sidebar-0.13.5/node_modules/mocha/lib/mocha.js:217:14)
    at Mocha.run (/Users/jeff/.vscode/extensions/maty.vscode-mocha-sidebar-0.13.5/node_modules/mocha/lib/mocha.js:469:10)
    at Object.<anonymous> (/Users/jeff/.vscode/extensions/maty.vscode-mocha-sidebar-0.13.5/worker/runtest.js:63:7)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)

I have the following config in my User Settings:

    "mocha.options": {
        "ui": "bdd",
        "timeout": 10000,
        "recursive": true
    },
    "mocha.files.glob": "test/**/*.js",
    "mocha.files.ignore": [
        "test/fixtures/**/*"
    ],
    "mocha.env": {
        "BLUEBIRD_DEBUG": "1",
        "BLUEBIRD_W_FORGOTTEN_RETURN": "0",
        "JWT_KEY": "XXXXX"
    },
    "mocha.node_options": [
        "--trace-warnings"
    ]

I am able to run my tests from the command line using both nyc and mocha:

$ yarn run test
yarn run v1.3.2
$ JWT_KEY=XXXXX nyc mocha


debug: -------------------------------------------------------
debug: :: Thu Nov 16 2017 15:49:01 GMT-0800 (PST)
debug: Environment : development
debug: Port        : 18888
debug: -------------------------------------------------------
  Controller: AdminController
    Route: GET /admin/alive
      ✓ should respond with an alive message

[ ... ]

  716 passing (9s)
  4 pending


=============================== Coverage summary ===============================
Statements   : 80.2% ( 3204/3995 )
Branches     : 67.07% ( 1167/1740 )
Functions    : 85.61% ( 595/695 )
Lines        : 80.84% ( 3131/3873 )
================================================================================
✨  Done in 11.05s.

But it seems like the files argument in worker.js is not being set correctly:

args.files.forEach(file => {

Any help would be appreciated!

Failed tests do not turn red if failure occurs in Mocha hooks

When an assertion fails in one of the Mocha hooks like before, beforeEach or afterEach, the corresponding test entry in the moca-sidebar does not turn red. Example:

describe("some test", () => {

  before(() => {
    // this assertion fails, but mocha-sidebar test entry does not turn red
    assert.equal(1, 2);
  });

  it("should pass", () => {

  });

});

Typo

finish failuare amount:0
should be
finish failure amount:0
Proper capitalisation would also be nice.

Location of "requires"

Hi, I cannot make your extension work.
I need to require a setup file before mocha executes.
This file is located in the root of my project "mocha.js"

When I specify "mocha.requires": ["./mocha.js"] it is giving me error that .. "node_modules/./mocha.js" cannot be found. It seems that the search starts in node_modules for some reason. I tried myriads of combinations "mocha.js" .. "../mocha.js" .. nothing seems to work.

The situation is complicated even more that the project is typescript. Therefore my "mocha.files.glob" is "src/**/*.test.ts".

Any advice how can I make this work?
Thanks

Blue dots not changing colour

Sometimes when tests fail the dots stay blue instead of turning red and after that it seems they don't go green even after fixing the tests until I restart vscode and re-run them.

refresh not update lenses

on refresh we should create code lenses again but only after item
updated in order to prevent inconsistent behavior

Test file(s): undefined

Everything appears set up OK (VSCode on Debian) but sidebar isn't locating test files, when runs I am just seeing:

Running Mocha with Node.js at "/usr/local/bin/node"
Applying Mocha options:
{
"mocha.files.glob": "test/**/*.js"
}
Test file(s):
undefined

Is there any basic setup I am missing?

thanks

Add License

Great extension! Could you add a license?

Use mocha options provided in Settings when debugging

Summary

We are still using the default args value for the path to the tests when we run tests in debug mode using the sidebar.

Origin

We are hardcoding the arguments we use when we run Mocha in debug mode as can be seen in the snippet:

~/.vscode/extensions/maty.vscode-mocha-sidebar-0.13.2/provider-extensions/runDebug.js

62|  callFunctionOnTerminate = functionOnTerminate.bind(_provider);
63|  mochaTest.args = ["./test/**/*.js"]

This above assignment of args is repeated for the methods debugLevel and debugItem as well.

Suggestion

Parse and use the options provided in the User/Workspace Settings file as the value for the argument to be used to run Mocha in debug mode.

Better error output

I'm getting this in a project:

so it says there's an error, and to see the output, but the output is only shows that line ... nothing more.

How can I debug what's going on, so I can make this amazing extension to work? :)

BTW The extension is working on other projects on the same machine.

Q: Is there a way to prevent the output window from activating?

Very happy to have discovered this project, and it's proved to be a good productivity tool.

The only slightly jarring thing, for me personally, is the constant activation and streams of text that appear in the output window. I tend to spend a lot of time in the terminal, and I have to keep switching back to that, only to have mocha-sidebar jump back to the output window.

As there are already indications in a sidebar, and inline in code, it would be great to have an option to disable output / or better still, an option to not automatically switch to the output window, allowing me to chose if I want it displayed or not. Perhaps I have missed an existing option to do so...?

Is it possible to print out mocha error message into "output" area

I saw an error alert emitted in my usage today, but I didn't know why it alerted:

2017-12-23_22-30-45
Until I ran the original mocha command I saw the compiling error in the log through the terminal, which is actually also highlighted in the screenshot above.

So is it possible or is there any options I could use to make the mocha's original log or error messages could be brought out ?

location of run options in test source

The run/debug option that appears in the test source code is appearing in the wrong place. It works, but it shows on the wrong it. See the attached image, the upper it has 2x run options, and the lower it has NO run options.

image

bug: finding..

Finding tests with Mocha on Node.js at "C:\nodejs\node.EXE"

Can't debug with Typescript

I can't debug with Typescript. I set a breakpoint and it seems to be ignored.

Here is my config:

"mocha.files.glob": "src/**/*.spec.ts",
"mocha.runTestsOnSave": "true",
"mocha.requires": [
    "ts-node/register"
],
"mocha.options": {
    "compilers": {
        "ts": "ts-node/register"
    }
}

Debug Suite/Item fails when using TDD ui

When trying to debug suite or item by clicking on the lens link, the exception is thrown:

Exception has occurred: ReferenceError
ReferenceError: suite is not defined
at Object. (...\test.js:6:1)
at Module._compile (module.js:641:30)
at Object.Module._extensions..js (module.js:652:10)
at Module.load (module.js:560:32)
at tryModuleLoad (module.js:503:12)
at Function.Module._load (module.js:495:3)
at Module.require (module.js:585:17)
at require (internal/module.js:11:18)
at ....vscode\extensions\maty.vscode-mocha-sidebar-0.14.5\node_modules\mocha\lib\mocha.js:220:27
at Array.forEach ()
at Mocha.loadFiles (....vscode\extensions\maty.vscode-mocha-sidebar-0.14.5\node_modules\mocha\lib\mocha.js:217:14)
at Mocha.run (....vscode\extensions\maty.vscode-mocha-sidebar-0.14.5\node_modules\mocha\lib\mocha.js:469:10)
at Object. (....vscode\extensions\maty.vscode-mocha-sidebar-0.14.5\node_modules\mocha\bin_mocha:404:18)
at Module._compile (module.js:638:14)
at Object.Module._extensions..js (module.js:652:10)
at Module.load (module.js:560:32)
at tryModuleLoad (module.js:503:12)
at Function.Module._load (module.js:495:3)
at Function.Module.runMain (module.js:682:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:613:3

Running tests through lens links or running on save works. It seems the workspace mocha settings options are not passed in when debugging.
This only happens if TDD ui is used, if the default ui is used then the debugging works.

How to run all tests with single trigger.

When I right click on Tests and click run all tests, I get exception with this stack trace

Test file(s):
  undefined
module.js:529
    throw err;
    ^

Error: Cannot find module '/home/user/dir1/dir2/dir3/undefined'
    at Function.Module._resolveFilename (module.js:527:15)
    at Function.Module._load (module.js:476:23)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at /home/user/.vscode/extensions/maty.vscode-mocha-sidebar-0.10.0/node_modules/mocha/lib/mocha.js:220:27
    at Array.forEach ()
    at Mocha.loadFiles (/home/user/.vscode/extensions/maty.vscode-mocha-sidebar-0.10.0/node_modules/mocha/lib/mocha.js:217:14)
    at Mocha.run (/home/user/.vscode/extensions/maty.vscode-mocha-sidebar-0.10.0/node_modules/mocha/lib/mocha.js:469:10)
    at Object. (/home/user/.vscode/extensions/maty.vscode-mocha-sidebar-0.10.0/worker/runtest.js:57:7)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Function.Module.runMain (module.js:665:10)
    at startup (bootstrap_node.js:201:16)

Sidebar failed to load tests

I have mochajs project with bable transpiler.
When i install mocha-sidebar in vscode, tests are not showing up.
api-test(root folder)/smoke-test/smoke.js is my test location.
When I change test location to this, it give me error
"Mocha sidebar: Process exited with code 255. See Mocha output for more info."
when i check mocha output, it says Finding tests with Mocha on Node.js at "/usr/local/bin/node"
I have set my settings as
{"mocha.options": {
"compilers": {
"js": "./custom-babel-register.js"
}
},
"mocha.requires": [
"babel-polyfill"
],
"mocha.files.glob": "api-tests/smoke/*.js"
}

Settings ignored: runTestsOnSave

Hi @maty21!

First of all, great work on this plugin!

I am having some issues with the test runner. When I save a .ts file, the mocha sidebar still runs the tests even though runTestOnSave is false. Here are my settings:

{
    // Mocha: Options to run Mocha
    "mocha.options": {
        "compilers": {
            "ts": "ts-node/register"
        }
    },
    // Mocha: Glob to search for test files
    "mocha.files.glob": "app/scenarios/**/*.scenario.ts",
    // Mocha: Globs to ignore when searching for test files
    "mocha.files.ignore": [
        "**/.git/**/*",
        "**/node_modules/**/*"
    ],
    //Mocha: run tests on each save
    "mocha.runTestsOnSave": "false",
    // Mocha: Environment variables to run your tests
    "mocha.env": {},
    // Mocha: Options to pass to node executable
    "mocha.node_options": [],
    // Mocha: Subdirectory in the Workspace where run mocha from
    "mocha.subfolder": "",
    // Mocha: List of files to require before running mocha
    "mocha.requires": [
        "ts-node/register"
    ],
    //Mocha: this option allows you to enable/disable lens decorations and set update threshold "
    "mocha.sideBarOptions": {
        
        "default": {
            "lens": true, // -> enable/disable lens
            "decoration": true, // -> enable/disable decoration
            "autoUpdateTime": 5000 // -> set timeout between each decorations and lens updates during test writing 
        }
    }
}

Unexpected token import while debugging single test

I have the following in my settings.json

  // Mocha: Glob to search for test files
  "mocha.files.glob": "src/test/**/*.ts",

  // Array of module required to run Mocha. (for example babel-register, coffee-script/register or ts-node/register)
  "mocha.requires": [ "ts-node/register" ],

The mocha sidebar shows my tests and runs the just fine.
If I click on debug I get the following error:

SyntaxError: Unexpected token import
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:607:28)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at C:\Users\user\.vscode\extensions\maty.vscode-mocha-sidebar-0.14.20\node_modules\mocha\lib\mocha.js:220:27
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (C:\Users\user\.vscode\extensions\maty.vscode-mocha-sidebar-0.14.20\node_modules\mocha\lib\mocha.js:217:14)
    at Mocha.run (C:\Users\user\.vscode\extensions\maty.vscode-mocha-sidebar-0.14.20\node_modules\mocha\lib\mocha.js:469:10)
    at Object.<anonymous> (C:\Users\user\.vscode\extensions\maty.vscode-mocha-sidebar-0.14.20\node_modules\mocha\bin\_mocha:404:18)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

In the debug console I can see the following command is executed:

node --inspect-brk=24297 ..\..\..\.vscode\extensions\maty.vscode-mocha-sidebar-0.14.20\node_modules\mocha\bin\_mocha src/test/**/*.ts --grep '^Hello function should return hello world$' 

As you can see, no arguments are passed to mocha. If I add --require ts-node/register the run works. How can I pass arguements to mocha while debugging a single test?

If I create a mocha.opts file a directory test with --require ts-node/register debugging will work. But that's not a good solution since my tests live in src/test/ not in test

Mocha Debug and Report Options

Hi, I have two questions about the mocha sidebar options.

  1. When I run this command at the Windows prompt, this works perfectly:
    npm mocha --ui bdd - reporter mocha-simple-html-reporter - reporter-output options = report.html

Ok, but when I use the mocha-sidebar in VS Code

Open User Settings:
File -> Preferences -> Settings (VS Code)

{
"mocha.options": {
"ui": "bdd",
"reporter": "mocha-simple-html-reporter"
}
}

ok, but how to configure "--reporter-options output = report.html"?

  1. When I run this command at the Windows prompt, this works perfectly:
    npm mocha --debug-brk

Ok, but when I use mocha-sidebar in VS Code

Open User Settings:
File -> Preferences -> Settings (VS Code)

{
"mocha.node_options": [
"debug"
]
}

Ok, there another option to configure "--debug-brk"?

Thanks for the advance.

"mocha.subfolder" is missing? Is there an alternative?

My TypeScript project has a structure like this.
-- src/test (all TypeScript test files)
-- out/test (all JavaScript test files)
-- package.json

I suppose "mocha.subfolder" = "out/test" tells the sidebar where to find the tests. Howerver, this setting is not available anymore. What is the alternative?

P.S: To run tests manually, "mocha out/test --recursive" works fine.

Test Runner Restarts

Version Info
mocha-sidebar: 0.14.20
mocha: 3.5.3

Problem:
When I have a test with multiple test cases (it(...)) in a describe function.

When I want to run a group of tests (describe) the plugin starts them all individually meaning that I lose all scope.

Expectation:
I would expect all test cases run inside a describe function to be executed in the same run and not to lose variable scope.

Example

describe('Scenarios', () => {

    // then run your test
    describe('Company Suggest Job', () => {

        let user: IdentityModel;
        let userToken: JwtEncodedModel;

        it('should create a user', inject([Done], (done: Done) => {

            let userData: any = {
                username: '[email protected]',
                password: 'Password123!'
            };

            SuperTest('http://localhost:9000')
                .put('/me/')
                .send(userData)
                .expect(200)
                .end((err, response: any) => {
                    if (err) {
                        throw (err);
                    }

                    let obj = JSON.parse(response.text);
                    expect(obj.id).to.not.be.undefined;
                    user = obj;
                    done();
                });
        }));

        it('should login as user', inject([Done], (done: Done) => {

            let loginData: any = {
                username: '[email protected]',
                password: 'Password123!',
                clientId: 'O7895v6bFs1fObkADKgW5RnMyjQr44Gt'
            };

            SuperTest('http://localhost:9000')
                .post('/auth/login/')
                .send(loginData)
                .expect(200)
                .end((err, response: any) => {
                    if (err) {
                        throw (err);
                    }

                    let obj = JSON.parse(response.text);
                    expect(obj.accessToken).to.not.be.undefined;
                    userToken = obj;
                    done();
                });
        }));

    });

});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.