Only include lib files, segregate browser tests

This commit is contained in:
Franck Royer 2021-07-14 13:03:57 +10:00
parent a9c83dac13
commit ac4f0aab98
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
4 changed files with 70 additions and 30 deletions

View File

@ -1,7 +1,11 @@
module.exports = function (config) {
config.set({
frameworks: ['mocha', 'karma-typescript'],
files: [{ pattern: 'src/**/*browser.spec.ts' }],
files: [
'src/lib/**/*.ts',
'src/proto/**/*.ts',
'src/tests/browser/*.spec.ts',
],
preprocessors: {
'**/*.ts': ['karma-typescript'],
},
@ -15,6 +19,9 @@ module.exports = function (config) {
browsers: ['Chromium'],
singleRun: true,
karmaTypescriptConfig: {
bundlerOptions: {
entrypoints: /src\/tests\/browser\/.*\.spec\.ts$/,
},
tsconfig: './tsconfig.karma.json',
coverageOptions: {
instrumentation: false,

View File

@ -1,29 +0,0 @@
import { expect } from 'chai';
import { NOISE_KEY_1, NOISE_KEY_2 } from '../test_utils/';
import { Waku } from './waku';
describe('Waku Dial', function () {
it('js connects to js', async function () {
this.timeout(10_000);
const [waku1, waku2] = await Promise.all([
Waku.create({
staticNoiseKey: NOISE_KEY_1,
libp2p: { addresses: { listen: ['/ip4/0.0.0.0/tcp/0/ws'] } },
}),
Waku.create({ staticNoiseKey: NOISE_KEY_2 }),
]);
const waku1MultiAddrWithId = waku1.getLocalMultiaddrWithID();
await waku2.dial(waku1MultiAddrWithId);
const waku2PeerId = waku2.libp2p.peerId;
const waku1Peers = waku1.libp2p.peerStore.peers;
expect(waku1Peers.has(waku2PeerId.toB58String())).to.be.true;
await Promise.all([waku1.stop(), waku2.stop()]);
});
});

View File

@ -0,0 +1,57 @@
import { expect } from 'chai';
import fc from 'fast-check';
import {
clearDecode,
clearEncode,
decryptAsymmetric,
encryptAsymmetric,
getPublicKey,
} from '../../lib/waku_message/version_1';
describe('Waku Message Version 1', function () {
it('Sign & Recover', function () {
fc.assert(
fc.property(
fc.uint8Array(),
fc.uint8Array({ minLength: 32, maxLength: 32 }),
(message, privKey) => {
const enc = clearEncode(message, privKey);
const res = clearDecode(enc.payload);
const pubKey = getPublicKey(privKey);
expect(res?.payload).deep.equal(
message,
'Payload was not encrypted then decrypted correctly'
);
expect(res?.sig?.publicKey).deep.equal(
pubKey,
'signature Public key was not recovered from encrypted then decrypted signature'
);
expect(enc?.sig?.publicKey).deep.equal(
pubKey,
'Incorrect signature public key was returned when signing the payload'
);
}
)
);
});
it('Asymmetric encrypt & Decrypt', async function () {
await fc.assert(
fc.asyncProperty(
fc.uint8Array({ minLength: 1 }),
fc.uint8Array({ minLength: 32, maxLength: 32 }),
async (message, privKey) => {
const publicKey = getPublicKey(privKey);
const enc = await encryptAsymmetric(message, publicKey);
const res = await decryptAsymmetric(enc, privKey);
expect(res).deep.equal(message);
}
)
);
});
});

View File

@ -3,5 +3,10 @@
"compilerOptions": {
"noEmit": false
},
"include": [
"src/lib/**/*.ts",
"src/proto/**/*.ts",
"src/tests/browser/**/*.ts"
],
"exclude": ["node_modules/**"]
}