mirror of https://github.com/waku-org/js-waku.git
Partial conversion to ts-node/mocha
This commit is contained in:
parent
090b064c84
commit
a89f2700a2
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"extension": ["ts"],
|
||||
"spec": "src/**/*.spec.ts",
|
||||
"require": "ts-node/register"
|
||||
}
|
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
|
@ -23,7 +23,7 @@
|
|||
"test:lint": "eslint src --ext .ts",
|
||||
"test:prettier": "prettier \"src/**/*.ts\" --list-different",
|
||||
"test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"",
|
||||
"test:unit": "nyc --silent jest",
|
||||
"test:unit": "mocha -r ts-node/register '**/*.spec.ts'",
|
||||
"test:lint-proto": "buf lint",
|
||||
"check-cli": "run-s test diff-integration-tests check-integration-tests",
|
||||
"check-integration-tests": "run-s check-integration-test:*",
|
||||
|
@ -63,14 +63,16 @@
|
|||
"@istanbuljs/nyc-config-typescript": "^1.0.1",
|
||||
"@types/app-root-path": "^1.2.4",
|
||||
"@types/axios": "^0.14.0",
|
||||
"@types/chai": "^4.2.15",
|
||||
"@types/google-protobuf": "^3.7.4",
|
||||
"@types/jest": "^26.0.20",
|
||||
"@types/mocha": "^8.2.2",
|
||||
"@types/node": "^14.14.31",
|
||||
"@types/tail": "^2.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.0.1",
|
||||
"@typescript-eslint/parser": "^4.0.1",
|
||||
"app-root-path": "^3.0.0",
|
||||
"axios": "^0.21.1",
|
||||
"chai": "^4.3.4",
|
||||
"codecov": "^3.5.0",
|
||||
"cspell": "^4.1.0",
|
||||
"cz-conventional-changelog": "^3.3.0",
|
||||
|
@ -82,8 +84,7 @@
|
|||
"fast-check": "^2.14.0",
|
||||
"gh-pages": "^3.1.0",
|
||||
"grpc_tools_node_protoc_ts": "^5.1.3",
|
||||
"jest": "^26.6.3",
|
||||
"jest-fast-check": "^1.0.2",
|
||||
"mocha": "^8.3.2",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"nyc": "^15.1.0",
|
||||
"open-cli": "^6.0.1",
|
||||
|
@ -91,7 +92,7 @@
|
|||
"prettier": "^2.1.1",
|
||||
"standard-version": "^9.0.0",
|
||||
"tail": "^2.2.0",
|
||||
"ts-node": "^9.0.0",
|
||||
"ts-node": "^9.1.1",
|
||||
"typedoc": "^0.20.29",
|
||||
"typescript": "^4.0.2"
|
||||
},
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/// <reference types="../gen/proto/waku/v2/waku_pb" />
|
||||
import { WakuMessage } from '../gen/proto/waku/v2/waku_pb';
|
||||
|
||||
// Ensure that this class matches the proto interface while
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import 'jest';
|
||||
import { expect } from 'chai';
|
||||
import Libp2p from 'libp2p';
|
||||
import Pubsub from 'libp2p-interfaces/src/pubsub';
|
||||
|
||||
|
@ -10,7 +10,7 @@ import { CODEC, TOPIC } from './waku_relay';
|
|||
|
||||
describe('Waku Relay', () => {
|
||||
// TODO: Fix this, see https://github.com/ChainSafe/js-libp2p-gossipsub/issues/151
|
||||
test.skip('Publish', async () => {
|
||||
it.skip('Publish', async () => {
|
||||
const message = Message.fromUtf8String('Bird bird bird, bird is the word!');
|
||||
|
||||
const [waku1, waku2] = await Promise.all([Waku.create(), Waku.create()]);
|
||||
|
@ -36,26 +36,26 @@ describe('Waku Relay', () => {
|
|||
|
||||
const node1Received = await promise;
|
||||
|
||||
expect(node1Received.isEqualTo(message)).toBeTruthy();
|
||||
expect(node1Received.isEqualTo(message)).to.be.true;
|
||||
|
||||
await Promise.all([waku1.stop(), waku2.stop()]);
|
||||
});
|
||||
|
||||
test('Registers waku relay protocol', async () => {
|
||||
it('Registers waku relay protocol', async () => {
|
||||
const waku = await Waku.create();
|
||||
|
||||
const protocols = Array.from(waku.libp2p.upgrader.protocols.keys());
|
||||
|
||||
expect(protocols.findIndex((value) => value == CODEC)).toBeTruthy();
|
||||
expect(protocols.findIndex((value) => value == CODEC)).to.be.true;
|
||||
|
||||
await waku.stop();
|
||||
});
|
||||
|
||||
test('Does not register any sub protocol', async () => {
|
||||
it('Does not register any sub protocol', async () => {
|
||||
const waku = await Waku.create();
|
||||
|
||||
const protocols = Array.from(waku.libp2p.upgrader.protocols.keys());
|
||||
expect(protocols.findIndex((value) => value.match(/sub/))).toBeTruthy();
|
||||
expect(protocols.findIndex((value) => value.match(/sub/))).to.be.true;
|
||||
|
||||
await waku.stop();
|
||||
});
|
||||
|
@ -73,7 +73,8 @@ describe('Waku Relay', () => {
|
|||
);
|
||||
const multiAddrWithId = localMultiaddr + '/p2p/' + peerId;
|
||||
|
||||
nimWaku = new NimWaku(expect.getState().currentTestName);
|
||||
console.log(this);
|
||||
nimWaku = new NimWaku('foo');
|
||||
await nimWaku.start({ staticnode: multiAddrWithId });
|
||||
});
|
||||
|
||||
|
@ -82,14 +83,14 @@ describe('Waku Relay', () => {
|
|||
waku ? await waku.stop() : null;
|
||||
});
|
||||
|
||||
test('nim subscribes to js', async () => {
|
||||
it('nim subscribes to js', async () => {
|
||||
const nimPeerId = await nimWaku.getPeerId();
|
||||
const subscribers = waku.libp2p.pubsub.getSubscribers(TOPIC);
|
||||
|
||||
expect(subscribers).toContain(nimPeerId.toB58String());
|
||||
expect(subscribers).to.contain(nimPeerId.toB58String());
|
||||
});
|
||||
|
||||
test('Js publishes to nim', async () => {
|
||||
it('Js publishes to nim', async () => {
|
||||
const message = Message.fromUtf8String('This is a message');
|
||||
// TODO: nim-waku does follow the `StrictNoSign` policy hence we need to change
|
||||
// it for nim-waku to process our messages. Can be removed once
|
||||
|
@ -104,14 +105,14 @@ describe('Waku Relay', () => {
|
|||
|
||||
const msgs = await nimWaku.messages();
|
||||
|
||||
expect(msgs[0].contentTopic).toEqual(message.contentTopic);
|
||||
expect(msgs[0].version).toEqual(message.version);
|
||||
expect(msgs[0].contentTopic).to.equal(message.contentTopic);
|
||||
expect(msgs[0].version).to.equal(message.version);
|
||||
|
||||
const payload = Buffer.from(msgs[0].payload);
|
||||
expect(Buffer.compare(payload, message.payload)).toBe(0);
|
||||
expect(Buffer.compare(payload, message.payload)).to.equal(0);
|
||||
});
|
||||
|
||||
test('Nim publishes to js', async () => {
|
||||
it('Nim publishes to js', async () => {
|
||||
const message = Message.fromUtf8String('Here is another message.');
|
||||
|
||||
await patchPeerStore(nimWaku, waku.libp2p);
|
||||
|
@ -128,11 +129,11 @@ describe('Waku Relay', () => {
|
|||
|
||||
const receivedMsg = await receivedPromise;
|
||||
|
||||
expect(receivedMsg.contentTopic).toBe(message.contentTopic);
|
||||
expect(receivedMsg.version).toBe(message.version);
|
||||
expect(receivedMsg.contentTopic).to.eq(message.contentTopic);
|
||||
expect(receivedMsg.version).to.eq(message.version);
|
||||
|
||||
const payload = Buffer.from(receivedMsg.payload);
|
||||
expect(Buffer.compare(payload, message.payload)).toBe(0);
|
||||
expect(Buffer.compare(payload, message.payload)).to.eq(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -41,10 +41,13 @@
|
|||
// "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */,
|
||||
|
||||
"lib": ["es2017"],
|
||||
"types": ["node", "jest"],
|
||||
"typeRoots": ["node_modules/@types", "src/types"]
|
||||
"types": ["node", "mocha"],
|
||||
"typeRoots": ["node_modules/@types", "src/types", "src/gen/proto"]
|
||||
},
|
||||
"include": ["src/**/*.ts"],
|
||||
"include": ["src/**/*.ts", "src/**/*.d.ts"],
|
||||
"exclude": ["node_modules/**"],
|
||||
"compileOnSave": false
|
||||
"compileOnSave": false,
|
||||
"ts-node": {
|
||||
"files": true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue