question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnhandledPromiseRejectionWarning during Mocha unit:test --watch

See original GitHub issue

After editing a component while running unit:test --watch, vuetify-loader causes an UnhandledPromiseRejectionWarning, and the webpack compile/rebuild hangs.

(node:8087) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "from" argument must be of type string. Received type function
    at validateString (internal/validators.js:125:11)
    at Object.relative (path.js:1162:5)
    at JSON.stringify.splitted.map (~/loader-promise-rejection/node_modules/loader-utils/lib/stringifyRequest.js:30:29)
    at Array.map (<anonymous>)
    at Object.stringifyRequest (~/loader-promise-rejection/node_modules/loader-utils/lib/stringifyRequest.js:23:8)
    at install (~/loader-promise-rejection/node_modules/vuetify-loader/lib/loader.js:38:57)
    at Object.module.exports (~/loader-promise-rejection/node_modules/vuetify-loader/lib/loader.js:106:15)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:8087) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:8087) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Simple steps to reproduce: vue --version 3.7.0

vue create my-app “Manually select features”, add Unit Testing, choose “Mocha + Chai” when prompted, everything else defaults.

cd my-app vue add vuetify

Steps to here are in https://github.com/ajhoddinott/vuetify-loader-promise-rejection.

yarn test:unit --watch

vue add vuetify has made changes to HelloWorld.vue without corresponding changes to example.spec.js, so the test fails.

Touch example.spec.js, the webpack rebuild completes and the test is run (and fails) again as expected.

Touch HelloWorld.vue, the webpack rebuild starts, but hangs/dies with the UnhandledPromiseRejectionWarning.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jconocommented, Jun 28, 2019

We are also seeing this issue and while I don’t fully understand what the problem is I can at least recap what I discovered in case it’s useful.

First of all, the problem only shows up for us under these conditions:

  • running test:unit --watch as outlined above (it succeeds on the initial run)
  • a vue component that uses vuetify components (e.g. v-layout)
  • modify the vue component file and save it to trigger the watcher

If the component doesn’t have use any vuetify components we don’t see the error.

Investigating into this a little the problem originates in the vuetify-loader/lib/loader.js file. Specifically (in v1.2.2 anyway) in the lines that install the components / directives line 106 / 107.

content = install('installComponents', content, getMatches.call(this, 'Tag', tags, options.match, component));
content = install('installDirectives', content, getMatches.call(this, 'Attr', attrs, options.attrsMatch, component));

The only thing I discovered about this call was that there seems to be a difference in the context that this code runs in the 2nd time through (upon saving the file). More specifically inspecting this at the point this code fails seems to indicate that this refers to the global object which causes the trouble once the install function calls stringifyRequest(this, ...).

So I think the solution is to make sure that the install function is called with the correct this context much like is done with the getMatches.call on those lines of code.

Anyway, if I manually modify that loader.js file like this (note the .call(this, modification):

content = install.call(this, 'installComponents', content, getMatches.call(this, 'Tag', tags, options.match, component));
content = install.call(this, 'installDirectives', content, getMatches.call(this, 'Attr', attrs, options.attrsMatch, component));

Then everything seems to work and error goes away.

However having not spent a lot of time understanding the vuetify-loader codebase I’m not certain about the ramifications of this and can’t be sure it doesn’t have other side effects that we’ve not seen yet.

I hope this helps. I’m happy to make a PR if this is the correct fix or for someone else to add it in if it is.

1reaction
gdandycommented, May 22, 2019

I’m experiencing the same/similar issue. It’s annoying to have to terminate the test watching and start it back up every time. I’m not sure if its vueitfy related though but I am using vuetify in the project. The only error I get is:

[===                      ] 10% (building)(node:27400) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Path must be a string. Received { [Function] skip: [Function], only: [Function] }
(node:27400) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to handle UnhandledPromiseRejectionWarning in simple ...
So my question is, how can I tell mocha that this test should be marked as failed without implementing any kind of catch...
Read more >
mochajs/mocha - Gitter
I am getting this in my test UnhandledPromiseRejectionWarning when I throw an error in the beforeEach. My test uses async/await.
Read more >
Setup Mocha in watch mode for TDD in Node.js - Promyze
The command npm run test:watch will help me for my TDD session. Everytime a file is saved (CTRL+S with in your favorite IDE),...
Read more >
6 - Testing a promise | Mocha - Javascript unit testing framework
This is the 6th video tutorial of this web series on Mocha ... Nyc - Unit test coverage report and its important configurations...
Read more >
How to write Mocha and Chai unit tests for your Node.js app?
0:00 · New! Watch ads now so you can enjoy fewer interruptions. Got it.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found