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

Cannot read property getFiles of undefined 1.0.0.beta.0/1 #127

Closed
jamespedid opened this issue Mar 28, 2017 · 11 comments · Fixed by #187
Closed

Cannot read property getFiles of undefined 1.0.0.beta.0/1 #127

jamespedid opened this issue Mar 28, 2017 · 11 comments · Fixed by #187

Comments

@jamespedid
Copy link

jamespedid commented Mar 28, 2017

#125
Hello; I'm trying to run mocha-webpack on 1.0.0.beta.0, and it seems that the webpack build process is failing with the following message:

 WEBPACK  Failed to compile with 1 error(s)

Error in ./~/mocha-webpack/lib/entry.js

   TypeError: Cannot read property 'getFiles' of undefined

Tracking it down, it seems like you're calling a getFiles on some config object, but it's not clear to me how this object should be provided, and it's preventing the tests from running. Any suggestions on how to fix this?

Thanks!

EDIT: I tracked it down to be a problem with the webpack.config.test.js file that I have. Maybe this can be detected and thrown an error if something here is wrong.

@pizzarob
Copy link

pizzarob commented Apr 6, 2017

So what was the fix ? @jamespedid

@jamespedid
Copy link
Author

Unfortunately I ended up abandoning mocha-webpack for the time being, however it wasn't the issue because I manually recreated the issue in a different way and found out some configuration issues. However, the way I'm running it now is much faster than mocha-webpack at runtime, especially with JSDOM tests.

We also found it useful to simply use null-loaders for things like CSS and such to load these kinds of files, which was an improvement. Lastly, there was a few odd whitelists that we had to do with nodeExternals to make things work properly with how we were using things.

Here's a few things that I found relevant:

  1. Use a test-context file as your entry point. That is, I found a snippet below that seems to work wonders:
const context = require.context(__dirname, true, /\.test\.js/);
context.keys().forEach(context);
module.exports = context;

For running the tests with parameters, we ended up using a bash script that looks sort of like this. We always output to the same test-bundle.js file and ran it with mocha. We used the source-map-support/register directly when using mocha.

#!/bin/bash -ex

if [[ $1 ]]; then
    webpack --progress --colors --config webpack.config.test.js $1 && mocha --colors --require source-map-support/register .tmp/test-bundle.js
else
    webpack --progress --colors --config webpack.config.test.js test/test-context.js && mocha --colors --require source-map-support/register .tmp/test-bundle.js
fi

The test execution time for ~700 tests dropped from to 3s from a much more significant chunk of time. I'm can't recall what was the biggest contributing factor, but something in our combination didn't work well with mocha-webpack

@bZichett
Copy link

bZichett commented Oct 8, 2017

@jamespedid What was the configuration issue with webpack.config.test.js, though?

@barnabaskecskes
Copy link

I'm having the same issue when trying to hook this into Laravel Mix (even with a fresh Laravel 5.5 install). I have posted a comment there but was advised to post it here instead (see post below from the Laracasts website). I know this is still in beta so hoping that this can be fixed asap. (v0.7 works just fine with the same setup so it is assumed the new version is at fault..)

screen shot 2017-10-28 at 09 02 44

@zinserjan
Copy link
Owner

@barnabaskecskes can you create a repo to reproduce this?

@barnabaskecskes
Copy link

@zinserjan here you are

@fshequin
Copy link

fshequin commented Oct 28, 2017

I have the same problem as @barnabaskecskes .

EDIT: I also solved it by using "mocha-webpack": "^0.7.0" instead of "v1.0.0".

In my NPM test script, I have tested using wild cards for files and folders to be tested, and that works too in "v0.7.0" .

@barnabaskecskes
Copy link

Would be handy if @zinserjan could fix this as I'm having #45 error now, which has been implemented in the beta version that currently fails for us. :)

@zinserjan
Copy link
Owner

Should be fixed with 1.0.1

@barnabaskecskes
Copy link

@zinserjan @fshequin Indeed it is fixed now. Thanks a ton!

screen shot 2017-10-28 at 21 26 17

@fshequin
Copy link

Also fixed for me now too, that was fast for a weekend.....thank you @zinserjan

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

Successfully merging a pull request may close this issue.

6 participants