Skip to content

Commit

Permalink
test: migrate types unit tests to vitest (#6224)
Browse files Browse the repository at this point in the history
* Migrate type tests to vitest

* Fix the npm scripts
  • Loading branch information
nazarhussain authored Dec 28, 2023
1 parent 82d7bc2 commit 4c6c33e
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 33 deletions.
9 changes: 0 additions & 9 deletions packages/types/karma.config.cjs

This file was deleted.

11 changes: 7 additions & 4 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@
"check-types": "tsc",
"lint": "eslint --color --ext .ts src/ test/",
"lint:fix": "yarn run lint --fix",
"test:unit": "yarn test:constants:minimal && yarn test:constants:mainnet && mocha 'test/unit/**/*.test.ts'",
"test:constants:minimal": "LODESTAR_PRESET=minimal mocha 'test/constants/**/*.test.ts'",
"test:constants:mainnet": "LODESTAR_PRESET=mainnet mocha 'test/constants/**/*.test.ts'",
"test:browsers": "yarn karma start karma.config.cjs",
"test:constants:minimal": "LODESTAR_PRESET=minimal vitest --run --dir test/constants/ --coverage",
"test:constants:mainnet": "LODESTAR_PRESET=mainnet vitest --run --dir test/constants/ --coverage",
"test:unit": "yarn test:constants:minimal && yarn test:constants:mainnet && vitest --run --dir test/unit/ --coverage",
"test:browsers": "yarn test:browsers:chrome && yarn test:browsers:firefox && yarn test:browsers:electron",
"test:browsers:chrome": "vitest --run --browser chrome --config ./vitest.browser.config.ts --dir test/unit",
"test:browsers:firefox": "vitest --run --browser firefox --config ./vitest.browser.config.ts --dir test/unit",
"test:browsers:electron": "echo 'Electron tests will be introduced back in the future as soon vitest supports electron.'",
"check-readme": "typescript-docs-verifier"
},
"types": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/test/constants/blobs.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expect} from "chai";
import {describe, it, expect} from "vitest";
import * as constants from "@lodestar/params";
import {ssz} from "../../src/index.js";

Expand Down
4 changes: 2 additions & 2 deletions packages/types/test/constants/lightclient.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expect} from "chai";
import {describe, it, expect} from "vitest";
import * as constants from "@lodestar/params";
import {ssz} from "../../src/index.js";

Expand Down Expand Up @@ -26,7 +26,7 @@ describe(`${constants.ACTIVE_PRESET}/ Lightclient pre-computed constants`, () =>

for (const [key, expectedValue] of Object.entries(correctConstants)) {
it(key, () => {
expect((constants as unknown as Record<string, number>)[key]).to.equal(expectedValue);
expect((constants as unknown as Record<string, number>)[key]).toBe(expectedValue);
});
}
});
Expand Down
2 changes: 2 additions & 0 deletions packages/types/test/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export async function setup(): Promise<void> {}
export async function teardown(): Promise<void> {}
10 changes: 5 additions & 5 deletions packages/types/test/unit/ssz.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {expect} from "chai";
import {describe, it, expect} from "vitest";
import {ssz} from "../../src/index.js";

describe("size", function () {
it("should calculate correct minSize and maxSize", () => {
const minSize = ssz.phase0.BeaconState.minSize;
const maxSize = ssz.phase0.BeaconState.maxSize;
// https://gist.github.com/protolambda/db75c7faa1e94f2464787a480e5d613e
expect(minSize).to.be.equal(2687377);
expect(maxSize).to.be.equal(141837543039377);
expect(minSize).toBe(2687377);
expect(maxSize).toBe(141837543039377);
});
});

Expand All @@ -24,7 +24,7 @@ describe("container serialization/deserialization field casing(s)", function ()

const result = ssz.phase0.AttesterSlashing.fromJson(json);
const back = ssz.phase0.AttesterSlashing.toJson(result);
expect(back).to.be.deep.equal(json);
expect(back).toEqual(json);
});

it("ProposerSlashing", function () {
Expand All @@ -39,6 +39,6 @@ describe("container serialization/deserialization field casing(s)", function ()

const result = ssz.phase0.ProposerSlashing.fromJson(json);
const back = ssz.phase0.ProposerSlashing.toJson(result);
expect(back).to.be.deep.equal(json);
expect(back).toEqual(json);
});
});
7 changes: 0 additions & 7 deletions packages/types/tsconfig.e2e.json

This file was deleted.

14 changes: 14 additions & 0 deletions packages/types/vitest.browser.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {defineConfig, mergeConfig} from "vitest/config";
import vitestConfig from "../../vitest.base.browser.config";

export default mergeConfig(
vitestConfig,
defineConfig({
test: {
globalSetup: ["./test/globalSetup.ts"],
},
optimizeDeps: {
exclude: ["@chainsafe/blst"],
},
})
);
11 changes: 11 additions & 0 deletions packages/types/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {defineConfig, mergeConfig} from "vitest/config";
import vitestConfig from "../../vitest.base.config";

export default mergeConfig(
vitestConfig,
defineConfig({
test: {
globalSetup: ["./test/globalSetup.ts"],
},
})
);
5 changes: 0 additions & 5 deletions packages/types/webpack.test.config.cjs

This file was deleted.

0 comments on commit 4c6c33e

Please sign in to comment.