Skip to content

Commit

Permalink
fix test and edit tsconfigs file
Browse files Browse the repository at this point in the history
  • Loading branch information
rstp-god committed Oct 14, 2022
1 parent 95063d3 commit 5f6c0ad
Show file tree
Hide file tree
Showing 24 changed files with 153 additions and 85 deletions.
13 changes: 0 additions & 13 deletions packages/e3kit-base/.mocharc.json

This file was deleted.

5 changes: 3 additions & 2 deletions packages/e3kit-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
"build": "rollup -c",
"clean": "rimraf .rpt2_cache dist",
"prepare": "npm run clean && npm run build",
"test": "mocha"
"ts-mocha": "ts-mocha -p tsconfig.spec.json src/__tests__/*.spec.ts"
},
"dependencies": {
"@types/abstract-leveldown": "7.2.0",
"@types/expect": "24.3.0",
"@types/levelup": "5.1.2",
"@virgilsecurity/crypto-types": "1.1.1",
"@virgilsecurity/keyknox": "1.0.3",
Expand All @@ -39,12 +40,12 @@
"chai": "4.3.6",
"chai-as-promised": "7.1.1",
"memdown": "^5.1.0",
"mocha": "10.0.0",
"rimraf": "3.0.2",
"rollup": "3.1.0",
"rollup-plugin-license": "2.8.1",
"rollup-plugin-typescript2": "0.34.1",
"sinon": "14.0.1",
"ts-mocha": "10.0.0",
"ts-node": "10.9.1",
"typescript": "4.8.4",
"virgil-crypto": "4.2.2"
Expand Down
4 changes: 2 additions & 2 deletions packages/e3kit-base/src/GroupManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ export class GroupManager {
apiUrl,
undefined,
new VirgilAgent(
process.env.__VIRGIL_PRODUCT_NAME__ ?? '',
process.env.__VIRGIL_PRODUCT_VERSION__ ?? '',
process.env.__VIRGIL_PRODUCT_NAME__!,
process.env.__VIRGIL_PRODUCT_VERSION__!,
),
),
);
Expand Down
4 changes: 2 additions & 2 deletions packages/e3kit-base/src/PrivateKeyLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export class PrivateKeyLoader {
this.options.apiUrl,
undefined,
new VirgilAgent(
process.env.__VIRGIL_PRODUCT_NAME__ ?? '',
process.env.__VIRGIL_PRODUCT_VERSION__ ?? '',
process.env.__VIRGIL_PRODUCT_NAME__!,
process.env.__VIRGIL_PRODUCT_VERSION__!,
),
);
private keyknoxCrypto = new KeyknoxCrypto(this.options.virgilCrypto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@
import { expect, use } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import sinon from 'sinon';
import { CardManager, CachingJwtProvider, KeyEntryStorage, ICard } from 'virgil-sdk';
import { VirgilCrypto } from 'virgil-crypto';
import { AbstractLevelDOWN } from 'abstract-leveldown';

import { ICard } from '../types';
import memdown from 'memdown';
import { VirgilCrypto } from 'virgil-crypto';
import { CachingJwtProvider, CardManager, KeyEntryStorage } from 'virgil-sdk';
import { PrivateKeyLoader } from '../PrivateKeyLoader';
import { AbstractEThree } from '../AbstractEThree';
import {
UsersNotFoundError,
UsersFoundWithMultipleCardsError,
IdentityAlreadyExistsError,
MultipleCardsError,
RegisterRequiredError,
UsersFoundWithMultipleCardsError,
UsersNotFoundError,
} from '../errors';
import { ICrypto } from '../types';
import memdown from 'memdown';

use(chaiAsPromised);

const getRandomString = (prefix?: string) => {
const getRandomString = (prefix: string): string => {
return `${prefix ? prefix : ''}${Math.random().toString(36).substr(2)}`;
};

Expand All @@ -36,9 +35,9 @@ class MyEThree extends AbstractEThree {
super({
identity,
virgilCrypto: cryptoStub,
cardManager: cardManagerStub as any,
keyLoader: keyLoaderStub as any,
groupStorageLeveldown: groupStorageLeveldownStub as any,
cardManager: cardManagerStub,
keyLoader: keyLoaderStub,
groupStorageLeveldown: groupStorageLeveldownStub,
// the following aren't actually used in the code and tests
accessTokenProvider: accessTokenProviderStub,
keyEntryStorage: keyEntryStorageStub,
Expand Down Expand Up @@ -87,8 +86,8 @@ describe('AbstractEthree', () => {
it('revoke all cards for identity', async () => {
const ethree = new MyEThree('my_identity');
const identitiesCards = [
{ id: getRandomString(), identity: 'my_identity' } as ICard,
{ id: getRandomString(), identity: 'my_identity' } as ICard,
{ id: getRandomString(''), identity: 'my_identity' } as ICard,
{ id: getRandomString(''), identity: 'my_identity' } as ICard,
];
cardManagerStub.searchCards.resolves(identitiesCards);
await ethree.unregister();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import { AbstractLevelDOWN } from 'abstract-leveldown';
use(chaiAsPromised);

const getRandomString = (prefix?: string) => {
return `${prefix ? prefix : ''}${Math.random()
.toString(36)
.substr(2)}`;
return `${prefix ? prefix : ''}${Math.random().toString(36).substr(2)}`;
};

const createGroupInfo = (initiator?: string): GroupInfo => {
Expand Down Expand Up @@ -436,12 +434,12 @@ describe('GroupLocalStorage', () => {
sessionIds.push(getRandomString('session'));
}

const groups = sessionIds.map(sessionId => ({
const groups = sessionIds.map((sessionId) => ({
info: createGroupInfo(),
tickets: createTickets(sessionId, 10),
}));

await Promise.all(groups.map(g => storage.store(g)));
await Promise.all(groups.map((g) => storage.store(g)));

await storage.reset();

Expand All @@ -464,28 +462,28 @@ describe('GroupLocalStorage', () => {
sessionIds.push(getRandomString('session'));
}

const groups = sessionIds.map(sessionId => ({
const groups = sessionIds.map((sessionId) => ({
info: createGroupInfo(),
tickets: createTickets(sessionId, 10),
}));

await Promise.all(
groups.map(g => storage1.store(g)).concat(groups.map(g => storage2.store(g))),
groups.map((g) => storage1.store(g)).concat(groups.map((g) => storage2.store(g))),
);

await storage1.reset();

const storage1Groups = await Promise.all(
sessionIds.map(sessionId => storage1.retrieve(sessionId, { ticketCount: 100 })),
sessionIds.map((sessionId) => storage1.retrieve(sessionId, { ticketCount: 100 })),
);

expect(storage1Groups.every(el => el == null)).to.be.true;
expect(storage1Groups.every((el) => el == null)).to.be.true;

const storage2Groups = await Promise.all(
sessionIds.map(sessionId => storage2.retrieve(sessionId, { ticketCount: 100 })),
sessionIds.map((sessionId) => storage2.retrieve(sessionId, { ticketCount: 100 })),
);

expect(storage2Groups.every(el => el != null)).to.be.true;
expect(storage2Groups.every((el) => el != null)).to.be.true;
});
});
});
1 change: 1 addition & 0 deletions packages/e3kit-base/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"declarationDir": "./dist/types",
"downlevelIteration": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"moduleResolution": "node",
"importHelpers": true,
"esModuleInterop": true,
Expand Down
26 changes: 26 additions & 0 deletions packages/e3kit-base/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/types",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": false,
"strictPropertyInitialization": false,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": true,
"declarationDir": "./dist/types",
"downlevelIteration": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"moduleResolution": "node",
"importHelpers": true,
"esModuleInterop": true,
"target": "es2020",
"module": "commonjs",
"lib": [
"es2018",
"dom"
]
},
}
1 change: 1 addition & 0 deletions packages/e3kit-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"rollup-plugin-license": "2.8.1",
"rollup-plugin-node-builtins": "2.1.2",
"rollup-plugin-node-globals": "1.4.0",
"rollup-plugin-node-polyfills": "0.2.1",
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-re": "1.0.7",
"rollup-plugin-typescript2": "0.34.1",
Expand Down
7 changes: 2 additions & 5 deletions packages/e3kit-browser/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const license = require('rollup-plugin-license');
const nodeBuiltins = require('rollup-plugin-node-builtins');
const nodeGlobals = require('rollup-plugin-node-globals');
const nodeResolve = require('rollup-plugin-node-resolve');
const nodePolyfills = require('rollup-plugin-node-polyfills');
const replace = require('rollup-plugin-re');
const typescript = require('rollup-plugin-typescript2');
const { generateCrossPlatformPath } = require('../../utils/build');
Expand Down Expand Up @@ -132,6 +133,7 @@ const createEntry = (target, cryptoType, format) => {
json(),
nodeGlobals(),
nodeBuiltins(),
nodePolyfills(),
license({
banner: {
content: {
Expand All @@ -142,11 +144,6 @@ const createEntry = (target, cryptoType, format) => {
wasm({
sync: [foundationWasmPath, pythiaWasmPath],
}),
// cryptoType === CRYPTO_TYPE.WASM &&
// copy({
// outputFolder: outputPath,
// targets: [foundationWasmPath, pythiaWasmPath],
// }),
],
};
};
Expand Down
23 changes: 19 additions & 4 deletions packages/e3kit-browser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
{
"compileOnSave": false,
"compilerOptions": {
"target": "ES2015",
"outDir": "./dist/types",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": false,
"strictPropertyInitialization": false,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": true,
"declarationDir": "./dist/types",
"strict": true,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"esModuleInterop": true,
"moduleResolution": "node"
}
"target": "es2020",
"module": "ES2020",
"lib": [
"es2018",
"dom"
]
},
}
7 changes: 2 additions & 5 deletions packages/e3kit-native/src/EThree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ export class EThree extends AbstractEThree {
retryOnUnauthorized: true,
apiUrl: opts.apiUrl,
productInfo: {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
product: process.env.__VIRGIL_PRODUCT_NAME__!,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
version: process.env.__VIRGIL_PRODUCT_VERSION__!,
product: process.env.__VIRGIL_PRODUCT_NAME__ ?? '',
version: process.env.__VIRGIL_PRODUCT_VERSION__ ?? '',
},
});
const groupStorageLeveldown = asyncstorageDown(opts.groupStorageName!, {
Expand Down Expand Up @@ -115,7 +113,6 @@ export class EThree extends AbstractEThree {
* @hidden
*/
protected isPublicKey(publicKey: any) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return publicKey != null && typeof (publicKey as any).value === 'string';
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncstorageDown from 'asyncstorage-down';

if (typeof asyncstorageDown.prototype.clear === 'undefined') {
asyncstorageDown.prototype.clear = function(opts?: any, cb?: (err?: Error) => void) {
asyncstorageDown.prototype.clear = function (opts?: any, cb?: (err?: Error) => void) {
let options;
let callback: (err?: Error) => void;
if (typeof opts === 'function') {
Expand Down
23 changes: 19 additions & 4 deletions packages/e3kit-native/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
{
"compileOnSave": false,
"compilerOptions": {
"target": "ES2015",
"outDir": "./dist/types",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": false,
"strictPropertyInitialization": false,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": true,
"declarationDir": "./dist/types",
"strict": true,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"esModuleInterop": true,
"moduleResolution": "node"
}
"target": "es2020",
"module": "es2015",
"lib": [
"es2018",
"dom"
]
},
}
23 changes: 19 additions & 4 deletions packages/e3kit-node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/types",
"resolveJsonModule": true,
"target": "ES2015",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": false,
"strictPropertyInitialization": false,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": true,
"declarationDir": "./dist/types",
"strict": true,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"esModuleInterop": true,
"moduleResolution": "node"
}
"target": "es2020",
"module": "es2015",
"lib": [
"es2018",
"dom"
]
},
}
2 changes: 1 addition & 1 deletion packages/e3kit-tests/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const webpack = require('webpack');

dotenv.config();

module.exports = config => {
module.exports = (config) => {
config.set({
frameworks: ['mocha'],
autoWatch: false,
Expand Down
Loading

0 comments on commit 5f6c0ad

Please sign in to comment.