diff --git a/RoboFile.php b/RoboFile.php index cd8c32f797..0c821875e1 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -83,7 +83,7 @@ class RoboFile extends \Robo\Tasks { $this->_exec(join(' ', array( './node_modules/mocha/bin/mocha', '-r tests/javascript/mochaTestHelper.js', - 'tests/javascript/newsletter_editor/testBundle.js' + 'tests/javascript/testBundles/**/*.js' ))); } diff --git a/package.json b/package.json index 57566ab24e..dbfdf6ede9 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "chai": "2.2.0", "chai-jq": "0.0.8", "grunt": "^0.4.5", + "jquery": "2.1.4", "jsdom": "3.1.2", "mocha": "2.2.1", "napa": "^1.2.0", diff --git a/tests/javascript/mochaTestHelper.js b/tests/javascript/mochaTestHelper.js index 7b034051c3..c6248a8b4e 100644 --- a/tests/javascript/mochaTestHelper.js +++ b/tests/javascript/mochaTestHelper.js @@ -26,3 +26,5 @@ if (!global.document || !global.window) { return this.compareDocumentPosition(node) & 16; }; } + +global.$ = global.jQuery = global.window.jQuery = require('../../node_modules/jquery/dist/jquery.js'); diff --git a/tests/javascript/newsletter_editor/testAjax.js b/tests/javascript/newsletter_editor/testAjax.js new file mode 100644 index 0000000000..c537f0d5f0 --- /dev/null +++ b/tests/javascript/newsletter_editor/testAjax.js @@ -0,0 +1,7 @@ +define('testAjax', [ 'mailpoet', 'ajax'], function(MailPoet) { + describe('Ajax submodule', function() { + it('has a version', function() { + expect(MailPoet.Ajax.version).to.be.a('number'); + }); + }); +}); diff --git a/webpack.config.js b/webpack.config.js index da9484949a..7794263d65 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,8 +1,10 @@ var path = require('path'), - fs = require('fs'); + fs = require('fs'), + _ = require('underscore'), + baseConfig; -// webpack.config.js -module.exports = { +baseConfig = { + name: 'main', context: __dirname , entry: { admin: './assets/js/admin.js', @@ -46,3 +48,30 @@ module.exports = { 'jquery': 'jQuery', } }; + +module.exports = [ + baseConfig, + + // Configuration specific for testing + _.extend({}, baseConfig, { + name: 'test', + entry: { + testAjax: 'testAjax.js', + }, + output: { + path: './tests/javascript/testBundles', + filename: '[name].js', + }, + resolve: { + modulesDirectories: [ + 'node_modules', + 'assets/js', + 'tests/javascript/newsletter_editor' + ], + fallback: path.join(__dirname, 'node_modules'), + alias: { + 'handlebars': 'handlebars/runtime.js' + } + }, + }) +];