Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wallaby-webpack

Package Overview
Dependencies
Maintainers
2
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wallaby-webpack - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

56

index.js

@@ -5,2 +5,3 @@ 'use strict';

var _ = require('lodash');
var mm = require('minimatch');
var WallabyInputFileSystem = require('./lib/WallabyInputFileSystem');

@@ -35,2 +36,10 @@

this._opts = opts || {};
this._entryPatterns = this._opts.entryPatterns;
delete this._opts.entryPatterns;
if (this._entryPatterns && _.isString(this._entryPatterns)) {
this._entryPatterns = [this._entryPatterns];
}
this._compilationCache = {};

@@ -41,2 +50,3 @@ this._compilationFileTimestamps = {};

this._allTrackedFiles = {};
this._entryFiles = {};
this._inputFileSystem = new WallabyInputFileSystem(this);

@@ -72,6 +82,16 @@ }

affectedFiles = self._allTrackedFiles = WebpackPostprocessor._fileArrayToObject(wallaby.allFiles);
self._entryFiles = _.reduce(!self._entryPatterns
? wallaby.allTestFiles
: _.filter(self._allTrackedFiles, file => _.find(self._entryPatterns, pattern => mm(file.path, pattern))),
function (memo, file) {
memo[file.fullPath] = file;
return memo;
}, {});
self._compiler = self._createCompiler({
cache: false, // wallaby post processor is using its own cache
entry: _.reduce(wallaby.allTestFiles, (memo, testFile) => {
memo[testFile.fullPath] = testFile.fullPath;
entry: _.reduce(self._entryFiles, (memo, entryFile) => {
memo[entryFile.fullPath] = entryFile.fullPath;
return memo;

@@ -83,3 +103,2 @@ }, {}),

affectedFiles = self._allTrackedFiles = WebpackPostprocessor._fileArrayToObject(wallaby.allFiles);
self._affectedModules = [];

@@ -120,5 +139,6 @@ self._moduleIds = {};

var createFilePromises = [];
var trackedFileIds = {};
_.each(self._affectedModules, function (m) {
var trackedFile = m.resource && affectedFiles[m.resource];
var isEntryFile = trackedFile && self._entryPatterns && self._entryFiles[trackedFile.fullPath];
var source = self._getSource(m);

@@ -139,3 +159,4 @@ var code = source.code;

sourceMap: sourceMap,
ts: !trackedFile ? 1 : undefined // caching non tracked files in browser/phantomjs until wallaby restarts
ts: !trackedFile ? 1 : undefined, // caching non tracked files in browser/phantomjs until wallaby restarts
order: isEntryFile ? trackedFile.order : undefined
}));

@@ -156,2 +177,6 @@

}
if (trackedFile) {
trackedFileIds[trackedFile.fullPath] = moduleId;
}
});

@@ -172,2 +197,12 @@

}));
// Executing all entry files
if (self._entryPatterns && self._entryFiles && !_.isEmpty(self._entryFiles)) {
createFilePromises.push(wallaby.createFile({
order: Infinity,
path: 'wallaby_webpack_entry.js',
content: _.reduce(_.values(self._entryFiles),
(memo, file) => memo + (file.test ? '' : 'window.__moduleBundler.require(' + JSON.stringify(trackedFileIds[file.fullPath]) + ');'), '')
}));
}
}

@@ -255,7 +290,12 @@

static _getLoaderContent() {
// webpack prelude (taken from browserify, slightly modified to include webpack specific module.id and module.loaded)
var prelude = '(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module \'"+o+"\'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{},id:o,loaded:false};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r);l.loaded=true}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})';
return 'window.__moduleBundler = {};'
+ 'window.__moduleBundler.cache = {};'
+ 'window.__moduleBundler.require = function (m) {'
+ prelude
+ '(window.__moduleBundler.cache, {}, [m]);'
+ '};'
+ 'window.__moduleBundler.loadTests = function () {'
// webpack prelude (taken from browserify, slightly modified to include webpack specific module.id and module.loaded)
+ '(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module \'"+o+"\'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{},id:o,loaded:false};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r);l.loaded=true}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})'
+ prelude
// passing accumulated files and entry points (webpack-ed tests for the current sandbox)

@@ -268,2 +308,2 @@ + '(window.__moduleBundler.cache, {}, (function(){ var testIds = []; for(var i = 0, len = wallaby.loadedTests.length; i < len; i++) { var test = wallaby.loadedTests[i]; if (test.substr(-7) === ".wbp.js") testIds.push(wallaby.baseDir + test.substr(0, test.length - 7)); } return testIds; })()); };'

return new WebpackPostprocessor(opts).createPostprocessor();
};
};

9

package.json
{
"name": "wallaby-webpack",
"version": "0.0.5",
"version": "0.0.6",
"description": "Webpack postprocessor for wallaby.js",

@@ -9,2 +9,6 @@ "main": "index.js",

},
"repository": {
"type": "git",
"url": "git+https://github.com/jeffling/wallaby-webpack.git"
},
"author": "Jeff Ling <jeff@bench.co>",

@@ -14,3 +18,4 @@ "license": "ISC",

"graceful-fs": "^3.0.6",
"lodash": "^3.5.0"
"lodash": "^3.5.0",
"minimatch": "2.0.1"
},

@@ -17,0 +22,0 @@ "devDependencies": {

@@ -57,2 +57,12 @@ # wallaby-webpack

You may also consider re-using your existing webpack config by requiring it in wallaby config and adjusting the way you need.
``` javascript
var webpackConfig = require('./webpack.config');
// Adjust the config as required
// webpackConfig.plugins.push(...);
var wallabyPostprocessor = wallabyWebpack(webpackConfig);
```
## Notes

@@ -67,5 +77,13 @@

it to disk) and serves each requested module file separately to properly leverage browser caching.
#### Source maps and `devtool` option
Please note, that some webpack loaders, such as `babel-loader` require you to use `devtool` option in order to generate a source map, that is required in wallaby.js for the correct error stack mappings. Wallaby supported `devtool` values are: `source-map`, `hidden-source-map`, `cheap-module-source-map`.
For your tests you don't have to use the module bundler loaders and where possible may use [wallaby.js preprocessors](https://github.com/wallabyjs/public#preprocessors-setting) instead. For example, if you are using ES6, instead of using `babel-loader` in the webpack configuration, you may specify wallaby.js preprocessor(s):
**For better performance, consider not using webpack loaders in wallaby configuration, specifically those that require `devtool` and source maps, and use wallaby.js preprocessors or compilers instead as described below.**
#### Loaders vs preprocessors/compilers
For your tests you don't have to use the module bundler loaders and where possible may use wallaby.js [preprocessors](https://github.com/wallabyjs/public#preprocessors-setting) or []([compiler](https://github.com/wallabyjs/public#compilers-setting)) instead.
For example, if you are using ES6/JSX, instead of using `babel-loader` in the webpack configuration, you may specify wallaby.js preprocessor:
``` javascript

@@ -86,2 +104,32 @@ files: [

```
or a compiler (recommended in case if you are using or planning to use ES7 features, with [proper `stage` value](https://babeljs.io/docs/usage/experimental/) passed to the compiler options):
``` javascript
files: [
{pattern: 'src/*.js', load: false}
],
tests: [
{pattern: 'test/*Spec.js', load: false}
],
compilers: {
'**/*.js': wallaby.compilers.babel({ babel: require('babel') /* , stage: 0 */ }),
}
postprocessor: wallabyPostprocessor
```
In this case, don't forget to remove `devtool` and not used loaders if you are using external webpack config as wallaby webpack config, for example:
``` javascript
var webpackConfig = require('./webpack.config');
// removing babel-loader, we will use babel compiler instead, it's more performant
webpackConfig.module.loaders = webpackConfig.module.loaders.filter(function(l){
return l.loader !== 'babel-loader';
});
delete webpackConfig.devtool;
var wallabyPostprocessor = wallabyWebpack(webpackConfig);
```
### Files and tests

@@ -94,1 +142,24 @@ All source files and tests (except external files/libs) must have `load: false` set, because wallaby will load wrapped versions of these files on `window.__moduleBundler.loadTests()` call in `bootstrap` function. Node modules should not be listed in the `files` list, they are loaded automatically.

the code immediately. Instead, it just adds some function, that executes the file code, to test loader's cache. Tests and dependent files are loaded from wallaby `bootstrap` function, by calling `__moduleBundler.loadTests()`, and then executed.
### Module resolution issues
If you are observing `ModuleNotFoundError`, required module folders are referenced in a relative manner and didn't make it into the wallaby file cache, that wallaby is using to run your tests.
For example, if you are using `bower_components` and may have something like this in you config:
```javascript
resolve: {
modulesDirectories: ['bower_components']
}
```
In this case, even though I would not recommend it, you may to add `{ pattern: 'bower_components/**/*.*', instrument: false, load: false }` to your files list, so that `bower_components` contents makes it into the wallaby cache and wallaby will be able to resolve modules from it.
The **more efficient approach** that I would recommend is to specify an absolute path in your wallaby configuration for webpack for **your external modules (not your source files)** instead:
```javascript
resolve: {
modulesDirectories: [require('path').join(__dirname, 'bower_components')]
}
```
This way you don't need to specify `bower_components` in your files list and wallaby will not have to copy it over to its cache.
The same applies to `resolve.fallback`, `resolve.root` and `resolveLoader` webpack configuration settings.
**Please note that you don't need to do a similar thing for `node_modules`, as wallaby-webapck automatically adds local project `node_modules` folder to the the fallback list**. Unlike `node_modules`, `bower_components` and any other custom module folders can be used with different names/paths, so wallaby doesn't try to automatically add them based on the name convention. Also, you should not use the approach for your source files, because they need to be instrumented and served from the wallaby cache, not from the local project folder.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc