diff --git a/lib/binary_parser.js b/lib/binary_parser.js index 12ece7ee..8058b27b 100644 --- a/lib/binary_parser.js +++ b/lib/binary_parser.js @@ -5,6 +5,9 @@ var vm = require("vm"); var Context = require("./context").Context; +if (typeof window !== 'undefined') + window.Buffer = Buffer + var PRIMITIVE_TYPES = { UInt8: 1, UInt16LE: 2, diff --git a/package.json b/package.json index be2f6595..473c08aa 100644 --- a/package.json +++ b/package.json @@ -6,13 +6,17 @@ "devDependencies": { "istanbul": "^0.4.5", "mocha": "^3.5.3", - "prettier": "^1.9.2" + "opn-cli": "^3.1.0", + "prettier": "^1.9.2", + "webpack": "^4.6.0", + "webpack-cli": "^2.0.15" }, "scripts": { "fmt": "npx prettier --write '{lib,test,example}/**/*.js'", "check-fmt": "npx prettier --list-different '{lib,test,example}/**/*.js'", "test": "npx mocha --reporter spec", - "cover": "npx istanbul cover --report html node_modules/.bin/_mocha" + "cover": "npx istanbul cover --report html node_modules/.bin/_mocha", + "test-webpack": "npx webpack --config test/browser/webpack.config.js && opn test/browser/run-mocha.html" }, "keywords": [ "binary", @@ -36,6 +40,6 @@ "bugs": "http://github.com/keichi/binary-parser/issues", "dependencies": {}, "engines": { - "node": ">=5.10.0" + "node": ">=5.10.0" } } diff --git a/test/browser/.gitignore b/test/browser/.gitignore new file mode 100644 index 00000000..1f939ef8 --- /dev/null +++ b/test/browser/.gitignore @@ -0,0 +1 @@ +bundle.js* diff --git a/test/browser/entry.js b/test/browser/entry.js new file mode 100644 index 00000000..048ac3a8 --- /dev/null +++ b/test/browser/entry.js @@ -0,0 +1,2 @@ +require('../primitive_parser') +require('../composite_parser') diff --git a/test/browser/run-mocha.html b/test/browser/run-mocha.html new file mode 100644 index 00000000..58cd5927 --- /dev/null +++ b/test/browser/run-mocha.html @@ -0,0 +1,18 @@ + + + + Mocha Tests + + + +
+ + + + + + diff --git a/test/browser/webpack.config.js b/test/browser/webpack.config.js new file mode 100644 index 00000000..f0b5e43c --- /dev/null +++ b/test/browser/webpack.config.js @@ -0,0 +1,10 @@ +const path = require('path') + +module.exports = { + entry: path.resolve(__dirname, 'entry.js'), + output: { + path: __dirname, + filename: 'bundle.js', + }, + mode: 'development', +}