From c58b0c0753d97713552d080fba36125af68afb65 Mon Sep 17 00:00:00 2001 From: Matt Gibson Date: Tue, 16 May 2023 10:20:40 -0400 Subject: [PATCH] Return error code when any tsc typecheck fails (#5459) * Return error code when any tsc typecheck fails * Try with bash `sh ./scripts/test-types.s` resulted in errors missing `[[`, which is a bash builtin. It's possible the ubuntu runner is using some other shell. * Fix spec type errors * Switch to node for Windows compatibility --- .eslintignore | 2 ++ .../models/data/server-config.data.spec.ts | 17 ++++------- .../src/services/import.service.spec.ts | 5 ++-- package.json | 2 +- scripts/test-types.js | 29 +++++++++++++++++++ 5 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 scripts/test-types.js diff --git a/.eslintignore b/.eslintignore index f34b968315..e1fbda3813 100644 --- a/.eslintignore +++ b/.eslintignore @@ -27,3 +27,5 @@ apps/cli/config/config.js tailwind.config.js libs/components/tailwind.config.base.js libs/components/tailwind.config.js + +scripts/*.js diff --git a/libs/common/src/models/data/server-config.data.spec.ts b/libs/common/src/models/data/server-config.data.spec.ts index 1c4e890ab8..30dc46cf1b 100644 --- a/libs/common/src/models/data/server-config.data.spec.ts +++ b/libs/common/src/models/data/server-config.data.spec.ts @@ -7,7 +7,7 @@ import { describe("ServerConfigData", () => { describe("fromJSON", () => { it("should create a ServerConfigData from a JSON object", () => { - const serverConfigData = ServerConfigData.fromJSON({ + const json = { version: "1.0.0", gitHash: "1234567890", server: { @@ -22,18 +22,11 @@ describe("ServerConfigData", () => { sso: "https://sso.com", }, utcDate: "2020-01-01T00:00:00.000Z", - }); + featureStates: { feature: "state" }, + }; + const serverConfigData = ServerConfigData.fromJSON(json); - expect(serverConfigData.version).toEqual("1.0.0"); - expect(serverConfigData.gitHash).toEqual("1234567890"); - expect(serverConfigData.server.name).toEqual("test"); - expect(serverConfigData.server.url).toEqual("https://test.com"); - expect(serverConfigData.environment.vault).toEqual("https://vault.com"); - expect(serverConfigData.environment.api).toEqual("https://api.com"); - expect(serverConfigData.environment.identity).toEqual("https://identity.com"); - expect(serverConfigData.environment.notifications).toEqual("https://notifications.com"); - expect(serverConfigData.environment.sso).toEqual("https://sso.com"); - expect(serverConfigData.utcDate).toEqual("2020-01-01T00:00:00.000Z"); + expect(serverConfigData).toEqual(json); }); it("should be an instance of ServerConfigData", () => { diff --git a/libs/importer/src/services/import.service.spec.ts b/libs/importer/src/services/import.service.spec.ts index 9dafaed14f..6dd6438b01 100644 --- a/libs/importer/src/services/import.service.spec.ts +++ b/libs/importer/src/services/import.service.spec.ts @@ -62,8 +62,9 @@ describe("ImportService", () => { }); it("has the promptForPassword_callback set", async () => { - expect(importer.promptForPassword_callback).not.toBeNull(); - expect(await importer.promptForPassword_callback()).toEqual(password); + // Cast to any to access private property. Note: assumes instance of BitwardenPasswordProtectedImporter + expect((importer as any).promptForPassword_callback).not.toBeNull(); + expect(await (importer as any).promptForPassword_callback()).toEqual(password); }); it("has the appropriate organization Id", () => { diff --git a/package.json b/package.json index c701317cdb..3a29fa4ab7 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "test": "jest", "test:watch": "jest --clearCache && jest --watch", "test:watch:all": "jest --watchAll", - "test:types": "for p in libs/**/tsconfig.spec.json; do echo \"Typechecking $p\"; tsc --noEmit --project $p; done", + "test:types": "node ./scripts/test-types.js", "docs:json": "compodoc -p ./tsconfig.json -e json -d .", "storybook": "npm run docs:json && start-storybook -p 6006", "build-storybook": "npm run docs:json && build-storybook", diff --git a/scripts/test-types.js b/scripts/test-types.js new file mode 100644 index 0000000000..0fc27f3646 --- /dev/null +++ b/scripts/test-types.js @@ -0,0 +1,29 @@ +const concurrently = require("concurrently"); +const path = require("path"); +const fs = require("fs"); + +function getFiles(dir) { + results = []; + fs.readdirSync(dir).forEach((file) => { + file = path.join(dir, file); + const stat = fs.statSync(file); + if (stat && stat.isDirectory()) { + results = results.concat(getFiles(file)); + } else { + results.push(file); + } + }); + return results; +} + +const files = getFiles(path.join(__dirname, "..", "libs")).filter((file) => { + const name = path.basename(file); + return name === "tsconfig.spec.json"; +}); + +concurrently( + files.map((file) => ({ + name: path.basename(path.dirname(file)), + command: `npx tsc --noEmit --project ${file}`, + })) +);