Karma: Remove tests folder and use in place files & update contrib guide

*.browser.spec.ts files will be tested on both node and browser.
Other files only tested on node.
This commit is contained in:
Franck Royer 2021-07-14 21:11:01 +10:00
parent 25fccb4c9a
commit 9374de1931
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
5 changed files with 12 additions and 91 deletions

View File

@ -19,9 +19,10 @@ To help ensure your PR passes, just run before committing:
To build and test this repository, you need: To build and test this repository, you need:
- [Node.js & npm](https://nodejs.org/en/) - [Node.js & npm](https://nodejs.org/en/).
- [bufbuild](https://github.com/bufbuild/buf) (only if changing protobuf files) - [bufbuild](https://github.com/bufbuild/buf) (only if changing protobuf files).
- [protoc](https://grpc.io/docs/protoc-installation/) (only if changing protobuf files) - [protoc](https://grpc.io/docs/protoc-installation/) (only if changing protobuf files).
- Firefox & Chrome (for browser testing).
To ensure interoperability with [nim-waku](https://github.com/status-im/nim-waku/), some tests are run against a nim-waku node. To ensure interoperability with [nim-waku](https://github.com/status-im/nim-waku/), some tests are run against a nim-waku node.
This is why `nim-waku` is present as a [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules), which itself contain several submodules. This is why `nim-waku` is present as a [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules), which itself contain several submodules.
@ -29,10 +30,14 @@ At this stage, it is not possible to exclude nim-waku tests, hence `git submodul
To build nim-waku, you also need [Rust](https://www.rust-lang.org/tools/install). To build nim-waku, you also need [Rust](https://www.rust-lang.org/tools/install).
Note that we run tests in both NodeJS and browser environments (both Chrome and Firefox, using [karma](https://karma-runner.github.io/)).
Files named `*.spec.ts` are only run in NodeJS environment;
Files named `*.browser.spec.ts` are run in both NodeJS and browser environment.
## Guidelines ## Guidelines
- Please follow [Chris Beam's commit message guide](https://chris.beams.io/posts/git-commit/), - Please follow [Chris Beam's commit message guide](https://chris.beams.io/posts/git-commit/) for commit patches,
- Usually best to test new code, - Please test new code, we use [mocha](https://mochajs.org/), [chai](https://www.chaijs.com/) and [karma](https://karma-runner.github.io/).
### Committing Patches ### Committing Patches

View File

@ -3,11 +3,7 @@ process.env.CHROME_BIN = require('puppeteer').executablePath();
module.exports = function (config) { module.exports = function (config) {
config.set({ config.set({
frameworks: ['mocha', 'karma-typescript'], frameworks: ['mocha', 'karma-typescript'],
files: [ files: ['src/lib/**/*.ts', 'src/proto/**/*.ts'],
'src/lib/**/*.ts',
'src/proto/**/*.ts',
'src/tests/browser/*.spec.ts',
],
preprocessors: { preprocessors: {
'**/*.ts': ['karma-typescript'], '**/*.ts': ['karma-typescript'],
}, },
@ -21,7 +17,7 @@ module.exports = function (config) {
singleRun: true, singleRun: true,
karmaTypescriptConfig: { karmaTypescriptConfig: {
bundlerOptions: { bundlerOptions: {
entrypoints: /src\/tests\/browser\/.*\.spec\.ts$/, entrypoints: /.*\.browser\.spec\.ts$/,
}, },
tsconfig: './tsconfig.karma.json', tsconfig: './tsconfig.karma.json',
coverageOptions: { coverageOptions: {

View File

@ -1,12 +1,6 @@
import { expect } from 'chai'; import { expect } from 'chai';
import fc from 'fast-check'; import fc from 'fast-check';
fc.configureGlobal({
interruptAfterTimeLimit: 1500,
markInterruptAsFailure: true,
numRuns: 10, // Firefox is too slow for 100 (fc default) runs in 2s (mocha default)
});
import { WakuMessage } from '../../lib/waku_message'; import { WakuMessage } from '../../lib/waku_message';
import { getPublicKey } from '../../lib/waku_message/version_1'; import { getPublicKey } from '../../lib/waku_message/version_1';

View File

@ -1,74 +0,0 @@
import { expect } from 'chai';
import fc from 'fast-check';
import {
clearDecode,
clearEncode,
decryptAsymmetric,
decryptSymmetric,
encryptAsymmetric,
encryptSymmetric,
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);
}
)
);
});
it('Symmetric encrypt & Decrypt', async function () {
await fc.assert(
fc.asyncProperty(
fc.uint8Array(),
fc.uint8Array({ minLength: 32, maxLength: 32 }),
async (message, key) => {
const enc = await encryptSymmetric(message, key);
const res = await decryptSymmetric(enc, key);
expect(res).deep.equal(message);
}
)
);
});
});