Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add jest coverage #8

Merged
merged 2 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading