diff --git a/RoboFile.php b/RoboFile.php index ec7c50bd7e..8007f8f3d0 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -30,6 +30,10 @@ class RoboFile extends \Robo\Tasks { $this->_exec(join(' ', $command)); } + function bundleJavascript() { + $this->_exec('./node_modules/webpack/bin/webpack.js'); + } + function makepot() { $this->_exec('grunt makepot'. ' --gruntfile '.__DIR__.'/tasks/makepot/makepot.js'. @@ -61,6 +65,11 @@ class RoboFile extends \Robo\Tasks { $this->_exec('vendor/bin/codecept run acceptance'); } + function testJavascript() { + // TODO: regenerate test bundle before running mocha tests + $this->_exec('./node_modules/mocha/bin/mocha -r tests/javascript/mochaTestHelper.js tests/javascript/newsletter_editor/testBundle.js'); + } + function testAll() { $this->_exec('vendor/bin/codecept build'); $this->loadEnv(); diff --git a/package.json b/package.json index 562ee3b3b1..57566ab24e 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "sinon": "1.14.1", "sinon-chai": "2.7.0", "stylus": "latest", - "swag": "~0.7.0" + "swag": "~0.7.0", + "webpack": "1.11.0" } } diff --git a/tests/javascript/mochaTestHelper.js b/tests/javascript/mochaTestHelper.js new file mode 100644 index 0000000000..7b034051c3 --- /dev/null +++ b/tests/javascript/mochaTestHelper.js @@ -0,0 +1,28 @@ +var chai = require('chai'); +var sinon = require('sinon'); +var sinonChai = require('sinon-chai'); +var chaiJq = require('chai-jq'); + +chai.use(sinonChai); +chai.use(chaiJq); + +global.expect = chai.expect; +global.sinon = sinon; + +if (!global.document || !global.window) { + var jsdom = require('jsdom').jsdom; + + global.document = jsdom('
', {}, { + FetchExternalResources: ['script'], + ProcessExternalResources: ['script'], + MutationEvents: '2.0', + QuerySelector: false + }); + + global.window = document.parentWindow; + global.navigator = global.window.navigator; + + global.window.Node.prototype.contains = function (node) { + return this.compareDocumentPosition(node) & 16; + }; +} diff --git a/views/layout.html b/views/layout.html index 75ce228dd2..9b9696ef49 100644 --- a/views/layout.html +++ b/views/layout.html @@ -31,4 +31,4 @@ )%> -<% block templates %><% endblock %> \ No newline at end of file +<% block templates %><% endblock %> diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000000..5e0113db9a --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,45 @@ +var path = require('path'), + fs = require('fs'); + +// webpack.config.js +module.exports = { + context: __dirname , + entry: { + mailpoet: './assets/js/mailpoet', + }, + output: { + path: './assets/js/src', + filename: '[name].js', + }, + loaders: [ + { + test: /\.js$/i, + loader: 'js' + }, + { + test: /\.css$/i, + loader: 'css' + }, + { + test: /\.jpe?g$|\.gif$|\.png$|\.svg$|\.woff$|\.ttf$|\.wav$|\.mp3$/i, + loader: 'file' + } + ], + resolve: { + modulesDirectories: [ + 'node_modules', + 'assets/js', + 'assets/css/lib' + ], + fallback: path.join(__dirname, 'node_modules'), + alias: { + 'handlebars': 'handlebars/runtime.js' + } + }, + resolveLoader: { + fallback: path.join(__dirname, 'node_modules'), + alias: { + 'hbs': 'handlebars-loader' + } + } +};