From ef1b2e99e0613da7758e2943a31089210cb278a4 Mon Sep 17 00:00:00 2001 From: ryo-casper Date: Mon, 15 Apr 2024 02:49:01 -0400 Subject: [PATCH 1/7] chore: add commonjs rollup plugin --- rollup.config.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rollup.config.js b/rollup.config.js index 3f177e994..cf12d614c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,4 +1,5 @@ const typescript = require('@rollup/plugin-typescript'); +const commonjs = require('@rollup/plugin-commonjs'); const { nodeResolve } = require('@rollup/plugin-node-resolve'); const json = require('@rollup/plugin-json'); const nodePolyfills = require('rollup-plugin-polyfill-node'); @@ -30,6 +31,7 @@ function getConfig(opts) { const plugins = [ json(), + commonjs(), typescript({ tsconfig: './tsconfig.json' }), nodeResolve({ exportConditions, From 022b8e5a5e292e9b242c128ca5dcd89012ba617d Mon Sep 17 00:00:00 2001 From: ryo-casper Date: Mon, 15 Apr 2024 02:49:59 -0400 Subject: [PATCH 2/7] chore: register chai global --- .mocharc.json | 10 ++++++++++ packages/keys/.mocharc.json | 1 + packages/keys/package.json | 2 +- packages/keys/src/typings/global.d.ts | 1 + packages/keys/tsconfig.build.json | 7 +++++++ packages/keys/tsconfig.json | 6 +----- packages/types/.mocharc.json | 1 + packages/types/package.json | 2 +- packages/types/src/typings/global.d.ts | 1 + packages/types/tsconfig.build.json | 7 +++++++ packages/types/tsconfig.json | 6 +----- tsconfig.base.json | 4 +++- 12 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 .mocharc.json create mode 120000 packages/keys/.mocharc.json create mode 100644 packages/keys/src/typings/global.d.ts create mode 100644 packages/keys/tsconfig.build.json create mode 120000 packages/types/.mocharc.json create mode 100644 packages/types/src/typings/global.d.ts create mode 100644 packages/types/tsconfig.build.json diff --git a/.mocharc.json b/.mocharc.json new file mode 100644 index 000000000..00b6038ea --- /dev/null +++ b/.mocharc.json @@ -0,0 +1,10 @@ +{ + "spec": "src/**/*.test.ts", + "require": [ + "ts-node/register", + "chai/register-assert.js", + "chai/register-expect.js", + "chai/register-should.js" + ], + "recursive": true +} diff --git a/packages/keys/.mocharc.json b/packages/keys/.mocharc.json new file mode 120000 index 000000000..bee364ef3 --- /dev/null +++ b/packages/keys/.mocharc.json @@ -0,0 +1 @@ +../../.mocharc.json \ No newline at end of file diff --git a/packages/keys/package.json b/packages/keys/package.json index 546187696..366937c1b 100644 --- a/packages/keys/package.json +++ b/packages/keys/package.json @@ -9,7 +9,7 @@ "license": "Apache-2.0", "scripts": { "build": "run -T rollup -c", - "test": "run -T cross-env NODE_ENV=test TS_NODE_FILES=true mocha -r ts-node/register \"src/**/*.test.ts\"", + "test": "run -T cross-env NODE_ENV=test TS_NODE_FILES=true mocha", "test:coverage": "run -T nyc --reporter=lcov yarn test", "coverage": "run -T codecov" }, diff --git a/packages/keys/src/typings/global.d.ts b/packages/keys/src/typings/global.d.ts new file mode 100644 index 000000000..192c79c5e --- /dev/null +++ b/packages/keys/src/typings/global.d.ts @@ -0,0 +1 @@ +declare const expect: Chai.ExpectStatic; diff --git a/packages/keys/tsconfig.build.json b/packages/keys/tsconfig.build.json new file mode 100644 index 000000000..0e151a9ca --- /dev/null +++ b/packages/keys/tsconfig.build.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "./dist/" + }, + "exclude": ["*/**/*.test.ts"] +} diff --git a/packages/keys/tsconfig.json b/packages/keys/tsconfig.json index 828ace546..564a59900 100644 --- a/packages/keys/tsconfig.json +++ b/packages/keys/tsconfig.json @@ -1,8 +1,4 @@ { "extends": "../../tsconfig.base.json", - "compilerOptions": { - "outDir": "./dist/", - }, - "include": ["src"], - "exclude": ["*/**/*.test.ts"] + "include": ["src"] } diff --git a/packages/types/.mocharc.json b/packages/types/.mocharc.json new file mode 120000 index 000000000..bee364ef3 --- /dev/null +++ b/packages/types/.mocharc.json @@ -0,0 +1 @@ +../../.mocharc.json \ No newline at end of file diff --git a/packages/types/package.json b/packages/types/package.json index d59353bb4..000b1e2f1 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -9,7 +9,7 @@ "license": "Apache-2.0", "scripts": { "build": "run -T rollup -c", - "test": "run -T cross-env NODE_ENV=test TS_NODE_FILES=true mocha -r ts-node/register \"src/**/*.test.ts\"", + "test": "run -T cross-env NODE_ENV=test TS_NODE_FILES=true mocha", "test:coverage": "run -T nyc --reporter=lcov yarn test", "coverage": "run -T codecov" } diff --git a/packages/types/src/typings/global.d.ts b/packages/types/src/typings/global.d.ts new file mode 100644 index 000000000..192c79c5e --- /dev/null +++ b/packages/types/src/typings/global.d.ts @@ -0,0 +1 @@ +declare const expect: Chai.ExpectStatic; diff --git a/packages/types/tsconfig.build.json b/packages/types/tsconfig.build.json new file mode 100644 index 000000000..0e151a9ca --- /dev/null +++ b/packages/types/tsconfig.build.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "./dist/" + }, + "exclude": ["*/**/*.test.ts"] +} diff --git a/packages/types/tsconfig.json b/packages/types/tsconfig.json index 828ace546..564a59900 100644 --- a/packages/types/tsconfig.json +++ b/packages/types/tsconfig.json @@ -1,8 +1,4 @@ { "extends": "../../tsconfig.base.json", - "compilerOptions": { - "outDir": "./dist/", - }, - "include": ["src"], - "exclude": ["*/**/*.test.ts"] + "include": ["src"] } diff --git a/tsconfig.base.json b/tsconfig.base.json index 0497b8563..1e0822a59 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -19,5 +19,7 @@ "target": "ES6", "lib": ["es2015", "dom"], "skipLibCheck": true - } + }, + "typeRoots": ["node_modules/@types", "./typings"], + "types": ["mocha", "chai", "node", "global"] } From 762a9ec3bcc62c9308b1e9c93c91952735881430 Mon Sep 17 00:00:00 2001 From: ryo-casper Date: Mon, 15 Apr 2024 03:02:58 -0400 Subject: [PATCH 3/7] update rollup config --- rollup.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rollup.config.js b/rollup.config.js index cf12d614c..3116d4ceb 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -32,7 +32,7 @@ function getConfig(opts) { const plugins = [ json(), commonjs(), - typescript({ tsconfig: './tsconfig.json' }), + typescript({ tsconfig: './tsconfig.build.json' }), nodeResolve({ exportConditions, mainFields, From aed94d6f893fca3584060013bdba436732c613b7 Mon Sep 17 00:00:00 2001 From: ryo-casper Date: Mon, 15 Apr 2024 03:06:59 -0400 Subject: [PATCH 4/7] update build tsconfig --- packages/keys/tsconfig.build.json | 1 + packages/types/tsconfig.build.json | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/keys/tsconfig.build.json b/packages/keys/tsconfig.build.json index 0e151a9ca..8f7aee609 100644 --- a/packages/keys/tsconfig.build.json +++ b/packages/keys/tsconfig.build.json @@ -3,5 +3,6 @@ "compilerOptions": { "outDir": "./dist/" }, + "include": ["src"], "exclude": ["*/**/*.test.ts"] } diff --git a/packages/types/tsconfig.build.json b/packages/types/tsconfig.build.json index 0e151a9ca..8f7aee609 100644 --- a/packages/types/tsconfig.build.json +++ b/packages/types/tsconfig.build.json @@ -3,5 +3,6 @@ "compilerOptions": { "outDir": "./dist/" }, + "include": ["src"], "exclude": ["*/**/*.test.ts"] } From 6e2e581d53cbf5ec04f9b6d8666e8235653ffa29 Mon Sep 17 00:00:00 2001 From: ryo-casper Date: Mon, 15 Apr 2024 03:11:19 -0400 Subject: [PATCH 5/7] add typings for assert --- packages/keys/src/typings/global.d.ts | 1 + packages/types/src/typings/global.d.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/keys/src/typings/global.d.ts b/packages/keys/src/typings/global.d.ts index 192c79c5e..18cb43a93 100644 --- a/packages/keys/src/typings/global.d.ts +++ b/packages/keys/src/typings/global.d.ts @@ -1 +1,2 @@ declare const expect: Chai.ExpectStatic; +declare const assert: Chai.AssertStatic; diff --git a/packages/types/src/typings/global.d.ts b/packages/types/src/typings/global.d.ts index 192c79c5e..18cb43a93 100644 --- a/packages/types/src/typings/global.d.ts +++ b/packages/types/src/typings/global.d.ts @@ -1 +1,2 @@ declare const expect: Chai.ExpectStatic; +declare const assert: Chai.AssertStatic; From 73dd6e2216e372ce32aba61a5f5f48b16967f25c Mon Sep 17 00:00:00 2001 From: ryo-casper Date: Mon, 15 Apr 2024 03:14:01 -0400 Subject: [PATCH 6/7] test: remove chai imports --- packages/keys/src/Ed25519.test.ts | 1 - packages/keys/src/Secp256k1.test.ts | 1 - packages/keys/src/utils.test.ts | 1 - packages/types/src/ByteConverters.test.ts | 1 - packages/types/src/CLValue/AccountHash.test.ts | 2 -- packages/types/src/CLValue/Bool.test.ts | 2 -- packages/types/src/CLValue/ByteArray.test.ts | 2 -- packages/types/src/CLValue/Key.test.ts | 2 -- packages/types/src/CLValue/List.test.ts | 2 -- packages/types/src/CLValue/Map.test.ts | 2 -- packages/types/src/CLValue/Numeric.test.ts | 2 -- packages/types/src/CLValue/Option.test.ts | 1 - packages/types/src/CLValue/PublicKey.test.ts | 2 -- packages/types/src/CLValue/Result.test.ts | 1 - packages/types/src/CLValue/String.test.ts | 2 -- packages/types/src/CLValue/Tuple.test.ts | 2 -- packages/types/src/CLValue/URef.test.ts | 2 -- packages/types/src/CLValue/Unit.test.ts | 2 -- packages/types/src/ChecksummedHex.test.ts | 6 ------ packages/types/src/StoredValue.test.ts | 1 - 20 files changed, 37 deletions(-) diff --git a/packages/keys/src/Ed25519.test.ts b/packages/keys/src/Ed25519.test.ts index 2cd03a826..7370f476e 100644 --- a/packages/keys/src/Ed25519.test.ts +++ b/packages/keys/src/Ed25519.test.ts @@ -4,7 +4,6 @@ import { decodeBase16, decodeBase64 } from 'casper-js-types'; -import { expect } from 'chai'; import sinon from 'sinon'; import { Ed25519 } from './Ed25519'; diff --git a/packages/keys/src/Secp256k1.test.ts b/packages/keys/src/Secp256k1.test.ts index 8814df15b..acf03a728 100644 --- a/packages/keys/src/Secp256k1.test.ts +++ b/packages/keys/src/Secp256k1.test.ts @@ -1,5 +1,4 @@ import { CLPublicKey, byteHash, decodeBase16 } from 'casper-js-types'; -import { expect } from 'chai'; import { Secp256K1 } from './Secp256k1'; diff --git a/packages/keys/src/utils.test.ts b/packages/keys/src/utils.test.ts index 32f48da39..cb8501a38 100644 --- a/packages/keys/src/utils.test.ts +++ b/packages/keys/src/utils.test.ts @@ -1,5 +1,4 @@ import { SignatureAlgorithm } from 'casper-js-types'; -import { expect } from 'chai'; import { accountHashHelper } from './utils'; diff --git a/packages/types/src/ByteConverters.test.ts b/packages/types/src/ByteConverters.test.ts index 12195d517..30a44e029 100644 --- a/packages/types/src/ByteConverters.test.ts +++ b/packages/types/src/ByteConverters.test.ts @@ -1,4 +1,3 @@ -import { expect } from 'chai'; import { Some } from 'ts-results'; import { diff --git a/packages/types/src/CLValue/AccountHash.test.ts b/packages/types/src/CLValue/AccountHash.test.ts index 7a531b17b..0e617262a 100644 --- a/packages/types/src/CLValue/AccountHash.test.ts +++ b/packages/types/src/CLValue/AccountHash.test.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import { CLAccountHash } from './AccountHash'; import { CLAccountHashType, CLValueParsers } from './index'; diff --git a/packages/types/src/CLValue/Bool.test.ts b/packages/types/src/CLValue/Bool.test.ts index 9ca35154c..f44c561e6 100644 --- a/packages/types/src/CLValue/Bool.test.ts +++ b/packages/types/src/CLValue/Bool.test.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import { CLBool, CLBoolType, diff --git a/packages/types/src/CLValue/ByteArray.test.ts b/packages/types/src/CLValue/ByteArray.test.ts index 1b5396e63..dd66c8ebc 100644 --- a/packages/types/src/CLValue/ByteArray.test.ts +++ b/packages/types/src/CLValue/ByteArray.test.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import { CLByteArray, CLByteArrayType, CLValueParsers } from './index'; describe('CLByteArray', () => { diff --git a/packages/types/src/CLValue/Key.test.ts b/packages/types/src/CLValue/Key.test.ts index 42f6740ce..1ff391dfb 100644 --- a/packages/types/src/CLValue/Key.test.ts +++ b/packages/types/src/CLValue/Key.test.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import { decodeBase16 } from '../Conversions'; import { AccessRights, diff --git a/packages/types/src/CLValue/List.test.ts b/packages/types/src/CLValue/List.test.ts index 73e70dd5b..e0a3e2935 100644 --- a/packages/types/src/CLValue/List.test.ts +++ b/packages/types/src/CLValue/List.test.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import { CLBool, CLBoolType, diff --git a/packages/types/src/CLValue/Map.test.ts b/packages/types/src/CLValue/Map.test.ts index 990baa5b8..5bb07c850 100644 --- a/packages/types/src/CLValue/Map.test.ts +++ b/packages/types/src/CLValue/Map.test.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import { CLBool, CLI32, diff --git a/packages/types/src/CLValue/Numeric.test.ts b/packages/types/src/CLValue/Numeric.test.ts index 73196d645..ec9b4ea9c 100644 --- a/packages/types/src/CLValue/Numeric.test.ts +++ b/packages/types/src/CLValue/Numeric.test.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import { CLI32, CLI32Type, diff --git a/packages/types/src/CLValue/Option.test.ts b/packages/types/src/CLValue/Option.test.ts index 1a0d55c9f..2311c3af8 100644 --- a/packages/types/src/CLValue/Option.test.ts +++ b/packages/types/src/CLValue/Option.test.ts @@ -1,4 +1,3 @@ -import { expect } from 'chai'; import { None, Some } from 'ts-results'; import { diff --git a/packages/types/src/CLValue/PublicKey.test.ts b/packages/types/src/CLValue/PublicKey.test.ts index c8e7270b8..ec5af20d1 100644 --- a/packages/types/src/CLValue/PublicKey.test.ts +++ b/packages/types/src/CLValue/PublicKey.test.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import { SignatureAlgorithm } from '../types'; import { CLPublicKey, diff --git a/packages/types/src/CLValue/Result.test.ts b/packages/types/src/CLValue/Result.test.ts index 039932a9e..74d2770f6 100644 --- a/packages/types/src/CLValue/Result.test.ts +++ b/packages/types/src/CLValue/Result.test.ts @@ -1,4 +1,3 @@ -import { expect } from 'chai'; import { Err, Ok, Some } from 'ts-results'; import { diff --git a/packages/types/src/CLValue/String.test.ts b/packages/types/src/CLValue/String.test.ts index 16ac79165..0b55ce983 100644 --- a/packages/types/src/CLValue/String.test.ts +++ b/packages/types/src/CLValue/String.test.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import { CLString, CLStringType, CLValueParsers } from './index'; describe('CLString', () => { diff --git a/packages/types/src/CLValue/Tuple.test.ts b/packages/types/src/CLValue/Tuple.test.ts index 1ffd48c62..6a5caaa91 100644 --- a/packages/types/src/CLValue/Tuple.test.ts +++ b/packages/types/src/CLValue/Tuple.test.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import { CLBool, CLBoolType, diff --git a/packages/types/src/CLValue/URef.test.ts b/packages/types/src/CLValue/URef.test.ts index c98cf07e9..101211e9e 100644 --- a/packages/types/src/CLValue/URef.test.ts +++ b/packages/types/src/CLValue/URef.test.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import { decodeBase16 } from '../Conversions'; import { AccessRights, CLURef, CLURefType, CLValueParsers } from './index'; diff --git a/packages/types/src/CLValue/Unit.test.ts b/packages/types/src/CLValue/Unit.test.ts index 6c70f5d07..628467333 100644 --- a/packages/types/src/CLValue/Unit.test.ts +++ b/packages/types/src/CLValue/Unit.test.ts @@ -1,5 +1,3 @@ -import { expect } from 'chai'; - import { CLUnit, CLValueParsers } from './index'; describe('Unit implementation tests', () => { diff --git a/packages/types/src/ChecksummedHex.test.ts b/packages/types/src/ChecksummedHex.test.ts index b9cd5c580..a9b1b6770 100644 --- a/packages/types/src/ChecksummedHex.test.ts +++ b/packages/types/src/ChecksummedHex.test.ts @@ -1,5 +1,3 @@ -import chai from 'chai'; - import { encode, isChecksummed, @@ -7,10 +5,6 @@ import { SMALL_BYTES_COUNT } from './ChecksummedHex'; -chai.should(); - -const { assert } = chai; - describe('ChecksumedHex', () => { it('should decode empty input', () => { const empty = ''; diff --git a/packages/types/src/StoredValue.test.ts b/packages/types/src/StoredValue.test.ts index b1f424baa..7e9189b98 100644 --- a/packages/types/src/StoredValue.test.ts +++ b/packages/types/src/StoredValue.test.ts @@ -1,4 +1,3 @@ -import { expect } from 'chai'; import camelCase from 'lodash/camelCase'; import mapKeys from 'lodash/mapKeys'; import { TypedJSON } from 'typedjson'; From fcfdec60302d24f4f2856e1cfa7cac91a561d62c Mon Sep 17 00:00:00 2001 From: ryo-casper Date: Mon, 15 Apr 2024 03:25:42 -0400 Subject: [PATCH 7/7] update codecov config --- codecov.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codecov.yml b/codecov.yml index 2fff88d41..6fad35b39 100644 --- a/codecov.yml +++ b/codecov.yml @@ -18,10 +18,10 @@ component_management: target: 80% individual_components: - - component_id: '@casper-js-sdk/types' + - component_id: 'casper-js-types' paths: - /packages/types/src/ - - component_id: '@casper-js-sdk/keys' + - component_id: 'casper-js-keys' paths: - /packages/keys/src/