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

mocha --watch breaks the parser #605

Closed
luxzeitlos opened this issue Nov 20, 2017 · 14 comments
Closed

mocha --watch breaks the parser #605

luxzeitlos opened this issue Nov 20, 2017 · 14 comments
Labels

Comments

@luxzeitlos
Copy link

this is very strange, but when I'm running mocha everything works fine, however when using mocha --watch only the first run will succeed, after then the parser will always return [].

Is this a known Issue? I can try to build a minimal example if it will help.

@bd82
Copy link
Member

bd82 commented Nov 20, 2017

Interesting, I just reproduced this using one of the samples grammars.

@bd82
Copy link
Member

bd82 commented Nov 20, 2017

Try adding:

require("chevrotain").clearCache();

before your tests, for example at the start of your test module or
using a "beforeAll".

This resolved the problem in my small reproduction.
I am guessing that mocha caches the commonjs modules and this somehow conflicts with
Chevrotain's own cache management.

Not sure how to get a deeper understanding here as I am not sure how to actually
debug in watch mode.

@bd82
Copy link
Member

bd82 commented Nov 20, 2017

Maybe I should add a section in the faq about this.

@luxzeitlos
Copy link
Author

Not sure how to get a deeper understanding here as I am not sure how to actually
debug in watch mode.

You can call mocha --watch --inspect and then go to chrome://inspect.

@bd82
Copy link
Member

bd82 commented Nov 22, 2017

You can call mocha --watch --inspect and then go to chrome://inspect.

Thanks. I will try to debug is farther, perhaps it would be possible to avoid this workaround.

@bd82
Copy link
Member

bd82 commented May 24, 2018

I've finally gotten around to debugging this.
the --inspect works great! 👍

What happens is that mocha reloads the user files during watch, but not the libraries inside
node_modules. Chevrotain manages cache related to user created parsers internally
but this cache does not get reset every time the watcher restarts the tests.

Effectively this creates multiple Parsers with the same name (see #715)
And in future versions will fail fast with a better error message.

I don't see a way to tell mocha to also reload chevrotain each time the tests are re-run
So the only workaround I can think of is to invoke clearCache (once), before the tests run.

@bd82 bd82 closed this as completed May 24, 2018
@luxzeitlos
Copy link
Author

Nice. Maybe add this to the documentation? Sounds like this just needs to be added to beforeEach for a testsuite?

@bd82
Copy link
Member

bd82 commented May 24, 2018

I think it needs to be added to the beforeAll of the entire test suite.

But it depends on the granularity of mocha --watch.
If mocha re-runs only specific tests due to code changes than maybe a beforeEach is needed
But if it just re-runs everything a beforeAll will suffice.

running clearCache too often will slow down the tests as it will force chevrotain to recompute
many things redundantly, so it may defeat the purpose of the --watch flag.

@bd82
Copy link
Member

bd82 commented May 24, 2018

I will add a section in the FAQ

@bd82 bd82 reopened this May 24, 2018
@bd82 bd82 closed this as completed in 210cf53 May 24, 2018
@bd82
Copy link
Member

bd82 commented May 24, 2018

Website will be updated once I republish it again.
I would probably only do so when I release a new version as otherwise it will mess up the
changelog a bit.

@bd82
Copy link
Member

bd82 commented Jun 25, 2018

I am reopening this because solving #754 should also fix this issue.

@bd82 bd82 reopened this Jun 25, 2018
@bd82
Copy link
Member

bd82 commented Jun 27, 2018

This should be resolved in 3.7.0 that will be released soon.
As the global Cache has been removed mocha reloading user's modules will create a new Parser instance with instance level cache so there would be no conflicts.

@bd82 bd82 added the Bug 🪲 label Jun 27, 2018
@bd82 bd82 closed this as completed Jun 27, 2018
@luxzeitlos
Copy link
Author

Awesome! 👍

@bd82
Copy link
Member

bd82 commented Jun 27, 2018

😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants