Closed timcosta closed 7 years ago
Hi,
this is by design, neither wallaby-webpack nor webpack is not required when running node tests, wallaby supports node environment.
I guess sometimes it's hard to get rid of webpack (aliases, shims etc. are just a few things that some in mind that wouldn't work without webpack).
@okonet I see what what you mean, yet more and more wallaby (and not only, for example jest
) users I see are selecting pure node test environment for their webpack bundled apps. One may just configure few things like create-react-app/jest config is doing.
aliases, shims
Various hooks/extension stubs work ok: https://github.com/wallabyjs/public/issues/1006#issue-206576112. NODE_PATH hints nicely work for resolve aliases.
Having said that, I do understand that it may be hard to make an app that uses a lot of webpack specific stuff to work in node.
Is there any way to reconsider this by-design decision. In my serverless app I need to load a bunch of .CSV file, and webpack csv-loader fits the bill perfectly. Unfortunately I can't test the app with Wallaby
In your case, you should be able to use the Wallaby setup function and override how csv files are loaded to match how the webpack csv-loader works:
Wallaby.js configuration file
...
setup: function (wallaby) {
const Papa = require('papaparse');
require.extensions['.csv'] = function (module, filename) {
const content = fs.readFileSync(filename, 'utf8');
const processedContent = Papa.parse(content, {});
module._compile('module.exports = ' + JSON.stringify(parsed.data), filename);
}
}
...
Currently this cannot be used when webpack has
target: 'node'
and wallaby'senv
type is set tonode
. I get errors aboutwindow
being undefined.