jeffling / wallaby-webpack

webpack preprocessor for wallabyjs
25 stars 8 forks source link

Webpack target: 'node' #22

Closed timcosta closed 7 years ago

timcosta commented 7 years ago

Currently this cannot be used when webpack has target: 'node' and wallaby's env type is set to node. I get errors about window being undefined.

ArtemGovorov commented 7 years ago

Hi,

this is by design, neither wallaby-webpack nor webpack is not required when running node tests, wallaby supports node environment.

okonet commented 7 years ago

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).

ArtemGovorov commented 7 years ago

@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.

vladistan commented 4 years ago

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

smcenlly commented 4 years ago

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);
    }
  }
...