Skip to content

Commit

Permalink
🆙 update @codechecks/client, add default export to make it work with …
Browse files Browse the repository at this point in the history
…declarative configs
  • Loading branch information
krzkaczor committed Mar 31, 2019
1 parent 830bf64 commit 9f032d6
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 42 deletions.
21 changes: 6 additions & 15 deletions jest.config.js
@@ -1,17 +1,8 @@
module.exports = {
"roots": [
"<rootDir>/src"
],
"transform": {
"^.+\\.tsx?$": "ts-jest"
roots: ["<rootDir>/src"],
transform: {
"^.+\\.tsx?$": "ts-jest",
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
}
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
};
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -35,7 +35,7 @@
"prepublishOnly": "yarn test && yarn build"
},
"devDependencies": {
"@codechecks/client": "^0.0.48",
"@codechecks/client": "^0.0.52",
"@types/jest": "^23.3.12",
"@types/lodash": "^4.14.121",
"@types/node": "^10.12.18",
Expand Down
4 changes: 2 additions & 2 deletions src/__mocks__/@codechecks/client.ts
@@ -1,7 +1,7 @@
import * as CodeChecks from "@codechecks/client";
import * as CC from "@codechecks/client";
import { join } from "path";

export const codeChecks: Partial<typeof CodeChecks.codeChecks> = {
export const codechecks: Partial<typeof CC.codechecks> = {
report: jest.fn(),
success: jest.fn(),
failure: jest.fn(),
Expand Down
26 changes: 13 additions & 13 deletions src/__tests__/index.spec.ts
@@ -1,17 +1,17 @@
import { typeCoverageWatcher } from "../index";
import { lint } from "type-coverage";
import { codeChecks } from "@codechecks/client";
import { codechecks } from "@codechecks/client";
import { TypeCoverageArtifact, RawTypeCoverageReport } from "../types";

type Mocked<T> = { [k in keyof T]: jest.Mock<T[k]> };

describe("type-coverage", () => {
const codeChecksMock = require("../__mocks__/@codechecks/client").codeChecks as Mocked<typeof codeChecks>;
const codechecksMock = require("../__mocks__/@codechecks/client").codechecks as Mocked<typeof codechecks>;
const typeCoverageMock = require("../__mocks__/type-coverage").lint as jest.Mock<typeof lint>;
beforeEach(() => jest.resetAllMocks());

it("should work not in PR context", async () => {
codeChecksMock.isPr.mockReturnValue(false);
codechecksMock.isPr.mockReturnValue(false);
typeCoverageMock.mockReturnValue({
correctCount: 2,
totalCount: 2,
Expand All @@ -21,8 +21,8 @@ describe("type-coverage", () => {

await typeCoverageWatcher({ tsconfigPath: "./tsconfig.json" });

expect(codeChecks.report).toBeCalledTimes(0);
expect(codeChecks.saveValue).toMatchInlineSnapshot(`
expect(codechecks.report).toBeCalledTimes(0);
expect(codechecks.saveValue).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
Expand All @@ -45,8 +45,8 @@ describe("type-coverage", () => {
});

it("should work in PR context", async () => {
codeChecksMock.isPr.mockReturnValue(true);
codeChecksMock.getValue.mockReturnValue({
codechecksMock.isPr.mockReturnValue(true);
codechecksMock.getValue.mockReturnValue({
typedSymbols: 2,
totalSymbols: 4,
allUntypedSymbols: [
Expand All @@ -66,7 +66,7 @@ describe("type-coverage", () => {
} as RawTypeCoverageReport);

await typeCoverageWatcher({ tsconfigPath: "./tsconfig.json" });
expect(codeChecks.report).toMatchInlineSnapshot(`
expect(codechecks.report).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
Expand All @@ -89,8 +89,8 @@ describe("type-coverage", () => {
});

it("should work in PR context 2", async () => {
codeChecksMock.isPr.mockReturnValue(true);
codeChecksMock.getValue.mockReturnValue({
codechecksMock.isPr.mockReturnValue(true);
codechecksMock.getValue.mockReturnValue({
typedSymbols: 4,
totalSymbols: 5,
allUntypedSymbols: [],
Expand All @@ -103,7 +103,7 @@ describe("type-coverage", () => {
} as RawTypeCoverageReport);

await typeCoverageWatcher({ tsconfigPath: "./tsconfig.json" });
expect(codeChecks.report).toMatchInlineSnapshot(`
expect(codechecks.report).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
Expand All @@ -130,7 +130,7 @@ describe("type-coverage", () => {
});

it("should work in PR context without baseline", async () => {
codeChecksMock.isPr.mockReturnValue(true);
codechecksMock.isPr.mockReturnValue(true);
typeCoverageMock.mockReturnValue({
correctCount: 2,
totalCount: 2,
Expand All @@ -139,7 +139,7 @@ describe("type-coverage", () => {
});

await typeCoverageWatcher({ tsconfigPath: "./tsconfig.json" });
expect(codeChecks.report).toMatchInlineSnapshot(`
expect(codechecks.report).toMatchInlineSnapshot(`
[MockFunction] {
"calls": Array [
Array [
Expand Down
12 changes: 7 additions & 5 deletions src/index.ts
@@ -1,4 +1,4 @@
import { codeChecks, CodeChecksReport } from "@codechecks/client";
import { codechecks, CodeChecksReport } from "@codechecks/client";
import { lint as getTypeCoverageInfo } from "type-coverage";
import { RawTypeCoverageReport, TypeCoverageArtifact, Options, SymbolInfo } from "./types";
import { groupBy } from "lodash";
Expand All @@ -16,19 +16,21 @@ export async function typeCoverageWatcher(_options: Options): Promise<void> {
};
const _typeCoverage = await getTypeCoverageInfo(options.tsconfigPath, true, false);
const typeCoverage = normalizeTypeCoverage(_typeCoverage);
await codeChecks.saveValue(ARTIFACT_KEY, typeCoverage);
await codechecks.saveValue(ARTIFACT_KEY, typeCoverage);

if (!codeChecks.isPr()) {
if (!codechecks.isPr()) {
return;
}

const baseTypeCoverage = await codeChecks.getValue<TypeCoverageArtifact>(ARTIFACT_KEY);
const baseTypeCoverage = await codechecks.getValue<TypeCoverageArtifact>(ARTIFACT_KEY);

const report = getReport(typeCoverage, baseTypeCoverage);

await codeChecks.report(report);
await codechecks.report(report);
}

export default typeCoverageWatcher;

function getReport(
headTypeCoverageArtifact: TypeCoverageArtifact,
baseTypeCoverageArtifact: TypeCoverageArtifact | undefined,
Expand Down
14 changes: 8 additions & 6 deletions yarn.lock
Expand Up @@ -18,18 +18,20 @@
esutils "^2.0.2"
js-tokens "^4.0.0"

"@codechecks/client@^0.0.48":
version "0.0.48"
resolved "https://registry.yarnpkg.com/@codechecks/client/-/client-0.0.48.tgz#ffcbecfcdb0ecc34e8ce08a0872f804d29c1fbc6"
integrity sha512-VXNUFhgRejHhfv+QngqJZ2Ay6Wste4zN4B2SSMtKlwcp3drXPwBxcDBag7lueoUdguKwi1FXbnCYOP07b47fyQ==
"@codechecks/client@^0.0.52":
version "0.0.52"
resolved "https://registry.yarnpkg.com/@codechecks/client/-/client-0.0.52.tgz#72ac4e712adde3e8bbfc8b29f94297258c8bba45"
integrity sha512-Cq+DJFuo9pfXnFAv+Hi2DSr+1/yOGPrAfzBjpoqlrLweRlRnvnXcgAnrglj2GHryVaBPhiWqwENfr2q5SpormA==
dependencies:
bluebird "^3.5.3"
commander "^2.19.0"
glob "^7.1.3"
graceful-fs "^4.1.15"
json5 "^2.1.0"
mkdirp "^0.5.1"
ms "^2.1.1"
promise "^8.0.2"
request "^2.88.0"
request-promise "^4.2.2"
ts-essentials "^1.0.2"
ts-node "^8.0.2"
Expand Down Expand Up @@ -2111,7 +2113,7 @@ json-stringify-safe@~5.0.1:
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
integrity sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=

json5@2.x:
json5@2.x, json5@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.1.0.tgz#e7a0c62c48285c628d20a10b85c89bb807c32850"
integrity sha512-8Mh9h6xViijj36g7Dxi+Y4S6hNGV96vcJZr/SrlHh1LR/pEn/8j/+qIBbs44YKl69Lrfctp4QD+AdWLTMqEZAQ==
Expand Down Expand Up @@ -2972,7 +2974,7 @@ request-promise@^4.2.2:
stealthy-require "^1.1.1"
tough-cookie "^2.3.3"

request@^2.87.0:
request@^2.87.0, request@^2.88.0:
version "2.88.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef"
integrity sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==
Expand Down

0 comments on commit 9f032d6

Please sign in to comment.