Skip to content

Commit

Permalink
Add test support for webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
kpdecker committed Dec 28, 2016
1 parent e13f814 commit f4c2bf2
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ browserify-test/script.js
browserify-test/script.map
header-test/script.js
header-test/script.map
webpack-test/compiled.js
10 changes: 8 additions & 2 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ var path = require('path');
var querystring = require('querystring');
var child_process = require('child_process');

var browserify = path.join('node_modules', '.bin', 'browserify');
var coffee = path.join('node_modules', '.bin', 'coffee');
var browserify = path.resolve(path.join('node_modules', '.bin', 'browserify'));
var webpack = path.resolve(path.join('node_modules', '.bin', 'webpack'));
var coffee = path.resolve(path.join('node_modules', '.bin', 'coffee'));

function run(command, callback) {
console.log(command);
Expand Down Expand Up @@ -71,3 +72,8 @@ run(coffee + ' --map --compile header-test/script.coffee', function(error) {
var contents = fs.readFileSync('header-test/script.js', 'utf8');
fs.writeFileSync('header-test/script.js', contents.replace(/\/\/# sourceMappingURL=.*/g, ''))
});

// Build the webpack test
child_process.exec(webpack, {cwd: 'webpack-test'}, function(error) {
if (error) throw error;
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"browserify": "3.44.2",
"coffee-script": "1.7.1",
"http-server": "^0.8.5",
"mocha": "1.18.2"
"mocha": "1.18.2",
"webpack": "^1.13.3"
},
"repository": {
"type": "git",
Expand Down
5 changes: 5 additions & 0 deletions webpack-test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>
Make sure to run build.js.
This test should say either "Test failed" or "Test passed":
</p>
<script src="compiled.js"></script>
16 changes: 16 additions & 0 deletions webpack-test/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require('../').install();

function foo() {
throw new Error('foo');
}

try {
foo();
} catch (e) {
if (/\bscript\.js\b/.test(e.stack)) {
document.body.appendChild(document.createTextNode('Test passed'));
} else {
document.body.appendChild(document.createTextNode('Test failed'));
console.log(e.stack);
}
}
12 changes: 12 additions & 0 deletions webpack-test/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var webpack = require('webpack');

module.exports = {
entry: './script.js',
devtool: 'inline-source-map',
output: {
filename: 'compiled.js'
},
resolve: {
extensions: ['', '.js']
}
};

0 comments on commit f4c2bf2

Please sign in to comment.