From 783a71217f94e614db1339dbcfcd0fcd9a2974df Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Tue, 24 Apr 2018 21:22:55 -0400 Subject: [PATCH] Fix typescript unit tests... maybe? --- src/web/api/__tests__/ServiceContext.test.ts | 4 ++-- src/web/api/build.cmd | 4 ++-- src/web/api/jest.config.js | 2 +- src/web/api/src/HelloService.ts | 4 ++-- src/web/api/src/ServiceContext.ts | 16 +--------------- src/web/api/src/bts_assert.ts | 3 ++- src/web/api/tsconfig.json | 9 +++++++-- 7 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/web/api/__tests__/ServiceContext.test.ts b/src/web/api/__tests__/ServiceContext.test.ts index 20440898d..269dbbc1e 100644 --- a/src/web/api/__tests__/ServiceContext.test.ts +++ b/src/web/api/__tests__/ServiceContext.test.ts @@ -4,8 +4,8 @@ import { connect, ServiceContext } from '../src/ServiceContext' import { HelloService } from '../src/HelloService' // Fix websocket for running in js -import WebSocket from 'ws' -global["WebSocket"] = WebSocket +// import WebSocket from 'ws' +// global["WebSocket"] = WebSocket test('log in and say hi', async () => { let ctx = await connect("bts", "password"); diff --git a/src/web/api/build.cmd b/src/web/api/build.cmd index 9df718f33..f35c8fe47 100644 --- a/src/web/api/build.cmd +++ b/src/web/api/build.cmd @@ -9,6 +9,6 @@ call npm run protogen call npm run build call npm run fable -::cd %~dp0\..\ui\src -::call dotnet fable webpack +cd %~dp0\..\ui\src +call dotnet fable webpack diff --git a/src/web/api/jest.config.js b/src/web/api/jest.config.js index eb31daf3e..8ff85d50a 100644 --- a/src/web/api/jest.config.js +++ b/src/web/api/jest.config.js @@ -1,5 +1,5 @@ module.exports = { - testEnvironment: 'node', + // testEnvironment: 'node', transform: { "^.+\\.tsx?$": "ts-jest" }, diff --git a/src/web/api/src/HelloService.ts b/src/web/api/src/HelloService.ts index ed5757655..be9425af6 100644 --- a/src/web/api/src/HelloService.ts +++ b/src/web/api/src/HelloService.ts @@ -1,7 +1,7 @@ // Future generated code import root from 'proto' import { ServiceContext } from 'ServiceContext' -// import { assertValid } from 'bts_assert'; +import { assertValid } from 'bts_assert'; const HelloRequestProto = root.lookupType("bts.api.test.HelloRequest") const HelloResponseProto = root.lookupType("bts.api.test.HelloResponse") @@ -24,7 +24,7 @@ export class HelloService { async say_hello(request : HelloRequest) : Promise { const r = HelloRequestProto.create(request) - // assertValid(HelloRequestProto, r) + assertValid(HelloRequestProto, r) const buffer = HelloRequestProto.encode(r).finish() // result = Uint8Array const result = await this.context.call(this.service_id, 0, buffer) diff --git a/src/web/api/src/ServiceContext.ts b/src/web/api/src/ServiceContext.ts index 3456d65d1..ecd040b6b 100644 --- a/src/web/api/src/ServiceContext.ts +++ b/src/web/api/src/ServiceContext.ts @@ -1,5 +1,5 @@ import {root} from 'proto' -// import { assertValid } from 'bts_assert' +import { assertValid } from 'bts_assert' const debug=true @@ -15,20 +15,6 @@ function default_ws_uri() { return ws_uri; } -function assert(condition:boolean, message?:string) : void { - if (!condition) { - message = message || "Assertion failed" - throw new Error(message); - } -} - -function assertValid(mtype, message) : void { - const r = mtype.verify(message) - assert(r != null, r) -} - - - // Message types const GatewayLogin = root.lookupType("bts.api.gateway.GatewayLogin") const GatewayRequest = root.lookupType("bts.api.gateway.GatewayRequest") diff --git a/src/web/api/src/bts_assert.ts b/src/web/api/src/bts_assert.ts index b7b06c2d5..0dbac3c12 100644 --- a/src/web/api/src/bts_assert.ts +++ b/src/web/api/src/bts_assert.ts @@ -7,6 +7,7 @@ export function assert(condition:boolean, message?:string) { } export function assertValid(mtype, message) { const r = mtype.verify(message) - assert(r != null, r) + console.log(r) + assert(r == null, r) } diff --git a/src/web/api/tsconfig.json b/src/web/api/tsconfig.json index 74ce4cad1..fcf7812fb 100644 --- a/src/web/api/tsconfig.json +++ b/src/web/api/tsconfig.json @@ -1,7 +1,12 @@ { "compilerOptions": { - "target": "ES6", - "module": "ES6", + "target": "ES5", + "module": "commonjs", + "lib": [ + "es2015", + "dom", + "es2016" + ], "allowSyntheticDefaultImports": true, "allowJs": false, "alwaysStrict": true,