-
Notifications
You must be signed in to change notification settings - Fork 73
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
Module not found: Error: Cannot resolve module 'fs'... #148
Comments
Upon further investigation, I found that webpack doesn't seem to provide a shim for Let me know if I'm on the right track. |
Sounds like you are on the right track - if there's no fs module, difficult to see how file search will work, however it should be possible obtain the feature files in an alternative way. Some options may be...
|
Thank you so much for the quick response! I think I can just let karma ignore those EDIT (just as I'm writing this message I discovered something): It appears This whole custom rewriting thing is bearable if it works, but please please let me know if there's an easier way assuming that I can already acquire the feature files in plain text. Thanks! |
Assuming you can obtain the files as plain text I would try...
Feature: some feature
Scenario: some scenario
Given X
Then Y
new Yadda.WebPackFeatures().each(function(file) {
|
Thank you so much for the detailed answer!! I realized that I misunderstood the webpack context thing in that it doesn't give me the text file, but only gives me a path to the bundled file like this Thanks again :) |
That would be awesome! Thanks |
@cressie176 hey, I created a sample project, and I managed to start karma without any errors 😃 however, I don't think the tests are run... When I run karma, it will launch the browser in which I can click "Debug" and check the console for any info or errors, but all I see is "Skipped 0 tests". Could you take a look at it and help figure out if the tests are indeed run? Here's the repo https://github.com/samzhao/yadda-karma-webpack Thanks very much! EDIT: I just read through @zpratt 's repo https://github.com/zpratt/yadda-karma-example, and it's quite obvious that he knows the library better than I do. I noticed that he also acquired the feature files via AJAX just like I did in the sample project, but he set the |
Good stuff. I'll also take a look (wont be this weekend though) |
Thanks! Please let me know when you do because even though I got it working now (with |
@cressie176 more updates: I am finally able to run tests now after applying 2 fixes to my code:
|
Any update on this? Is there a workaround that doesn't require giving up async? |
Nothing from my side. I haven't used karma and am not finding much time to investigate |
@semblant is there any critical feature you are missing by disabling async for fetching the feature files? In my case, I think I either had to disable async or write some custom karma or yadda plugin, and the former option is the easiest the quickest. Besides, I didn't miss much by doing so. |
Is there any interest in a PR to merge my project as an example to show how to use this with karma if using sync ajax to load the feature files is acceptable? |
Was thinking about this. My problem is I don't have enough karma knowledge to maintain the example if it goes wrong (e.g. karma gets updated with a different version). The absolute idea would be a spin off project, similar to cucumber-boilerplate that would get people up and running with sensible defaults. Alternatively (and much less effort), would be to link to your existing example (and others) from README.md |
@samzhao I am not sure why I took issue with sync ajax. I went ahead and disabled async and got it working, and that's really what matters. I'm not sure that I am forfeiting any feature by disabling the async. I am using yadda with the mocha plugin, so it feels a bit handicapped in spirit to not have async tests, but honestly, I'm just happy to have it working. |
@semblant I'm pretty sure it won't affect your tests at all given that
|
It is possible to get the feature file list from karma, so there is not need to use a REST like interface. I don't remember how to do that, but I remember I did it maybe a year ago. It requires a karma start file or a reporter or something like that. It is different from the karma config file. There is another way to start karma if you don't want use the
Maybe this could be used instead of a reporter. update: I found this mysterious start file. It is used by require.js https://karma-runner.github.io/0.8/plus/RequireJS.html, and it looks something like this: var tests = [];
for (var file in window.__karma__.files) {
if (window.__karma__.files.hasOwnProperty(file)) {
if (/Spec\.js$/.test(file)) {
tests.push(file);
}
}
}
requirejs.config({
// Karma serves files from '/base'
baseUrl: '/base/src',
paths: {
'jquery': '../lib/jquery',
'underscore': '../lib/underscore',
},
shim: {
'underscore': {
exports: '_'
}
},
// ask Require.js to load these files (all our tests)
deps: tests,
// start test run, once Require.js is done
callback: window.__karma__.start
}); By iterating through the files it is possible to create a list of .feature files. I am not sure where this update: Another way could be to optimize this is parsing gherkin with nodejs, serialize the results and use it in the browser to run the tests. So we would have only a single .json file instead of a bunch of .feature files. I am not sure whether this is possible with yadda. If we stick with multiple gets, maybe it would be better to use https://github.com/mafintosh/level-filesystem instead of jquery, which is the browserified implementation of fs. I am not sure how exactly it works. |
@Inf3rno hey, thanks for the information! I agree with you that getting the feature files using AJAX probably isn't the proper way, and it isn't elegant. I think the problem was we couldn't directly get the step files because they were being loaded by Webpack (honestly I don't remember why I needed to do that...). That was why we needed the AJAX requests in the first place — to work around the So if you don't need to share any of your app code with your tests, and you don't need to use Webpack loaders on your test files, then you don't need to go through any of these hoops. I think the most common reason to use Webpack is to use ES6 in step files, in which case this example code can help. |
@samzhao I am using browserify. I think I experience the same cannot resolve fs problem, at least |
I checked yadda. By browserify the problem that we don't have shim for browser fs https://github.com/acuminous/yadda/blob/master/lib/shims/index.js#L46 and fs from browserify does not support sync methods: https://github.com/mafintosh/level-filesystem In theory it would work by an async file search, so we would not need to use jquery. I'll try to implement something like this. I don't know if this helps by webpack users. |
@samzhao I modified the lib this way: #58 (comment) Try it out, I think it works with webpack as well. It uses sync XHR and karma file list to implement a browser fs shim yadda can use. I tried out with browserify, it worked. Maybe others develop it further and integrate it into the lib. |
wow, awesome job! It looks like it's gonna work. |
@samzhao I don't fully understand yet how to integrate properly with yadda and the browserified version of the node path module. I'll might rewrite it later, so it is experimental now. If webpack does not emulate this path module somehow, it won't work, since I use |
@samzhao I created a fork with some enhancements on the code. You can try it out by putting this in the package.json: |
Think this should be OK to close thanks to @Inf3rno's efforts with karma shims. Agree? |
@cressie176 I don't think that webpack is supported yet, but this is a duplicate of #58 , so it might be closed in favor of that issue. |
Hi,
I was trying to use Yadda with Karma and Jasmine. When I use webpack to build and run the tests, I get these errors:
There's no usage of CasperJS or PhantomJS or Mocha, and the test is exactly the same as the jasmine example found in here.
And here's my karma.conf.js
karma.webpack.config.js
And because webpack requires the files to have a context, so
client/tests/all.js
looks like this:It tries to find
*.test.js
inside of the./unit
directory, which is the entry point for Yadda:bottles.test.js
After googling about the
fs not found
problem, I learned that I can get rid of the error messages by settingBut that causes another problem because I think Yadda's
FileSearch.js
is trying to usefs.existsSync
which will not be found becausefs
becomes undefined.Sorry if this is a really special case, but it would be awesome if you guys could help find out the cause of the problem. Thanks very much!
The text was updated successfully, but these errors were encountered: