From 756c080f0d8392eb39bb3f626aae4a2f2d34e886 Mon Sep 17 00:00:00 2001 From: shelly_goldblit Date: Sat, 22 Jun 2024 07:03:49 +0300 Subject: [PATCH 1/2] add jest coverage --- jest.config.ts | 7 ++++++- package.json | 2 +- src/stub-builder.cy.ts | 1 + src/stub-builder.test.ts | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/jest.config.ts b/jest.config.ts index 68c1e76..21a0d3a 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,7 +1,12 @@ import type { JestConfigWithTsJest } from "ts-jest"; const jestConfig: JestConfigWithTsJest = { - // [...] + coverageReporters: [ + "clover", + "json-summary", + "lcov", + ["text", { skipFull: false }] + ], transform: { // '^.+\\.[tj]sx?$' to process js/ts with `ts-jest` // '^.+\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest` diff --git a/package.json b/package.json index ff117a4..6f7e6fc 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "build": "rollup --configPlugin @rollup/plugin-typescript --config rollup.config.ts ", "cy:run": "cypress run", "cy:open": "cypress open", - "test": "jest", + "test": "jest --coverage", "generate-md-docs": "typedoc --includeVersion --plugin typedoc-plugin-markdown --plugin typedoc-plugin-merge-modules --options typedoc.md.json", "generate-docs": "typedoc --includeVersion --plugin typedoc-plugin-merge-modules --options typedoc.html.json", "deploy": "gh-pages -d docs" diff --git a/src/stub-builder.cy.ts b/src/stub-builder.cy.ts index 695b476..bdafac2 100644 --- a/src/stub-builder.cy.ts +++ b/src/stub-builder.cy.ts @@ -290,6 +290,7 @@ describe("Cypress stub builder tests with Sinon Stubs", () => { }); it("should stub class function", () => { + // creating a stubbed instance using sinon const mockMyClass = StubbedInstanceCreator(() => sinon.stub() ).createStubbedInstance(); diff --git a/src/stub-builder.test.ts b/src/stub-builder.test.ts index 8b52a6f..1c227ac 100644 --- a/src/stub-builder.test.ts +++ b/src/stub-builder.test.ts @@ -291,6 +291,7 @@ describe("Jest stub builder tests with Jest Mocks", () => { }); it("should have own property given property is set", () => { + // creating a stubbed instance using jest const mockMyClass = StubbedInstanceCreator(() => jest.fn() ).createStubbedInstance(); From 0619e9c60cfd0720be427cc67692b35c9abd5435 Mon Sep 17 00:00:00 2001 From: shelly_goldblit Date: Sat, 22 Jun 2024 07:09:35 +0300 Subject: [PATCH 2/2] publish the badge --- .github/workflows/npm-publish.yml | 2 ++ README.md | 1 + 2 files changed, 3 insertions(+) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 880def2..141a3c4 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -23,6 +23,8 @@ jobs: - run: npm run build - run: npm run test - run: npm run cy:run + - name: Update Coverage Badge + uses: we-cli/coverage-badge-action@main - name: Build the Docs run: | npm run generate-md-docs diff --git a/README.md b/README.md index 28e3934..12b5629 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # ts-stubber ![ts-stubber](https://github.com/ShellyDCMS/ts-stubber/actions/workflows/npm-publish.yml/badge.svg) +[![cov](https://ShellyDCMS.github.io/ts-stubber/badges/coverage.svg)](https://github.com/ShellyDCMS/ts-stubber/actions) A generic stubbed instance creator to lazy stub any interface/class, while completely avoiding calling class's constructor. Thus, enabling both avoiding side effects that may occur while class constructor is activated and mocking Classes with no default constructor.