From 0d810aa92e9b54493a2e075c3bb497b3857a2119 Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Wed, 11 Dec 2019 14:31:56 -0500 Subject: Add ts-jest to improve TS coverage reports --- package-lock.json | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 14 ++++++++++---- src/errors.test.ts | 27 ++++++++++++++++++++++++++ src/errors.ts | 2 ++ 4 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 src/errors.test.ts diff --git a/package-lock.json b/package-lock.json index ccf2ce1..4abcc11 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1098,6 +1098,15 @@ } } }, + "bs-logger": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.6.tgz", + "integrity": "sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==", + "dev": true, + "requires": { + "fast-json-stable-stringify": "2.x" + } + }, "bser": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", @@ -4251,6 +4260,12 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" }, + "lodash.memoize": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", + "integrity": "sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=", + "dev": true + }, "lodash.sortby": { "version": "4.7.0", "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", @@ -4318,6 +4333,12 @@ } } }, + "make-error": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.5.tgz", + "integrity": "sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g==", + "dev": true + }, "makeerror": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.11.tgz", @@ -6078,6 +6099,41 @@ "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz", "integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==" }, + "ts-jest": { + "version": "24.2.0", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-24.2.0.tgz", + "integrity": "sha512-Yc+HLyldlIC9iIK8xEN7tV960Or56N49MDP7hubCZUeI7EbIOTsas6rXCMB4kQjLACJ7eDOF4xWEO5qumpKsag==", + "dev": true, + "requires": { + "bs-logger": "0.x", + "buffer-from": "1.x", + "fast-json-stable-stringify": "2.x", + "json5": "2.x", + "lodash.memoize": "4.x", + "make-error": "1.x", + "mkdirp": "0.x", + "resolve": "1.x", + "semver": "^5.5", + "yargs-parser": "10.x" + }, + "dependencies": { + "camelcase": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz", + "integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=", + "dev": true + }, + "yargs-parser": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-10.1.0.tgz", + "integrity": "sha512-VCIyR1wJoEBZUqk5PA+oOBF6ypbwh5aNB3I50guxAL/quggdfs4TtNHQrSazFA3fYZ+tEqfs0zIGlv0c/rgjbQ==", + "dev": true, + "requires": { + "camelcase": "^4.1.0" + } + } + } + }, "tsc-watch": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/tsc-watch/-/tsc-watch-4.0.0.tgz", diff --git a/package.json b/package.json index f2d060f..2548e55 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,8 @@ "format": "prettier --write 'src/**/*.ts'", "lint": "eslint 'src/**/*.ts'", "lint:fix": "eslint --fix 'src/**/*.ts'", - "test": "tsc && jest", - "test:coverage": "tsc && jest --coverage", + "test": "jest", + "test:coverage": "jest --coverage", "tsc": "tsc" }, "author": "Kevin J Hoerr ", @@ -45,12 +45,18 @@ "jest": "^24.9.0", "prettier": "^1.19.1", "triple-beam": "^1.3.0", + "ts-jest": "^24.2.0", "tsc-watch": "^4.0.0" }, "jest": { + "preset": "ts-jest", "testEnvironment": "node", + "collectCoverageFrom": [ + "src/**/*.ts", + "!src/**/*.test.ts" + ], "roots": [ - "build/" + "src/" ] } -} +} \ No newline at end of file diff --git a/src/errors.test.ts b/src/errors.test.ts new file mode 100644 index 0000000..235c0d2 --- /dev/null +++ b/src/errors.test.ts @@ -0,0 +1,27 @@ +import { InvalidReportDocumentError, BranchNotFoundError } from "./errors"; + +describe("InvalidReportDocumentError", () => { + it("should have the correct name and default message", () => { + // Arrange + + // Act + const err = new InvalidReportDocumentError(); + + // Assert + expect(err.name).toEqual("InvalidReportDocumentError"); + expect(err.message).toEqual("Invalid report document"); + }); +}); + +describe("BranchNotFoundError", () => { + it("should have the correct name and default message", () => { + // Arrange + + // Act + const err = new BranchNotFoundError(); + + // Assert + expect(err.name).toEqual("BranchNotFoundError"); + expect(err.message).toEqual("Branch not found"); + }); +}); diff --git a/src/errors.ts b/src/errors.ts index 3af634d..6e8c32f 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -1,6 +1,7 @@ export class BranchNotFoundError extends Error { constructor() { super(); + this.name = "BranchNotFoundError"; this.message = "Branch not found"; } } @@ -8,6 +9,7 @@ export class BranchNotFoundError extends Error { export class InvalidReportDocumentError extends Error { constructor() { super(); + this.name = "InvalidReportDocumentError"; this.message = "Invalid report document"; } } -- cgit