Checking for undefined textencoder (#100)

* Fix `ReferenceError: TextEncoder is not defined`

* Add CI pipeline which runs avm client tests
This commit is contained in:
Pavel 2021-05-11 10:36:59 +03:00 committed by GitHub
parent e973d5ba56
commit 792763c72b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 5999 deletions

43
.github/workflows/avm_client_ci.yml vendored Normal file
View File

@ -0,0 +1,43 @@
name: Run tests for avm client (js)
defaults:
run:
working-directory: ./avm/client
on:
push:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 15.x]
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-v1-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-v1-node-${{ matrix.node-version }}
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
continue-on-error: true
- run: ./build_wasm.sh
- run: npm install
- name: test
run: npm run test
env:
CI: true

File diff suppressed because it is too large Load Diff

View File

@ -20,6 +20,7 @@
},
"devDependencies": {
"@types/jest": "^26.0.23",
"@types/node": "^14.0.0",
"jest": "26.5.0",
"ts-jest": "^26.5.5",
"typescript": "^3.9.5"

View File

@ -46,8 +46,8 @@ type ImportObject = {
'./air_interpreter_client_bg.js': {
// fn call_service_impl(service_id: String, fn_name: String, args: String, security_tetraplets: String) -> String;
// prettier-ignore
__wbg_callserviceimpl_d5849c05cb19df30: (arg0: any, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, arg8: any, ) => void;
__wbg_getcurrentpeeridimpl_20a1d2447bdbf3bc: (arg0: any) => void;
__wbg_callserviceimpl_6ea5db923e95be46: (arg0: any, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, arg8: any, ) => void;
__wbg_getcurrentpeeridimpl_f15307711f3f0ce6: (arg0: any) => void;
__wbindgen_throw: (arg: any) => void;
};
host: LogImport;
@ -133,7 +133,7 @@ function newImportObject(
// If so, an error with a new name will be occurred after wasm initialization.
'./air_interpreter_client_bg.js': {
// prettier-ignore
__wbg_callserviceimpl_d5849c05cb19df30: (arg0: any, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, arg8: any) => {
__wbg_callserviceimpl_6ea5db923e95be46: (arg0: any, arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, arg6: any, arg7: any, arg8: any) => {
let wasm = cfg.exports;
let serviceId = getStringFromWasm0(wasm, arg1, arg2);
let fnName = getStringFromWasm0(wasm, arg3, arg4);
@ -162,7 +162,7 @@ function newImportObject(
let resultStr = JSON.stringify(serviceResult);
return_call_service_result(wasm, resultStr, arg0);
},
__wbg_getcurrentpeeridimpl_20a1d2447bdbf3bc: (arg0: any) => {
__wbg_getcurrentpeeridimpl_f15307711f3f0ce6: (arg0: any) => {
let wasm = cfg.exports;
return_current_peer_id(wasm, peerId, arg0);
},

View File

@ -34,7 +34,9 @@ function getUint8Memory0(wasm) {
return cachegetUint8Memory0;
}
let cachedTextEncoder = new TextEncoder();
const lTextEncoder = typeof TextEncoder === 'undefined' ? module.require('util').TextEncoder : TextEncoder;
let cachedTextEncoder = new lTextEncoder('utf-8');
const encodeString =
typeof cachedTextEncoder.encodeInto === 'function'
@ -97,9 +99,9 @@ function getInt32Memory0(wasm) {
return cachegetInt32Memory0;
}
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
const lTextDecoder = typeof TextDecoder === 'undefined' ? module.require('util').TextDecoder : TextDecoder;
cachedTextDecoder.decode();
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
export function getStringFromWasm0(wasm, ptr, len) {
return cachedTextDecoder.decode(getUint8Memory0(wasm).subarray(ptr, ptr + len));