ソースを参照

Bootstrap tests asynchronously

Danilo Bargen 6 年 前
コミット
52a8edca3c
14 ファイル変更633 行追加1146 行削除
  1. 2 2
      README.md
  2. 26 5
      karma.conf.js
  3. 501 1120
      package-lock.json
  4. 1 1
      package.json
  5. 0 3
      src/app.ts
  6. 4 1
      src/bootstrap.ts
  7. 25 0
      tests/bootstrap.ts
  8. 0 4
      tests/filters.js
  9. 5 0
      tests/init.js
  10. 6 3
      tests/testsuite.html
  11. 25 0
      tests/ts/bootstrap.ts
  12. 25 0
      tests/ui/bootstrap.ts
  13. 1 0
      webpack.common.js
  14. 12 7
      webpack.tests.js

+ 2 - 2
README.md

@@ -82,8 +82,8 @@ Web on a server, please follow the instructions at
 
 To run unit tests:
 
-    npm run build:unittests
-    firefox tests/testsuite.html
+    npm run build:unittests && npm run testserver
+    firefox http://localhost:7777/tests/testsuite.html
 
 To run UI tests:
 

+ 26 - 5
karma.conf.js

@@ -2,16 +2,33 @@ module.exports = function(config) {
 
     var configuration = {
         frameworks: ['jasmine'],
+        mime: {
+            'application/wasm': ['wasm'],
+        },
         files: [
+            // Angular core
             'node_modules/angular/angular.js',
-            'node_modules/angular-mocks/angular-mocks.js',
-            'node_modules/angular-translate/dist/angular-translate.min.js',
             'node_modules/angular-aria/angular-aria.min.js',
             'node_modules/angular-animate/angular-animate.min.js',
+            'node_modules/angular-sanitize/angular-sanitize.min.js',
+            'node_modules/angular-route/angular-route.min.js',
             'node_modules/angular-material/angular-material.min.js',
+            'node_modules/angular-translate/dist/angular-translate.min.js',
+
+            // Angular mocking
+            'node_modules/angular-mocks/angular-mocks.js',
+
+            // SaltyRTC
             'node_modules/@saltyrtc/chunked-dc/dist/chunked-dc.es5.js',
-            'dist/app.bundle.js',
-            'dist/unittests.bundle.js',
+
+            // App bundles
+            'dist/generated/app_noinit.bundle.js',
+            'dist/generated/unittest_karma.bundle.js',
+            {pattern: 'dist/generated/[0-9].*.bundle.js', included: false, serve: true},
+            {pattern: 'dist/generated/*.module.wasm', included: false, serve: true, type: 'wasm'},
+
+            // Tests
+            'tests/init.js',
             'tests/filters.js',
             'tests/service/message.js',
             'tests/service/mime.js',
@@ -23,8 +40,12 @@ module.exports = function(config) {
             'tests/service/keystore.js',
             'tests/service/notification.js',
             'tests/service/receiver.js',
-            'tests/ts/helpers.ts',
         ],
+        proxies: {
+            // Also serve all generated files on the root.
+            // This is required for the .wasm modules.
+            '/dist/generated/': '/base/dist/generated/',
+        },
         customLaunchers: {
             Chromium_ci_gitlab: {
                 base: 'Chromium',

ファイルの差分が大きいため隠しています
+ 501 - 1120
package-lock.json


+ 1 - 1
package.json

@@ -91,7 +91,7 @@
     "geckodriver": "^1.14.1",
     "jasmine": "^3.3.1",
     "jasmine-core": "^3.3.0",
-    "karma": "^3.1.4",
+    "karma": "^4.1.0",
     "karma-chrome-launcher": "^2.2.0",
     "karma-firefox-launcher": "^1.1.0",
     "karma-jasmine": "^2.0.1",

+ 0 - 3
src/app.ts

@@ -175,6 +175,3 @@ angular.module('3ema', [
 ])
 
 ;
-
-// Bootstrap application
-angular.bootstrap(document, ['3ema']);

+ 4 - 1
src/bootstrap.ts

@@ -21,5 +21,8 @@
 
 // A dependency graph that contains any wasm must all be imported asynchronously.
 import('./app')
-    .then(() => console.info('Application bootstrapped'))
+    .then(() => {
+        console.info('Bundle loaded, bootstrapping application.');
+        angular.bootstrap(document, ['3ema']);
+    })
     .catch((e) => console.error('Could not bootstrap application', e));

+ 25 - 0
tests/bootstrap.ts

@@ -0,0 +1,25 @@
+/**
+ * Copyright © 2016-2019 Threema GmbH (https://threema.ch/).
+ *
+ * This file is part of Threema Web.
+ *
+ * Threema Web is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Threema Web. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// tslint:disable:no-console
+
+// A dependency graph that contains any wasm must all be imported asynchronously.
+import('../src/app')
+    .then(() => console.info('Bundle loaded'))
+    .catch((e) => console.error('Could not load bundle', e));

+ 0 - 4
tests/filters.js

@@ -1,7 +1,3 @@
-afterEach(function () {
-    jasmine.clock().uninstall();
-});
-
 describe('Filters', function() {
 
     let $filter;

+ 5 - 0
tests/init.js

@@ -0,0 +1,5 @@
+// Wait for main application to be fully loaded
+beforeAll((done) => setTimeout(done, 1000));
+
+// Uninstall the mock clock after every test
+afterEach(() => jasmine.clock().uninstall());

+ 6 - 3
tests/testsuite.html

@@ -20,9 +20,12 @@
 
         <script src="../node_modules/@saltyrtc/chunked-dc/dist/chunked-dc.es5.js"></script>
 
-        <script src="../dist/app.bundle.js"></script>
-        <script src="../dist/unittests.bundle.js"></script>
+        <!-- App bundles -->
+        <script src="../dist/generated/app_noinit.bundle.js"></script>
+        <script src="../dist/generated/unittest.bundle.js"></script>
 
+        <!-- Tests -->
+        <script src="init.js"></script>
         <script src="filters.js"></script>
         <script src="service/message.js"></script>
         <script src="service/mime.js"></script>
@@ -33,7 +36,7 @@
         <script src="service/browser.js"></script>
         <script src="service/keystore.js"></script>
         <script src="service/notification.js"></script>
-        <script src="helpers.js"></script>
+        <script src="service/receiver.js"></script>
     </head>
     <body>
     <script>

+ 25 - 0
tests/ts/bootstrap.ts

@@ -0,0 +1,25 @@
+/**
+ * Copyright © 2016-2019 Threema GmbH (https://threema.ch/).
+ *
+ * This file is part of Threema Web.
+ *
+ * Threema Web is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Threema Web. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// tslint:disable:no-console
+
+// A dependency graph that contains any wasm must all be imported asynchronously.
+import('./main')
+    .then(() => console.info('Tests bootstrapped'))
+    .catch((e) => console.error('Could not bootstrap tests', e));

+ 25 - 0
tests/ui/bootstrap.ts

@@ -0,0 +1,25 @@
+/**
+ * Copyright © 2016-2019 Threema GmbH (https://threema.ch/).
+ *
+ * This file is part of Threema Web.
+ *
+ * Threema Web is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Threema Web. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// tslint:disable:no-console
+
+// A dependency graph that contains any wasm must all be imported asynchronously.
+import('./main')
+    .then(() => console.info('Tests bootstrapped'))
+    .catch((e) => console.error('Could not bootstrap tests', e));

+ 1 - 0
webpack.common.js

@@ -56,5 +56,6 @@ module.exports = {
   output: {
     path: path.resolve(__dirname, 'dist', 'generated'),
     filename: '[name].bundle.js',
+    chunkFilename: '[name].[chunkhash].bundle.js',
   },
 };

+ 12 - 7
webpack.tests.js

@@ -2,11 +2,16 @@ const dev = require('./webpack.dev.js');
 const merge = require('webpack-merge');
 
 module.exports = merge(dev, {
-    entry: {
-        unittest: './tests/ts/main.ts',
-        uitest: './tests/ui/main.ts',
-    },
-    devServer: {
-        port: 7777,
-    },
+  entry: {
+    unittest: './tests/ts/bootstrap.ts',
+    uitest: './tests/ui/bootstrap.ts',
+    app_noinit: './tests/bootstrap.ts',
+    unittest_karma: './tests/ts/main.ts',
+  },
+  devServer: {
+    port: 7777,
+  },
+  output: {
+    publicPath: '/dist/generated/',
+  },
 });

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません