Skip to content

Commit

Permalink
Merge pull request #8 from ShellyDCMS/add-jest-coverage
Browse files Browse the repository at this point in the history
add jest coverage
  • Loading branch information
ShellyDCMS authored Jun 22, 2024
2 parents 04550d7 + 0619e9c commit 3554345
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
7 changes: 6 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/stub-builder.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyClass, SinonStub>(() =>
sinon.stub()
).createStubbedInstance();
Expand Down
1 change: 1 addition & 0 deletions src/stub-builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyClass, jest.Mock>(() =>
jest.fn()
).createStubbedInstance();
Expand Down

0 comments on commit 3554345

Please sign in to comment.