Skip to content

Commit

Permalink
add test-support package for unit test (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzcwoshizz committed Feb 14, 2023
1 parent 872ed45 commit 67b3fa1
Show file tree
Hide file tree
Showing 34 changed files with 521 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"access": "public",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"ignore": []
"ignore": ["test-support"]
}
3 changes: 2 additions & 1 deletion jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module.exports = Object.assign({}, config, {
'@zcloak/verify(.*)$': '<rootDir>/packages/verify/src/$1',
'@zcloak/wasm-asm(.*)$': '<rootDir>/packages/wasm-asm/src/$1',
'@zcloak/wasm-bridge(.*)$': '<rootDir>/packages/wasm-bridge/src/$1',
'@zcloak/wasm(.*)$': '<rootDir>/packages/wasm/src/$1'
'@zcloak/wasm(.*)$': '<rootDir>/packages/wasm/src/$1',
'test-support(.*)$': '<rootDir>/packages/test-support/src/$1'
},
testTimeout: 30000
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"build:wasm": "install-build-deps && build-wasm",
"changeset": "zcloak-exec-changeset",
"clean": "zcloak-dev-clean-build",
"lint": "zcloak-dev-run-lint && zcloak-dev-lint-dependencies",
"lint": "zcloak-dev-run-lint",
"postinstall": "zcloak-dev-yarn-only",
"test": "zcloak-dev-run-test --coverage --forceExit --runInBand --testPathIgnorePatterns e2e",
"test:one": "zcloak-dev-run-test --runInBand",
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/blake2/asHex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { initCrypto } from '../initCrypto';
import { blake2AsHex } from '.';

describe('blake2AsHex', (): void => {
beforeEach(async (): Promise<void> => {
beforeAll(async (): Promise<void> => {
await initCrypto();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/blake2/asU8a.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { initCrypto } from '../initCrypto';
import { blake2AsU8a } from '.';

describe('blake2AsU8a', (): void => {
beforeEach(async (): Promise<void> => {
beforeAll(async (): Promise<void> => {
await initCrypto();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/blake3-2to1/asU8a.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { initCrypto } from '../initCrypto';
import { blake32to1AsU8a } from './asU8a';

describe('blake32to1AsU8a', (): void => {
beforeEach(async (): Promise<void> => {
beforeAll(async (): Promise<void> => {
await initCrypto();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/blake3/asU8a.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { initCrypto } from '../initCrypto';
import { blake3AsU8a } from './asU8a';

describe('blake3AsU8a', (): void => {
beforeEach(async (): Promise<void> => {
beforeAll(async (): Promise<void> => {
await initCrypto();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/ed25519/fromSeed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('ed25519PairFromSeed', (): void => {
])
};

beforeEach(async (): Promise<void> => {
beforeAll(async (): Promise<void> => {
await initCrypto();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/ed25519/sign.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ed25519PairFromSeed, ed25519Sign } from '.';
describe('ed25519Sign', (): void => {
let pair: Keypair;

beforeEach(async (): Promise<void> => {
beforeAll(async (): Promise<void> => {
await initCrypto();
pair = ed25519PairFromSeed(stringToU8a('12345678901234567890123456789012'));
});
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/hmac/shaAsU8a.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { initCrypto } from '../initCrypto';
import { hmacShaAsU8a } from '.';

describe('hmacShaAsU8a', (): void => {
beforeEach(async (): Promise<void> => {
beforeAll(async (): Promise<void> => {
await initCrypto();
});

Expand Down
7 changes: 7 additions & 0 deletions packages/crypto/src/mnemonic/generate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('mnemonicGenerate', (): void => {

it.each([12, 15, 18, 21, 24] as 12[])('generates a valid mnemonic (%p words)', (num): void => {
const mnemonic = mnemonicGenerate(num);

const isValid = mnemonicValidate(mnemonic);

expect(mnemonic.split(' ')).toHaveLength(num);
Expand All @@ -26,6 +27,12 @@ describe('mnemonicGenerate', (): void => {
const m1 = mnemonicGenerate(24);
const m2 = mnemonicGenerate(24);

console.log(mnemonicGenerate());
console.log(mnemonicGenerate());
console.log(mnemonicGenerate());
console.log(mnemonicGenerate());
console.log(mnemonicGenerate());

expect(m1 === m2).toEqual(false);
expect(mnemonicValidate(m1)).toEqual(true);
expect(mnemonicValidate(m2)).toEqual(true);
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/pbkdf2/encode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const KNOWN_SALT = new Uint8Array([
const TEST_PASSWORD = 'test password';

describe('pbkdf2Encode', (): void => {
beforeEach(async (): Promise<void> => {
beforeAll(async (): Promise<void> => {
await initCrypto();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/rescue/asU8a.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { initCrypto } from '../initCrypto';
import { rescuePrimeAsU8a } from '.';

describe('rescuePrimeAsU8a', (): void => {
beforeEach(async (): Promise<void> => {
beforeAll(async (): Promise<void> => {
await initCrypto();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/rlp/encode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { rlpEncode } from './encode';
import * as official from './rlptest.json';

describe('encode rlp', (): void => {
beforeEach(async (): Promise<void> => {
beforeAll(async (): Promise<void> => {
await initCrypto();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/scrypt/encode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const KNOWN_SALT = new Uint8Array([
]);

describe('scryptEncode', (): void => {
beforeEach(async (): Promise<void> => {
beforeAll(async (): Promise<void> => {
await initCrypto();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/secp256k1/compress.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { initCrypto } from '../initCrypto';
import { secp256k1Compress } from '.';

describe('secp256k1Compress', (): void => {
beforeEach(async (): Promise<void> => {
beforeAll(async (): Promise<void> => {
await initCrypto();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/sha/asU8a512.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { initCrypto } from '../initCrypto';
import { sha512AsU8a } from '.';

describe('sha512AsU8a', (): void => {
beforeEach(async (): Promise<void> => {
beforeAll(async (): Promise<void> => {
await initCrypto();
});

Expand Down
15 changes: 6 additions & 9 deletions packages/ctype/src/publish.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@

import type { BaseCType } from './types';

import { initCrypto, mnemonicGenerate } from '@zcloak/crypto';
import { Did, helpers } from '@zcloak/did';
import { charlie } from 'test-support';

import { initCrypto } from '@zcloak/crypto';

import { DEFAULT_CTYPE_SCHEMA } from './defaults';
import { getCTypeHash, getPublish } from './publish';

describe('publish ctype', (): void => {
let publisher: Did;

beforeAll(async (): Promise<void> => {
await initCrypto();

publisher = helpers.createEcdsaFromMnemonic(mnemonicGenerate(12));
});

it('get ctype hash', (): void => {
Expand All @@ -37,8 +34,8 @@ describe('publish ctype', (): void => {
required: ['name', 'age']
};

expect(getCTypeHash(base, publisher.id)).toEqual(
getCTypeHash(base, publisher.getKeyUrl('authentication'))
expect(getCTypeHash(base, charlie.id)).toEqual(
getCTypeHash(base, charlie.getKeyUrl('authentication'))
);
});

Expand All @@ -61,7 +58,7 @@ describe('publish ctype', (): void => {
required: ['name', 'age']
};

expect(await getPublish(base, publisher)).toMatchObject({
expect(await getPublish(base, charlie)).toMatchObject({
...base,
$schema: DEFAULT_CTYPE_SCHEMA
});
Expand Down
2 changes: 1 addition & 1 deletion packages/did-resolver/src/ArweaveDidResolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const DOCUMENT = {
describe.skip('ArweaveDidResolver', (): void => {
let resolver: ArweaveDidResolver;

beforeEach(() => {
beforeAll(() => {
resolver = new ArweaveDidResolver();
});

Expand Down
Loading

0 comments on commit 67b3fa1

Please sign in to comment.