Skip to content

Instantly share code, notes, and snippets.

@bohde
Last active June 5, 2018 02:57
Show Gist options
  • Save bohde/2c4e5e865a855272c13cbb72f0b7b260 to your computer and use it in GitHub Desktop.
Save bohde/2c4e5e865a855272c13cbb72f0b7b260 to your computer and use it in GitHub Desktop.
example webpack & mocha project
// a simple module
exports.add = function(a, b) {
return a + b;
};
<!doctype html>
<html>
<head>
<title>Getting Started</title>
</head>
<body>
<script src="dist/index.js"></script>
</body>
</html>
// our app entry point.
var add = require('./add').add;
function component() {
var element = document.createElement('div');
element.innerHTML = add(1, 2);
return element;
}
document.body.appendChild(component());
{
"name": "webpack-mocha-example",
"version": "1.0.0",
"description": "",
"private": true,
"dependencies": {},
"devDependencies": {
"mocha": "^5.2.0",
"webpack": "^4.10.2",
"webpack-cli": "^3.0.2"
},
"scripts": {
"build": "webpack --entry . -o dist/index.js",
"test": "mocha"
},
"author": "",
"license": "ISC"
}
#!/bin/bash
# setup
npm install
# run tests
npm test
# build and view in browser
npm run build && browse index.html
// a simple test of our module
var assert = require('assert'),
add = require('./add').add;
describe('add', function() {
it('1 + 1 = 2', function() {
assert.equal(add(1, 1), 2);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment