1
0
Fork 0
mirror of synced 2024-08-12 16:41:26 +12:00

Merge pull request #11412 from Budibase/chore/typecheck_tests

Chore - Fix type checks on tests
This commit is contained in:
Adria Navarro 2023-08-01 17:10:30 +01:00 committed by GitHub
commit 039207255b
25 changed files with 71 additions and 65 deletions

View file

@ -3,7 +3,7 @@
"default": {
"runner": "nx-cloud",
"options": {
"cacheableOperations": ["build", "test"],
"cacheableOperations": ["build", "test", "check:types"],
"accessToken": "MmM4OGYxNzItMDBlYy00ZmE3LTk4MTYtNmJhYWMyZjBjZTUyfHJlYWQ="
}
}

View file

@ -36,7 +36,7 @@
"bootstrap": "./scripts/link-dependencies.sh && echo '***BOOTSTRAP ONLY REQUIRED FOR USE WITH ACCOUNT PORTAL***'",
"build": "yarn nx run-many -t=build",
"build:dev": "lerna run --stream prebuild && yarn nx run-many --target=build --output-style=dynamic --watch --preserveWatchOutput",
"check:types": "lerna run check:types --skip-nx-cache",
"check:types": "lerna run check:types",
"backend:bootstrap": "./scripts/scopeBackend.sh && yarn run bootstrap",
"backend:build": "./scripts/scopeBackend.sh 'lerna run --stream build'",
"build:sdk": "lerna run --stream build:sdk",

View file

@ -16,6 +16,7 @@
"prepack": "cp package.json dist",
"build": "tsc -p tsconfig.build.json",
"build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput",
"check:types": "tsc -p tsconfig.json --noEmit --paths null",
"test": "bash scripts/test.sh",
"test:watch": "jest --watchAll"
},

View file

@ -36,7 +36,7 @@ describe("writethrough", () => {
_id: docId,
value: 1,
})
const output = await db.get(response.id)
const output = await db.get<any>(response.id)
current = output
expect(output.value).toBe(1)
})
@ -45,7 +45,7 @@ describe("writethrough", () => {
it("second put shouldn't update DB", async () => {
await config.doInTenant(async () => {
const response = await writethrough.put({ ...current, value: 2 })
const output = await db.get(response.id)
const output = await db.get<any>(response.id)
expect(current._rev).toBe(output._rev)
expect(output.value).toBe(1)
})
@ -55,7 +55,7 @@ describe("writethrough", () => {
await config.doInTenant(async () => {
tk.freeze(Date.now() + DELAY + 1)
const response = await writethrough.put({ ...current, value: 3 })
const output = await db.get(response.id)
const output = await db.get<any>(response.id)
expect(response.rev).not.toBe(current._rev)
expect(output.value).toBe(3)
@ -79,7 +79,7 @@ describe("writethrough", () => {
expect.arrayContaining([current._rev, current._rev, newRev])
)
const output = await db.get(current._id)
const output = await db.get<any>(current._id)
expect(output.value).toBe(4)
expect(output._rev).toBe(newRev)
@ -107,7 +107,7 @@ describe("writethrough", () => {
})
expect(res.ok).toBe(true)
const output = await db.get(id)
const output = await db.get<any>(id)
expect(output.value).toBe(3)
expect(output._rev).toBe(res.rev)
})
@ -130,8 +130,8 @@ describe("writethrough", () => {
const resp2 = await writethrough2.put({ _id: "db1", value: "second" })
expect(resp1.rev).toBeDefined()
expect(resp2.rev).toBeDefined()
expect((await db.get("db1")).value).toBe("first")
expect((await db2.get("db1")).value).toBe("second")
expect((await db.get<any>("db1")).value).toBe("first")
expect((await db2.get<any>("db1")).value).toBe("second")
})
})
})

View file

@ -1,5 +1,3 @@
import * as events from "../../../../src/events"
beforeAll(async () => {
const processors = await import("../../../../src/events/processors")
const events = await import("../../../../src/events")

View file

@ -7,6 +7,5 @@
"@budibase/types": ["../types/src"]
}
},
"exclude": ["node_modules", "dist"]
}

View file

@ -140,6 +140,18 @@
}
]
},
"dev:builder": {
"dependsOn": [
{
"projects": [
"@budibase/string-templates",
"@budibase/shared-core",
"@budibase/types"
],
"target": "build"
}
]
},
"test": {
"dependsOn": [
{

View file

@ -14,6 +14,7 @@
"tsc": "tsc -p tsconfig.build.json",
"pkg": "pkg . --out-path build --no-bytecode --public --public-packages \"*\" -C GZip",
"build": "yarn prebuild && yarn rename && yarn tsc && yarn pkg && yarn postbuild",
"check:types": "tsc -p tsconfig.json --noEmit --paths null",
"postbuild": "rm -rf prebuilds 2> /dev/null"
},
"pkg": {
@ -45,7 +46,7 @@
"lookpath": "1.1.0",
"node-fetch": "2.6.7",
"pkg": "5.8.0",
"posthog-node": "1.0.7",
"posthog-node": "1.3.0",
"pouchdb": "7.3.0",
"pouchdb-replication-stream": "1.2.9",
"randomstring": "1.1.5",

View file

@ -11,7 +11,7 @@
"scripts": {
"prebuild": "rimraf dist/",
"build": "node ./scripts/build.js",
"check:types": "tsc -p tsconfig.build.json --noEmit",
"check:types": "tsc -p tsconfig.json --noEmit --paths null",
"postbuild": "copyfiles -f ../client/dist/budibase-client.js ../client/manifest.json client",
"build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput",
"debug": "yarn build && node --expose-gc --inspect=9222 dist/index.js",

View file

@ -22,6 +22,10 @@ jest.mock(
}))
)
const mockedOpenAIApi = openai.OpenAIApi as jest.MockedClass<
typeof openai.OpenAIApi
>
const OPENAI_PROMPT = "What is the meaning of life?"
describe("test the openai action", () => {
@ -68,11 +72,16 @@ describe("test the openai action", () => {
})
it("should present the correct error message when an error is thrown from the createChatCompletion call", async () => {
openai.OpenAIApi.mockImplementation(() => ({
createChatCompletion: jest.fn(() => {
throw new Error("An error occurred while calling createChatCompletion")
}),
}))
mockedOpenAIApi.mockImplementation(
() =>
({
createChatCompletion: jest.fn(() => {
throw new Error(
"An error occurred while calling createChatCompletion"
)
}),
} as any)
)
const res = await setup.runStep("OPENAI", {
prompt: OPENAI_PROMPT,

View file

@ -30,7 +30,7 @@ GoogleSpreadsheet.mockImplementation(() => mockGoogleIntegration)
import { structures } from "@budibase/backend-core/tests"
import TestConfiguration from "../../tests/utilities/TestConfiguration"
import GoogleSheetsIntegration from "../googlesheets"
import { FieldType, Table, TableSchema } from "../../../../types/src/documents"
import { FieldType, Table, TableSchema } from "@budibase/types"
describe("Google Sheets Integration", () => {
let integration: any,

View file

@ -17,7 +17,7 @@ tk.freeze(timestamp)
const clearMigrations = async () => {
const dbs = [context.getDevAppDB(), context.getProdAppDB()]
for (const db of dbs) {
const doc = await db.get(DocumentType.MIGRATIONS)
const doc = await db.get<any>(DocumentType.MIGRATIONS)
const newDoc = { _id: doc._id, _rev: doc._rev }
await db.put(newDoc)
}
@ -52,7 +52,7 @@ describe("migrations", () => {
await config.createTable()
await config.createView()
await config.createTable()
await config.createView(structures.view(config.table._id))
await config.createView(structures.view(config.table!._id!))
await config.createScreen()
await config.createScreen()

View file

@ -1,18 +1,19 @@
import { fixAutoColumnSubType } from "../utils"
import { AutoFieldDefaultNames, AutoFieldSubTypes } from "../../../constants"
import { FieldSchema, FieldType, RelationshipType } from "@budibase/types"
describe("rowProcessor utility", () => {
describe("fixAutoColumnSubType", () => {
let schema = {
let schema: FieldSchema = {
name: "",
type: "link",
type: FieldType.LINK,
subtype: "", // missing subtype
icon: "ri-magic-line",
autocolumn: true,
constraints: { type: "array", presence: false },
tableId: "ta_users",
fieldName: "test-Updated By",
relationshipType: "many-to-many",
relationshipType: RelationshipType.MANY_TO_MANY,
sortable: false,
}

View file

@ -5,7 +5,7 @@ import {
FormulaTypes,
} from "../../constants"
import { processStringSync } from "@budibase/string-templates"
import { FieldSchema, FieldType, Row, Table } from "@budibase/types"
import { FieldSchema, Row, Table } from "@budibase/types"
/**
* If the subtype has been lost for any reason this works out what

View file

@ -2,15 +2,12 @@
"extends": "./tsconfig.build.json",
"compilerOptions": {
"composite": true,
"declaration": true,
"sourceMap": true,
"baseUrl": ".",
"outDir": "dist"
"baseUrl": "."
},
"ts-node": {
"require": ["tsconfig-paths/register"],
"swc": true
},
"include": ["src/**/*", "specs"],
"include": ["src/**/*", "specs", "__mocks__"],
"exclude": ["node_modules", "dist"]
}

View file

@ -17,7 +17,8 @@
"prebuild": "rimraf dist/",
"build": "tsc -p tsconfig.build.json && tsc -p tsconfig-cjs.build.json",
"build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput",
"dev:builder": "yarn prebuild && concurrently \"tsc -p tsconfig.build.json --watch\" \"tsc -p tsconfig-cjs.build.json --watch\""
"dev:builder": "yarn prebuild && concurrently \"tsc -p tsconfig.build.json --watch\" \"tsc -p tsconfig-cjs.build.json --watch\"",
"check:types": "tsc -p tsconfig.json --noEmit --paths null"
},
"dependencies": {
"@budibase/types": "0.0.0"

View file

@ -6,5 +6,7 @@
"paths": {
"@budibase/types": ["../types/src"]
}
}
},
"include": ["**/*.js", "**/*.ts"],
"exclude": ["node_modules", "dist"]
}

View file

@ -16,7 +16,8 @@
"prebuild": "rimraf dist/",
"build": "tsc -p tsconfig.build.json && tsc -p tsconfig-cjs.build.json",
"build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput",
"dev:builder": "yarn prebuild && concurrently \"tsc -p tsconfig.build.json --watch\" \"tsc -p tsconfig-cjs.build.json --watch\""
"dev:builder": "yarn prebuild && concurrently \"tsc -p tsconfig.build.json --watch\" \"tsc -p tsconfig-cjs.build.json --watch\"",
"check:types": "tsc -p tsconfig.json --noEmit --paths null"
},
"jest": {},
"devDependencies": {

View file

@ -3,8 +3,5 @@
"compilerOptions": {
"composite": true
},
"exclude": [
"node_modules",
"dist"
]
}
"exclude": ["node_modules", "dist"]
}

View file

@ -14,7 +14,7 @@
"scripts": {
"prebuild": "rimraf dist/",
"build": "node ../../scripts/build.js",
"check:types": "tsc -p tsconfig.build.json --noEmit",
"check:types": "tsc -p tsconfig.json --noEmit --paths null",
"build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput",
"run:docker": "node dist/index.js",
"debug": "yarn build && node --expose-gc --inspect=9223 dist/index.js",

View file

@ -206,7 +206,7 @@ describe("/api/global/auth", () => {
const newPassword = "newpassword"
const res = await config.api.auth.updatePassword(code!, newPassword)
user = await config.getUser(user.email)
user = (await config.getUser(user.email))!
delete user.password
expect(res.body).toEqual({ message: "password reset successfully." })

View file

@ -36,7 +36,7 @@ describe("/api/global/self", () => {
})
.expect(200)
const dbUser = await config.getUser(user.email)
const dbUser = (await config.getUser(user.email))!
user._rev = dbUser._rev
user.dayPassRecordedAt = mocks.date.MOCK_DATE.toISOString()
@ -58,7 +58,7 @@ describe("/api/global/self", () => {
})
.expect(200)
const dbUser = await config.getUser(user.email)
const dbUser = (await config.getUser(user.email))!
user._rev = dbUser._rev
user.dayPassRecordedAt = mocks.date.MOCK_DATE.toISOString()

View file

@ -1,3 +1,4 @@
import { HealthStatusResponse } from "@budibase/types"
import { TestConfiguration } from "../../../../tests"
import { accounts as _accounts } from "@budibase/backend-core"
const accounts = jest.mocked(_accounts)
@ -31,13 +32,15 @@ describe("/api/system/status", () => {
})
it("returns status in cloud", async () => {
const value = {
health: {
passing: false,
const value: HealthStatusResponse = {
passing: false,
checks: {
login: false,
search: false,
},
}
accounts.getStatus.mockReturnValueOnce(Promise.resolve(value))
accounts.getStatus.mockResolvedValue(value)
const res = await config.api.status.getStatus()

View file

@ -2,14 +2,12 @@
"extends": "./tsconfig.build.json",
"compilerOptions": {
"composite": true,
"declaration": true,
"sourceMap": true,
"baseUrl": "."
},
"ts-node": {
"require": ["tsconfig-paths/register"],
"swc": true
},
"include": ["src/**/*"],
"exclude": ["dist"]
"include": ["src/**/*", "__mocks__/**/*"],
"exclude": ["node_modules", "dist"]
}

View file

@ -20279,20 +20279,6 @@ posthog-js@^1.36.0:
fflate "^0.4.1"
rrweb-snapshot "^1.1.14"
posthog-node@1.0.7:
version "1.0.7"
resolved "https://registry.yarnpkg.com/posthog-node/-/posthog-node-1.0.7.tgz#a7a9525eebff23312117e57cff3ddac82afb2262"
integrity sha512-KTCwyU+PU1eAQtjy5ZSJ47mrxv2d/mMkxo+vvV5c+YqfE4mBAY1UPEPMv1nElb5Vq0UnxvyQXaUnOn8d8Xr6Eg==
dependencies:
axios "^0.21.1"
axios-retry "^3.1.9"
component-type "^1.2.1"
join-component "^1.1.0"
md5 "^2.3.0"
ms "^2.1.3"
remove-trailing-slash "^0.1.1"
uuid "^8.3.2"
posthog-node@1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/posthog-node/-/posthog-node-1.3.0.tgz#804ed2f213a2f05253f798bf9569d55a9cad94f7"