Browse Source

Add the ability to run tests via the webpack devserver

JC Brand 5 years ago
parent
commit
7eb6a17fd2
6 changed files with 60 additions and 16 deletions
  1. 0 1
      src/headless/converse-core.js
  2. 33 0
      tests.html
  3. 1 0
      tests/index.html
  4. 0 3
      tests/mock.js
  5. 21 12
      tests/runner.js
  6. 5 0
      webpack.serve.js

+ 0 - 1
src/headless/converse-core.js

@@ -28,7 +28,6 @@ const $iq = strophe.default.$iq;
 const $msg = strophe.default.$msg;
 const $pres = strophe.default.$pres;
 
-
 dayjs.extend(advancedFormat);
 
 // Add Strophe Namespaces

+ 33 - 0
tests.html

@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <title>Converse.js</title>
+    <meta charset="utf-8">
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+    <meta name="description" content="Converse.js: A free chat client for your website" />
+    <script src="3rdparty/libsignal-protocol.js"></script>
+    <link rel="manifest" href="./manifest.json">
+    <link rel="shortcut icon" type="image/ico" href="favicon.ico"/>
+    <link rel="shortcut icon" type="image/png" href="node_modules/jasmine-core/images/jasmine_favicon.png">
+    <link rel="stylesheet" type="text/css" media="screen" href="node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
+    <script data-main="tests/runner" src="../node_modules/requirejs/require.js"></script>
+    <style>
+        .tests-brand-heading {
+            margin-top: 1em;
+            font-size: 200%;
+        }
+    </style>
+</head>
+<body class="reset"></body>
+    <div id="header_wrap" class="outer">
+        <header class="inner">
+          <h1 class="brand-heading tests-brand-heading">
+              <i class="icon-conversejs"></i> Converse</h1>
+          <h2 id="project_tagline">Tests</h2>
+        </header>
+    </div>
+    <script>
+        converse.load();
+    </script>
+</html>

+ 1 - 0
tests/index.html

@@ -25,5 +25,6 @@
           <h2 id="project_tagline">Tests</h2>
         </header>
     </div>
+    <script>converse.load();</script>
 </body>
 </html>

+ 0 - 3
tests/mock.js

@@ -1,9 +1,6 @@
 (function (root, factory) {
     define("mock", [], factory);
 }(this, function () {
-
-    converse.load();
-
     const _ = converse.env._;
     const u = converse.env.utils;
     const Promise = converse.env.Promise;

+ 21 - 12
tests/runner.js

@@ -70,16 +70,25 @@ var specs = [
     "spec/xss"
 ];
 
-require(['console-reporter', 'mock', 'sinon'], (ConsoleReporter, mock, sinon) => {
-    if (window.view_mode) {
-        mock.view_mode = window.view_mode;
-    }
-    window.sinon = sinon;
-    // Load the specs
-    require(specs, jasmine => {
-        jasmine.DEFAULT_TIMEOUT_INTERVAL = 7000;
-        const jasmineEnv = jasmine.getEnv();
-        jasmineEnv.addReporter(new ConsoleReporter());
-        window.onload();
+
+function load () {
+    require(['console-reporter', 'mock', 'sinon'], (ConsoleReporter, mock, sinon) => {
+        if (window.view_mode) {
+            mock.view_mode = window.view_mode;
+        }
+        window.sinon = sinon;
+        // Load the specs
+        require(specs, jasmine => {
+            jasmine.DEFAULT_TIMEOUT_INTERVAL = 7000;
+            const jasmineEnv = jasmine.getEnv();
+            jasmineEnv.addReporter(new ConsoleReporter());
+            window.onload();
+        });
     });
-});
+}
+
+if (window.converse) {
+    load();
+} else {
+    window.addEventListener('converse-loaded', load);
+}

+ 5 - 0
webpack.serve.js

@@ -13,6 +13,11 @@ module.exports = merge(common, {
         new HTMLWebpackPlugin({
             title: 'Converse.js Dev',
             template: 'webpack.html'
+        }),
+        new HTMLWebpackPlugin({
+            filename: 'tests.html',
+            title: 'Converse.js Tests',
+            template: 'tests.html'
         })
     ],
 });