Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--include does not work when in 'opts' file [Bug] #73

Open
1 task
gdarai opened this issue Jun 19, 2020 · 9 comments
Open
1 task

--include does not work when in 'opts' file [Bug] #73

gdarai opened this issue Jun 19, 2020 · 9 comments
Labels
bug Something isn't working

Comments

@gdarai
Copy link

gdarai commented Jun 19, 2020

  • I'd be willing to submit the fix

Describe the bug
I am upgrading our libraries, so I swapped to mochapack and now I have an issue:
We are having global memory clearing method in cleanUpResources.js

afterEach('Cleanup after test', function () {
    // Remove all listeners added by our test
    console.log('-- clear --');
    listeners.window.forEach((listener) => window.removeEventListener(listener.type, listener.listener));
    listeners.document.forEach((listener) => document.removeEventListener(listener.type, listener.listener));
    listeners.window = [];
    listeners.document = [];
    // Restore sinon sandbox
    sinon.reset();
    sinon.restore();
});

Loading this file using
--include ./test/cleanupResources.js
also using parameter
--opts mochapack.opts

--colors
--recursive
--full-trace
--require mock-local-storage
--require ./test/test_helpers.js
--include ./test/cleanupResources.js

clear and concise description of what the bug is.

when I have the include inline directly it loads the cleanup file. When I have it in the opts file, it does not.

To Reproduce

You can do the same thing I did... have an --include with some file and in it have afterEach with console.log and check the difference with inline and in opts solution.

Environment if relevant (please complete the following information):

Currently I am bypassing this using the inline solution.

@gdarai gdarai added the bug Something isn't working label Jun 19, 2020
@panta82
Copy link

panta82 commented Aug 20, 2020

image

It seems opts file is only parsed if you specify --opts arg. It no longer loads the file by default.

This behavior is a deal breaker for me. I am using opt-file to point the correct webpack config when I run random tests from my IDE. Without it, I'd have to edit every run configuration manually. Too fiddly.

@Jack-Barry
Copy link

Looks like I may have forgotten to include the opts file path here.

Just needs parsedMochaArgs.opts added as the third argument as far as I can tell.

@gdarai Would you be able to test this in your project to see if it fixes what you're getting here?

@panta82 The opts file is deprecated by Mocha, so automatically using it is no longer the strategy used/supported by Mochapack. When you say you're pointing to Webpack config from it, pardon my ignorance but I'm not sure I catch the difference between updating a CLI script argument and updating the contents of the opts file to accomplish this, in both cases don't you still have a manual step involved to configure?

@panta82
Copy link

panta82 commented Aug 26, 2020

@Jack-Barry The trick is that Webstorm IDE allows me to click a little "play" button next to unit tests and run them immediately in an ad-hoc fashion. And I couldn't figure out how to tell Webstorm to use a particular CLI arg when launching tests that way. So an opts file worked nicely for that.

@Jack-Barry
Copy link

@panta82 Would you be able to provide those arguments using a custom run configuration as outlined here? I haven't used Webstorm but from those docs it looks like you should be able to customize the script triggered by the play button.

@panta82
Copy link

panta82 commented Aug 26, 2020

@Jack-Barry Yes, but this is a custom run configuration. You would create these for permanent things you would want to run all the time. Eg. "All tests", "All unit tests", etc.

The problem is when I just want to run an ad-hoc individual test while working on a new code or debugging something. Sure I could click, see it crash, then edit the created run configuration, and then run again. But that's way more fiddly than just using the version of mocha that supports .opts. :)

@dhartjes
Copy link

dhartjes commented Sep 9, 2020

Hello! I'm wondering if the opts section could be removed from the documentation. Thanks for picking this up!

@ascii-soup
Copy link

@panta82 Forgive me if you are aware of this already, I appreciate this is months later, but you can edit the templates for ad-hoc run configurations in Webstorm - just look for the 'Templates' section in the list below your normal run configurations. Here you can select 'Mocha' for example, and then set the properties you wish to be inherited by all new run configurations created for Mocha inside that project. Hope this helps!

@jcjp
Copy link

jcjp commented Mar 3, 2022

What's the alternative for the *.opts file? Just add it on the node/npm command itself i'm only using the CLI.

@Bistard

This comment was marked as abuse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants