Last active
April 15, 2017 22:15
-
-
Save ninjapanzer/70b55f90edcb69c74e52 to your computer and use it in GitHub Desktop.
Jest Wepback Testing Preprocessor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// Adapted from https://github.com/ColCh/jest-webpack/blob/f8e02b7a51da48c55395392e61d9c03789e43911/preprocessor.js | |
// Packages these tests with deps with webpack https://github.com/ninjapanzer/Backbone-Flux-React-Webpack/tree/master/__tests__ | |
var webpack = require('webpack'); | |
var MemoryFileSystem = require('memory-fs'); | |
var fs = new MemoryFileSystem(); | |
module.exports = { | |
process: function (src, filename) { | |
var options = require('./webpack.config.test.js'); | |
options.entry = filename; | |
options.output.path = '/'; | |
options.output.filename = filename; | |
var compiler = webpack(options); | |
compiler.outputFileSystem = fs; | |
var stats = null; | |
compiler.run(function() { | |
console.log("\nwebpack compile "+ filename) | |
stats = true; | |
}); | |
while (stats === null) { | |
require('deasync').sleep(100); | |
} | |
var contentBuffer = fs.readFileSync(filename); | |
var content = contentBuffer + ''; | |
fs.unlinkSync(filename); | |
return content; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webpack = require("webpack"); | |
var path = require("path"); | |
var bower_dir = __dirname + '/bower_components'; | |
var resolveBowerPath = function(componentPath) { | |
return path.join(bower_dir, componentPath); | |
}; | |
module.exports = { | |
entry: './src/app.coffee', | |
devtool: "source-map", | |
target: 'node', | |
output: { | |
path: './build', | |
filename: 'bundle.test.js' | |
}, | |
module: { | |
noParse: [ | |
resolveBowerPath('/react/react-with-addons.js'), | |
resolveBowerPath('/flux/dist/Flux.js'), | |
resolveBowerPath('/underscore/underscore-min.js'), | |
resolveBowerPath('/jquery/jquery.min.js') | |
], | |
loaders: [ | |
{ test: /\.coffee$/, loader: "coffee-jsx-loader" } | |
//{ test: /\.coffee$/, loader: "coffee" } | |
] | |
}, | |
plugins: [ | |
new webpack.ProvidePlugin({ | |
underscore: 'underscore', | |
jquery: 'jquery', | |
Backbone: 'backbone', | |
React: 'react', | |
Flux: 'flux' | |
}) | |
], | |
resolve: { | |
alias: { | |
'jquery': resolveBowerPath('/jquery/dist/jquery.min.js'), | |
'backbone': resolveBowerPath('/backbone/backbone.js'), | |
'react': resolveBowerPath('/react/react-with-addons.js'), | |
'flux': resolveBowerPath('/flux/dist/Flux.js'), | |
'underscore': resolveBowerPath('/underscore/underscore-min.js') | |
}, | |
extensions: ["", ".web.coffee", ".web.js", ".coffee", ".js"] | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment