From d418c3a1359209620807bc55da75365d295c5bb1 Mon Sep 17 00:00:00 2001 From: DieMyst Date: Wed, 22 Feb 2023 19:21:09 +0400 Subject: [PATCH] test fixes, wip --- packages/core/js-peer/jest.config.cjs | 5 +++++ packages/core/js-peer/package.json | 2 +- .../__test__/integration/jsonBuiltin.spec.ts | 7 ++++--- .../js-peer/__test__/integration/peer.spec.ts | 9 ++++----- .../src/js-peer/__test__/unit/ast.spec.ts | 4 ++-- .../core/js-peer/src/js-peer/__test__/util.ts | 17 ++++++++++++++--- packages/core/js-peer/src/js-peer/utils.ts | 2 +- packages/core/js-peer/tsconfig.json | 1 + 8 files changed, 32 insertions(+), 15 deletions(-) diff --git a/packages/core/js-peer/jest.config.cjs b/packages/core/js-peer/jest.config.cjs index aeb61cbc..2b6fa37d 100644 --- a/packages/core/js-peer/jest.config.cjs +++ b/packages/core/js-peer/jest.config.cjs @@ -1,6 +1,7 @@ /** @type {import('ts-jest').JestConfigWithTsJest} */ module.exports = { extensionsToTreatAsEsm: ['.ts'], + testPathIgnorePatterns: ['dist'], "preset": "ts-jest/presets/default-esm", "moduleNameMapper": { "^(\\.{1,2}/.*)\\.js$": "$1" @@ -12,6 +13,10 @@ module.exports = { "useESM": true } ] + }, + + tsConfig: { + skipLibCheck: true } }; diff --git a/packages/core/js-peer/package.json b/packages/core/js-peer/package.json index eafbb3ee..1e902cc3 100644 --- a/packages/core/js-peer/package.json +++ b/packages/core/js-peer/package.json @@ -13,7 +13,7 @@ "build": "tsc", "compile-aqua": "aqua -i ./aqua/ -o ./src/internal/_aqua", "test:smoke": "node ./dist/js-peer/__test__/integration/smokeTest.js", - "test": "NODE_OPTIONS=--experimental-vm-modules npx jest", + "test": "NODE_OPTIONS=--experimental-vm-modules pnpm jest", "test:unit": "NODE_OPTIONS=--experimental-vm-modules pnpm jest --testPathPattern=src/__test__/unit", "test:integration": "NODE_OPTIONS=--experimental-vm-modules pnpm jest --testPathPattern=src/__test__/integration" }, diff --git a/packages/core/js-peer/src/js-peer/__test__/integration/jsonBuiltin.spec.ts b/packages/core/js-peer/src/js-peer/__test__/integration/jsonBuiltin.spec.ts index 782648d2..0abffeab 100644 --- a/packages/core/js-peer/src/js-peer/__test__/integration/jsonBuiltin.spec.ts +++ b/packages/core/js-peer/src/js-peer/__test__/integration/jsonBuiltin.spec.ts @@ -1,7 +1,8 @@ import { Particle } from '../../Particle.js'; import { doNothing } from '../../utils.js'; -import {createClient} from "../../../../../../client/js-client.node"; -import {FluencePeer} from "../../FluencePeer"; +import { FluencePeer } from '../../FluencePeer.js'; +import {mkTestNode} from "../util.js"; + let peer: FluencePeer; @@ -13,7 +14,7 @@ describe('Sig service test suite', () => { }); beforeEach(async () => { - peer = createClient(); + peer = await mkTestNode(); await peer.start(); }); diff --git a/packages/core/js-peer/src/js-peer/__test__/integration/peer.spec.ts b/packages/core/js-peer/src/js-peer/__test__/integration/peer.spec.ts index c815c38c..1f45d759 100644 --- a/packages/core/js-peer/src/js-peer/__test__/integration/peer.spec.ts +++ b/packages/core/js-peer/src/js-peer/__test__/integration/peer.spec.ts @@ -1,14 +1,13 @@ import { nodes } from '../connection.js'; import { checkConnection, doNothing, handleTimeout } from '../../utils.js'; -import {registerHandlersHelper, mkTestPeer, withPeer, withConnectedPeer} from '../util.js'; -import {FluencePeer} from "../../FluencePeer"; -import {createClient} from "../../../../../../client/js-client.node"; +import {registerHandlersHelper, mkTestPeer, withPeer, withConnectedPeer, mkTestNode} from '../util.js'; +import {FluencePeer} from "../../FluencePeer.js"; describe('Typescript usage suite', () => { describe('Should expose correct peer status', () => { - it('Should expose correct status for uninitialized peer', () => { - const peer = createClient(); + it('Should expose correct status for uninitialized peer', async () => { + const peer = await mkTestNode(); const status = peer.getStatus(); expect(status.isConnected).toBe(false); diff --git a/packages/core/js-peer/src/js-peer/__test__/unit/ast.spec.ts b/packages/core/js-peer/src/js-peer/__test__/unit/ast.spec.ts index 5fdc2cab..182ccf72 100644 --- a/packages/core/js-peer/src/js-peer/__test__/unit/ast.spec.ts +++ b/packages/core/js-peer/src/js-peer/__test__/unit/ast.spec.ts @@ -1,11 +1,11 @@ -import {createClient} from "../../../../../../client/js-client.node"; +import {mkTestNode} from "../util.js"; describe('Parse ast tests', () => { let somePeer: any; beforeAll(async () => { - somePeer = await createClient(); + somePeer = await mkTestNode(); await somePeer.start(); }, 10000); diff --git a/packages/core/js-peer/src/js-peer/__test__/util.ts b/packages/core/js-peer/src/js-peer/__test__/util.ts index e6bceaf0..7a40362e 100644 --- a/packages/core/js-peer/src/js-peer/__test__/util.ts +++ b/packages/core/js-peer/src/js-peer/__test__/util.ts @@ -12,8 +12,9 @@ import { marineLogFunction } from '../utils.js'; import { MarineBackgroundRunner } from '../../marine/worker/index.js'; import { MarineBasedAvmRunner } from '../avm.js'; import { nodes } from './connection.js'; -import {WorkerLoaderFromFs} from '../../marine/deps-loader/node.js'; -import {createClient} from "../../../../../client/js-client.node"; +import {WasmLoaderFromNpm, WorkerLoaderFromFs} from '../../marine/deps-loader/node.js'; +import {defaultNames} from "../../../../../client/js-client.node/src/index.js"; +import {WorkerLoader} from "../../marine/worker-script/workerLoader.js"; export const registerHandlersHelper = ( peer: FluencePeer, @@ -58,6 +59,16 @@ export const compileAqua = async (aquaFile: string): Promise => { return { functions, services: compilationResult.services }; }; +export const mkTestNode = () => { + const workerLoader = new WorkerLoader(); + const controlModuleLoader = new WasmLoaderFromNpm(defaultNames.marine.package, defaultNames.marine.file); + const avmModuleLoader = new WasmLoaderFromNpm(defaultNames.avm.package, defaultNames.avm.file); + + const marine = new MarineBackgroundRunner(workerLoader, controlModuleLoader, marineLogFunction); + const avm = new MarineBasedAvmRunner(marine, avmModuleLoader, undefined); + return new FluencePeer(marine, avm); +}; + export const mkTestPeer = () => { const workerLoader = new WorkerLoaderFromFs('../../marine/worker-script'); @@ -67,7 +78,7 @@ export const mkTestPeer = () => { }; export const withPeer = async (action: (p: FluencePeer) => Promise, config?: PeerConfig) => { - const p = createClient() + const p = await mkTestNode() try { console.log("connecting to: ") console.log(config) diff --git a/packages/core/js-peer/src/js-peer/utils.ts b/packages/core/js-peer/src/js-peer/utils.ts index 71bb7315..7f729e29 100644 --- a/packages/core/js-peer/src/js-peer/utils.ts +++ b/packages/core/js-peer/src/js-peer/utils.ts @@ -20,7 +20,7 @@ import { Buffer } from 'buffer'; import { CallServiceData, CallServiceResult, CallServiceResultType, ResultCodes } from '../interfaces/commonTypes.js'; import { ParticleExecutionStage } from './Particle.js'; import { LogFunction } from '@fluencelabs/marine-js/dist/types'; -import {FluencePeer} from "./FluencePeer"; +import {FluencePeer} from "./FluencePeer.js"; export const MakeServiceCall = (fn: (args: any[]) => CallServiceResultType) => diff --git a/packages/core/js-peer/tsconfig.json b/packages/core/js-peer/tsconfig.json index 8c5f23b0..d9108f69 100644 --- a/packages/core/js-peer/tsconfig.json +++ b/packages/core/js-peer/tsconfig.json @@ -4,6 +4,7 @@ "outDir": "./dist", "moduleResolution": "nodenext" }, + "skipLibCheck": true, "include": ["src/**/*"], "exclude": ["node_modules", "dist"], "esModuleInterop": true