2
0
Эх сурвалжийг харах

Build test bundle with webpack

Senya 6 жил өмнө
parent
commit
cb4dfe37a7

+ 2 - 0
.gitignore

@@ -61,3 +61,5 @@ develop-eggs
 # Builds
 .sv?
 /vendor/
+
+tests/*tests-bundle.js

+ 1 - 0
Makefile

@@ -229,6 +229,7 @@ eslint: stamp-npm
 
 .PHONY: check
 check: eslint
+	$(NPX) webpack --config webpack.tests.config.js
 	LOG_CR_VERBOSITY=INFO $(CHROMIUM) --no-sandbox http://localhost:$(HTTPSERVE_PORT)/tests/index.html
 
 ########################################################################

+ 2 - 1
spec/chatbox.js

@@ -5,8 +5,9 @@
         "mock",
         "test-utils"
         ], factory);
-} (this, function ($, jasmine, mock, test_utils) {
+} (this, function ($, _jasmine, mock, test_utils) {
     "use strict";
+    const jasmine = _jasmine.default;
     const _ = converse.env._;
     const $iq = converse.env.$iq;
     const $msg = converse.env.$msg;

+ 2 - 1
spec/chatroom.js

@@ -1,6 +1,7 @@
 (function (root, factory) {
     define(["jasmine", "mock", "test-utils" ], factory);
-} (this, function (jasmine, mock, test_utils) {
+} (this, function (_jasmine, mock, test_utils) {
+    const jasmine = _jasmine.default;
     const _ = converse.env._,
           $pres = converse.env.$pres,
           $iq = converse.env.$iq,

+ 4 - 3
spec/controlbox.js

@@ -1,6 +1,7 @@
 (function (root, factory) {
     define(["jquery", "jasmine", "mock", "test-utils"], factory);
-} (this, function ($, jasmine, mock, test_utils) {
+} (this, function ($, _jasmine, mock, test_utils) {
+    const jasmine = _jasmine.default;
     const _ = converse.env._,
           $pres = converse.env.$pres,
           $msg = converse.env.$msg,
@@ -34,7 +35,7 @@
 
         describe("The \"Contacts\" section", function () {
 
-            it("can be used to add contact and it checks for case-sensivity", 
+            it("can be used to add contact and it checks for case-sensivity",
                 mock.initConverseWithPromises(
                     null, ['rosterGroupsFetched'], {},
                     async function (done, _converse) {
@@ -214,7 +215,7 @@
         }));
 
 
-        it("integrates with xhr_user_search_url to search for contacts", 
+        it("integrates with xhr_user_search_url to search for contacts",
             mock.initConverseWithPromises(
                 null, ['rosterGroupsFetched'],
                 { 'xhr_user_search': true,

+ 4 - 3
spec/mam.js

@@ -1,7 +1,8 @@
 (function (root, factory) {
     define(["jasmine", "mock", "test-utils"], factory);
-} (this, function (jasmine, mock, test_utils) {
+} (this, function (_jasmine, mock, test_utils) {
     "use strict";
+    const jasmine = _jasmine.default;
     const _ = converse.env._;
     const Backbone = converse.env.Backbone;
     const Strophe = converse.env.Strophe;
@@ -15,7 +16,7 @@
 
         describe("Archived Messages", function () {
 
-           it("aren't shown as duplicates by comparing their stanza-id attribute", 
+           it("aren't shown as duplicates by comparing their stanza-id attribute",
                 mock.initConverseWithPromises(
                     null, ['discoInitialized'], {},
                     async function (done, _converse) {
@@ -57,7 +58,7 @@
                 done();
             }));
 
-           it("aren't shown as duplicates by comparing their queryid attribute", 
+           it("aren't shown as duplicates by comparing their queryid attribute",
                 mock.initConverseWithPromises(
                     null, ['discoInitialized'], {},
                     async function (done, _converse) {

+ 4 - 3
spec/messages.js

@@ -5,8 +5,9 @@
         "mock",
         "test-utils"
         ], factory);
-} (this, function ($, jasmine, mock, test_utils) {
+} (this, function ($, _jasmine, mock, test_utils) {
     "use strict";
+    const jasmine = _jasmine.default;
     const { Backbone, Promise, Strophe, $iq, $msg, $pres, b64_sha1, moment, sizzle, _ } = converse.env;
     const u = converse.env.utils;
 
@@ -528,7 +529,7 @@
             const chatbox = _converse.chatboxes.get(sender_jid);
             const view = _converse.chatboxviews.get(sender_jid);
             await new Promise((resolve, reject) => view.once('messageInserted', resolve));
-                
+
             expect(chatbox).toBeDefined();
             expect(view).toBeDefined();
             // Check that the message was received and check the message parameters
@@ -1163,7 +1164,7 @@
                         'from': _converse.bare_jid+"/some-other-resource",
                         'type': 'chat'})
                     .c('body').t("A carbon message 4 minutes later")
-                    .tree()); 
+                    .tree());
             await new Promise((resolve, reject) => view.once('messageInserted', resolve));
 
             expect(chat_content.querySelectorAll('.message').length).toBe(8);

+ 1 - 1
spec/profiling.js

@@ -54,7 +54,7 @@
                 mock.initConverseWithPromises(
                     null, ['rosterGroupsFetched'], {},
                     function (done, _converse) {
-            
+
             // _converse.show_only_online_users = true;
             _converse.roster_groups = true;
             test_utils.openControlBox();

+ 4 - 3
spec/protocol.js

@@ -4,8 +4,9 @@
         "jquery",
         "mock",
         "test-utils"], factory);
-} (this, function (jasmine, $, mock, test_utils) {
+} (this, function (_jasmine, $, mock, test_utils) {
     "use strict";
+    const jasmine = _jasmine.default;
     var Strophe = converse.env.Strophe;
     var $iq = converse.env.$iq;
     var $pres = converse.env.$pres;
@@ -362,7 +363,7 @@
                 expect($contacts.hasClass('to')).toBeFalsy();
                 expect($contacts.hasClass('both')).toBeTruthy();
                 done();
-                
+
             }));
 
             it("Alternate Flow: Contact Declines Subscription Request",
@@ -472,7 +473,7 @@
                 });
                 const $header = $('a:contains("My contacts")');
                 await test_utils.waitUntil(() => $header.parent().find('li').length);
-                        
+
                 // remove the first user
                 $header.parent().find('li .remove-xmpp-contact').get(0).click();
                 expect(window.confirm).toHaveBeenCalled();

+ 2 - 2
spec/spoilers.js

@@ -119,7 +119,7 @@
             expect(view.onMessageSubmitted).toHaveBeenCalled();
             await new Promise((resolve, reject) => view.once('messageInserted', resolve));
 
-            /* Test the XML stanza 
+            /* Test the XML stanza
              *
              * <message from="dummy@localhost/resource"
              *          to="max.frankfurter@localhost"
@@ -200,7 +200,7 @@
             expect(view.onMessageSubmitted).toHaveBeenCalled();
             await new Promise((resolve, reject) => view.once('messageInserted', resolve));
 
-            /* Test the XML stanza 
+            /* Test the XML stanza
              *
              * <message from="dummy@localhost/resource"
              *          to="max.frankfurter@localhost"

+ 1 - 2
tests/index.html

@@ -12,8 +12,7 @@
     <link type="text/css" rel="stylesheet" media="screen" href="../css/website.css" />
     <link type="text/css" rel="stylesheet" media="screen" href="../css/converse.css" />
 
-    <script src="../dist/converse.js"></script>
-    <script data-main="runner" src="../node_modules/requirejs/require.js"></script>
+    <script src="tests-bundle.js"></script>
 
     <style>
         .tests-brand-heading {

+ 3 - 0
tests/jasmine.js

@@ -0,0 +1,3 @@
+import "jasmine-core/lib/jasmine-core/jasmine-html"
+import "jasmine-core/lib/jasmine-core/boot"
+export default window.jasmine

+ 2 - 2
tests/mock.js

@@ -1,5 +1,5 @@
 (function (root, factory) {
-    define("mock", [], factory);
+    define("mock", ["converse.js"], factory);
 }(this, function () {
     var _ = converse.env._;
     var Promise = converse.env.Promise;
@@ -19,7 +19,7 @@
             this.encrypt = () => Promise.resolve({
                 'type': 1,
                 'body': 'c1ph3R73X7',
-                'registrationId': '1337' 
+                'registrationId': '1337'
             });
             this.decryptPreKeyWhisperMessage = (key_and_tag) => {
                 return Promise.resolve(key_and_tag);

+ 47 - 137
tests/runner.js

@@ -1,141 +1,51 @@
-var config = {
-    baseUrl: '../',
-    paths: {
-        "console-reporter":         "tests/console-reporter",
-        "es6-promise":              "node_modules/es6-promise/dist/es6-promise.auto",
-        "jquery":                   "node_modules/jquery/dist/jquery",
-        "lodash":                   "node_modules/lodash/lodash",
-        "lodash.converter":         "3rdparty/lodash.fp",
-        "lodash.fp":                "src/lodash.fp",
-        "lodash.noconflict":        "node_modules/@converse/headless/lodash.noconflict",
-        "pluggable":                "node_modules/pluggable.js/dist/pluggable",
-        "sizzle":                   "node_modules/sizzle/dist/sizzle",
-        "underscore":               "src/underscore-shim",
-    },
-    map: {
-        // '*' means all modules will get the '*.noconflict' version
-        // as their dependency.
-        '*': {
-            'backbone': 'backbone.noconflict',
-            'lodash': 'lodash.noconflict'
-         },
-        // '*.noconflict' wants the real module
-        // If this line was not here, there would
-        // be an unresolvable cyclic dependency.
-        'backbone.noconflict': { 'backbone': 'backbone' },
-        'lodash.noconflict': { 'lodash': 'lodash' }
-    },
+import ConsoleReporter from './console-reporter'
+import mock from "./mock"
+import sinon from "sinon"
+import waitUntilPromise from "wait-until-promise"
+import pluggable from "pluggable"
+import jasmine from "jasmine"
 
-    lodashLoader: {
-        // Configuration for requirejs-tpl
-        // Use Mustache style syntax for variable interpolation
-        root: "src/templates/",
-        templateSettings: {
-            "escape": /\{\{\{([\s\S]+?)\}\}\}/g,
-            "evaluate": /\{\[([\s\S]+?)\]\}/g,
-            "interpolate": /\{\{([\s\S]+?)\}\}/g,
-            // By default, template places the values from your data in the
-            // local scope via the with statement. However, you can specify
-            // a single variable name with the variable setting. This can
-            // significantly improve the speed at which a template is able
-            // to render.
-            "variable": 'o'
-        }
-    },
+if (window.view_mode) {
+    mock.view_mode = window.view_mode;
+}
+window.sinon = sinon;
+window.waitUntilPromise = waitUntilPromise;
+window.localStorage.clear();
+window.sessionStorage.clear();
 
-    // define module dependencies for modules not using define
-    shim: {
-        'backbone.orderedlistview': { deps: ['backbone.nativeview'] },
-        'backbone.overview':        { deps: ['backbone.nativeview'] },
-        'backbone.vdomview':        { deps: ['backbone.nativeview'] },
-        'awesomplete':              { exports: 'Awesomplete'},
-        'emojione':                 { exports: 'emojione'},
-        'xss':  {
-            'init': function (xss_noconflict) {
-                return {
-                    filterXSS: window.filterXSS,
-                    filterCSS: window.filterCSS
-                }
-            }
-        }
-    }
-};
+var jasmineEnv = jasmine.getEnv();
+jasmineEnv.addReporter(new ConsoleReporter());
 
-// Extra test dependencies
-config.paths.mock = "tests/mock";
-config.paths['wait-until-promise'] = "node_modules/wait-until-promise/index";
-config.paths['test-utils'] = "tests/utils";
-config.paths.sinon = "node_modules/sinon/pkg/sinon";
-config.paths.transcripts = "converse-logs/converse-logs";
-config.paths["jasmine-core"] = "node_modules/jasmine-core/lib/jasmine-core/jasmine";
-config.paths.jasmine = "node_modules/jasmine-core/lib/jasmine-core/boot";
-config.paths["jasmine-console"] = "node_modules/jasmine-core/lib/console/console";
-config.paths["jasmine-html"] = "node_modules/jasmine-core/lib/jasmine-core/jasmine-html";
-config.shim.jasmine = {
-    exports: 'window.jasmineRequire'
-};
-config.shim['jasmine-html'] = {
-    deps: ['jasmine-core'],
-    exports: 'window.jasmineRequire'
-};
-config.shim['jasmine-console'] = {
-    deps: ['jasmine-core'],
-    exports: 'window.jasmineRequire'
-};
-config.shim.jasmine = {
-    deps: ['jasmine-core', 'jasmine-html', 'jasmine-console'],
-    exports: 'window.jasmine'
-};
-require.config(config);
-
-var specs = [
-    "jasmine",
+// Load the specs
+require([
     //"spec/transcripts",
-    "spec/spoilers",
-    "spec/profiling",
-    "spec/utils",
-    "spec/converse",
-    "spec/bookmarks",
-    "spec/roomslist",
-    "spec/headline",
-    "spec/disco",
-    "spec/protocol",
-    "spec/presence",
-    "spec/eventemitter",
-    "spec/ping",
-    "spec/push",
-    "spec/xmppstatus",
-    "spec/mam",
-    "spec/omemo",
-    "spec/controlbox",
-    "spec/roster",
-    "spec/chatbox",
-    "spec/user-details-modal",
-    "spec/messages",
-    "spec/chatroom",
-    "spec/room_registration",
-    "spec/autocomplete",
-    "spec/minchats",
-    "spec/notification",
-    "spec/login",
-    "spec/register",
-    "spec/http-file-upload"
-];
-
-require(['console-reporter', 'mock', 'sinon', 'wait-until-promise', 'pluggable'],
-        function(ConsoleReporter, mock, sinon, waitUntilPromise, pluggable) {
-
-    if (window.view_mode) {
-        mock.view_mode = window.view_mode;
-    }
-    window.sinon = sinon;
-    window.waitUntilPromise = waitUntilPromise.default;
-    window.localStorage.clear();
-    window.sessionStorage.clear();
-    // Load the specs
-    require(specs, function (jasmine) {
-        var jasmineEnv = jasmine.getEnv();
-        jasmineEnv.addReporter(new ConsoleReporter());
-        window.onload();
-    });
-});
+    "../spec/spoilers",
+    "../spec/profiling",
+    "../spec/utils",
+    "../spec/converse",
+    "../spec/bookmarks",
+    "../spec/roomslist",
+    "../spec/headline",
+    "../spec/disco",
+    "../spec/protocol",
+    "../spec/presence",
+    "../spec/eventemitter",
+    "../spec/ping",
+    "../spec/push",
+    "../spec/xmppstatus",
+    "../spec/mam",
+    "../spec/omemo",
+    "../spec/controlbox",
+    "../spec/roster",
+    "../spec/chatbox",
+    "../spec/user-details-modal",
+    "../spec/messages",
+    "../spec/chatroom",
+    "../spec/room_registration",
+    "../spec/autocomplete",
+    "../spec/minchats",
+    "../spec/notification",
+    "../spec/login",
+    "../spec/register",
+    "../spec/http-file-upload"
+]);

+ 116 - 0
webpack.tests.config.js

@@ -0,0 +1,116 @@
+/*global path, __dirname, module, process */
+'use strict'
+const minimist = require('minimist');
+const path = require('path');
+const webpack = require('webpack');
+
+const config = {
+
+    entry: path.resolve(__dirname, 'tests/runner.js'),
+    externals: [{
+        "window": "window"
+    }],
+    output: {
+        path: path.resolve(__dirname, 'tests'),
+        filename: 'tests-bundle.js'
+    },
+    devtool: 'source-map',
+    plugins: [
+        new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
+        new webpack.ProvidePlugin({
+          'jasmineRequire': path.resolve(__dirname, "node_modules/jasmine-core/lib/jasmine-core/jasmine"),
+        })
+    ],
+    module: {
+        rules: [
+        {
+            test: path.resolve(__dirname, "node_modules/backbone.overview/backbone.orderedlistview"),
+            use: 'imports-loader?backbone.nativeview'
+        },
+        {
+            test: path.resolve(__dirname, "node_modules/backbone.overview/backbone.overview"),
+            use: 'imports-loader?backbone.nativeview'
+        },
+        {
+            test: path.resolve(__dirname, "node_modules/backbone.vdomview/backbone.vdomview"),
+            use: 'imports-loader?backbone.nativeview'
+        },
+        {
+            test: path.resolve(__dirname, "node_modules/awesomplete-avoid-xss/awesomplete"),
+            use: "exports-loader?Awesomplete"
+        },
+        {
+            test: path.resolve(__dirname, "node_modules/xss/dist/xss"),
+            use: "exports-loader?filterXSS,filterCSS"
+        },
+        {
+            test: /\.(html|svg)$/,
+            exclude: /node_modules/,
+            use: [{
+                loader: 'lodash-template-webpack-loader',
+                options: {
+                    "escape": /\{\{\{([\s\S]+?)\}\}\}/g,
+                    "evaluate": /\{\[([\s\S]+?)\]\}/g,
+                    "interpolate": /\{\{([\s\S]+?)\}\}/g,
+                    // By default, template places the values from your data in the
+                    // local scope via the with statement. However, you can specify
+                    // a single variable name with the variable setting. This can
+                    // significantly improve the speed at which a template is able
+                    // to render.
+                    "variable": 'o',
+                    "prependFilenameComment": __dirname
+                }
+            }]
+        }, {
+            test: /\.js$/,
+            exclude: /(node_modules|spec|mockup)/,
+            use: {
+                loader: 'babel-loader',
+                options: {
+                    presets: [
+                        ["@babel/preset-env", {
+                            "targets": {
+                                "browsers": [">1%", "not ie 11", "not op_mini all"]
+                            }
+                        }]
+                    ]
+                }
+            }
+        }],
+    },
+    resolve: {
+        extensions: ['.js'],
+        modules: [
+            'node_modules',
+            path.resolve(__dirname, "src")
+        ],
+        alias: {
+            "IPv6":                     path.resolve(__dirname, "node_modules/urijs/src/IPv6"),
+            "SecondLevelDomains":       path.resolve(__dirname, "node_modules/urijs/src/SecondLevelDomains"),
+            "awesomplete":              path.resolve(__dirname, "node_modules/awesomplete-avoid-xss/awesomplete"),
+            "bootstrap":                path.resolve(__dirname, "node_modules/bootstrap.native/dist/bootstrap-native-v4"),
+            "formdata-polyfill":        path.resolve(__dirname, "node_modules/formdata-polyfill/FormData"),
+            "jquery":                   path.resolve(__dirname, "node_modules/jquery/dist/jquery"),
+            "pluggable":                path.resolve(__dirname, "node_modules/pluggable.js/dist/pluggable"),
+            "punycode":                 path.resolve(__dirname, "node_modules/urijs/src/punycode"),
+            "snabbdom":                 path.resolve(__dirname, "node_modules/snabbdom/dist/snabbdom"),
+            "snabbdom-attributes":      path.resolve(__dirname, "node_modules/snabbdom/dist/snabbdom-attributes"),
+            "snabbdom-class":           path.resolve(__dirname, "node_modules/snabbdom/dist/snabbdom-class"),
+            "snabbdom-dataset":         path.resolve(__dirname, "node_modules/snabbdom/dist/snabbdom-dataset"),
+            "snabbdom-eventlisteners":  path.resolve(__dirname, "node_modules/snabbdom/dist/snabbdom-eventlisteners"),
+            "snabbdom-props":           path.resolve(__dirname, "node_modules/snabbdom/dist/snabbdom-props"),
+            "snabbdom-style":           path.resolve(__dirname, "node_modules/snabbdom/dist/snabbdom-style"),
+            "tovnode":                  path.resolve(__dirname, "node_modules/snabbdom/dist/tovnode"),
+            "underscore":               path.resolve(__dirname, "src/underscore-shim"),
+            "uri":                      path.resolve(__dirname, "node_modules/urijs/src/URI"),
+            "vdom-parser":              path.resolve(__dirname, "node_modules/vdom-parser/dist"),
+            "xss":                      path.resolve(__dirname, "node_modules/xss/dist/xss"),
+
+            "mock": path.resolve(__dirname, "tests/mock"),
+            "test-utils": path.resolve(__dirname, "tests/utils"),
+            "jasmine": path.resolve(__dirname, "tests/jasmine"),
+        }
+    }
+}
+
+module.exports = config;