Jelajahi Sumber

Add support for tests written in TypeScript (#489)

Danilo Bargen 7 tahun lalu
induk
melakukan
46dbbe3ad6
5 mengubah file dengan 72 tambahan dan 1 penghapusan
  1. 1 0
      karma.conf.js
  2. 38 0
      package-lock.json
  3. 4 1
      package.json
  4. 1 0
      tests/testsuite.html
  5. 28 0
      tests/ts/main.ts

+ 1 - 0
karma.conf.js

@@ -10,6 +10,7 @@ module.exports = function(config) {
             'node_modules/angular-animate/angular-animate.min.js',
             'node_modules/angular-material/angular-material.min.js',
             'dist/app.js',
+            'dist/ts-tests.js',
             'tests/filters.js',
             'tests/service/message.js',
             'tests/service/mime.js',

+ 38 - 0
package-lock.json

@@ -64,6 +64,12 @@
       "resolved": "https://registry.npmjs.org/@types/filesaver/-/filesaver-0.0.30.tgz",
       "integrity": "sha1-cUiW9WpI9ki/DFAnPHcaNfNYACc="
     },
+    "@types/jasmine": {
+      "version": "2.8.6",
+      "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-2.8.6.tgz",
+      "integrity": "sha512-clg9raJTY0EOo5pVZKX3ZlMjlYzVU73L71q5OV1jhE2Uezb7oF94jh4CvwrW6wInquQAdhOxJz5VDF2TLUGmmA==",
+      "dev": true
+    },
     "@types/jquery": {
       "version": "2.0.48",
       "resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-2.0.48.tgz",
@@ -4084,6 +4090,38 @@
       "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
       "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
     },
+    "jasmine": {
+      "version": "3.1.0",
+      "resolved": "https://registry.npmjs.org/jasmine/-/jasmine-3.1.0.tgz",
+      "integrity": "sha1-K9Wf1+xuwOistk4J9Fpo7SrRlSo=",
+      "dev": true,
+      "requires": {
+        "glob": "7.1.2",
+        "jasmine-core": "3.1.0"
+      },
+      "dependencies": {
+        "glob": {
+          "version": "7.1.2",
+          "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
+          "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
+          "dev": true,
+          "requires": {
+            "fs.realpath": "1.0.0",
+            "inflight": "1.0.6",
+            "inherits": "2.0.3",
+            "minimatch": "3.0.4",
+            "once": "1.4.0",
+            "path-is-absolute": "1.0.1"
+          }
+        },
+        "jasmine-core": {
+          "version": "3.1.0",
+          "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-3.1.0.tgz",
+          "integrity": "sha1-pHheE11d9lAk38kiSVPfWFvSdmw=",
+          "dev": true
+        }
+      }
+    },
     "jasmine-core": {
       "version": "2.5.2",
       "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-2.5.2.tgz",

+ 4 - 1
package.json

@@ -7,10 +7,11 @@
     "build:js": "browserify -p tsify src/app.ts -t [ babelify --presets [ es2015 ] --extensions .ts ] -p [ browserify-header --file header.js ] -o dist/app.js",
     "build:css": "node-sass -o public/css/ --output-style compressed src/sass/",
     "build:css:watch": "node-sass -w -r --source-map true --source-map-embed true -o public/css/ --output-style compressed src/sass/",
+    "build:tests": "browserify -p tsify tests/ts/main.ts -t [ babelify --presets [ es2015 ] --extensions .ts ] -o dist/ts-tests.js",
     "dist": "npm run build && echo \"\" && node dist/build-package.js",
     "serve": "npm run build:css && budo src/app.ts:dist/app.js -- -d -p tsify -t [ babelify --presets [ es2015 ] --extensions .ts ]",
     "serve:live": "npm run build:css && concurrently --kill-others --names \"css,server\" -p name \"npm run build:css:watch\" \"budo src/app.ts:dist/app.js -d . -d public -d src --live -- -d -p tsify -t [ babelify --presets [ es2015 ] --extensions .ts ]\"",
-    "test": "karma start --single-run --log-level=debug --colors",
+    "test": "npm run build:tests && karma start --single-run --log-level=debug --colors",
     "lint": "tslint -c tslint.json --project tsconfig.json --exclude \"**/src/config.ts\"",
     "clean": "rm -rf js/ build/ dist/app*"
   },
@@ -67,9 +68,11 @@
     "webrtc-adapter": "~3.4.3"
   },
   "devDependencies": {
+    "@types/jasmine": "^2.8.6",
     "angular-mocks": "~1.5.10",
     "budo": "~9.4.7",
     "concurrently": "~3.3.0",
+    "jasmine": "^3.1.0",
     "jasmine-core": "~2.5.2",
     "karma": "~1.5.0",
     "karma-chrome-launcher": "~2.0.0",

+ 1 - 0
tests/testsuite.html

@@ -19,6 +19,7 @@
         <script src="../node_modules/angular-aria/angular-aria.min.js"></script>
 
         <script src="../dist/app.js"></script>
+        <script src="../dist/ts-tests.js"></script>
 
         <script src="filters.js"></script>
         <script src="service/message.js"></script>

+ 28 - 0
tests/ts/main.ts

@@ -0,0 +1,28 @@
+/**
+ * Copyright © 2016-2018 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/>.
+ */
+
+import 'jasmine';
+import {u8aToHex} from '../../src/helpers';
+
+describe('Helpers', () => {
+    it('u8aToHex', function() {
+        const arr = Uint8Array.of(1, 2, 4, 8, 254, 255);
+        expect(u8aToHex(arr)).toEqual('01020408feff');
+    });
+});