Merge pull request #4116 from mslourens/worker_typescript

Add typescript to worker project
This commit is contained in:
Martin McKeaveney 2022-02-01 10:05:11 +00:00 committed by GitHub
commit 725c65a69b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 1969 additions and 2093 deletions

View File

@ -36,10 +36,10 @@
"dev:server": "lerna run --parallel dev:builder --concurrency 1 --scope @budibase/worker --scope @budibase/server",
"test": "lerna run test",
"lint:eslint": "eslint packages",
"lint:prettier": "prettier --check \"packages/**/*.{js,svelte}\"",
"lint:prettier": "prettier --check \"packages/**/*.{js,ts,svelte}\"",
"lint": "yarn run lint:eslint && yarn run lint:prettier",
"lint:fix:eslint": "eslint --fix packages",
"lint:fix:prettier": "prettier --write \"packages/**/*.{js,svelte}\"",
"lint:fix:prettier": "prettier --write \"packages/**/*.{js,ts,svelte}\"",
"lint:fix:ts": "lerna run lint:fix",
"lint:fix": "yarn run lint:fix:ts && yarn run lint:fix:prettier && yarn run lint:fix:eslint",
"test:e2e": "lerna run cy:test",

View File

@ -40,7 +40,7 @@ async function run() {
// it will cause environment module to be loaded prematurely
const server = require("../../server/dist/app")
process.env.PORT = WORKER_PORT
const worker = require("../../worker/src/index")
const worker = require("../../worker/dist/index")
// reload main port for rest of system
process.env.PORT = MAIN_PORT
server.on("close", () => console.log("Server Closed"))

View File

@ -9,7 +9,7 @@ module ArangoMock {
this.close = jest.fn()
}
// @ts-ignore
// @ts-ignore
arangodb.aql = (strings, ...args) => {
let str = strings.join("{}")

View File

@ -1,7 +1,7 @@
module AwsMock {
const aws: any = {}
const response = (body: any) => () => ({promise: () => body})
const response = (body: any) => () => ({ promise: () => body })
function DocumentClient() {
// @ts-ignore
@ -39,9 +39,9 @@ module AwsMock {
)
}
aws.DynamoDB = {DocumentClient}
aws.DynamoDB = { DocumentClient }
aws.S3 = S3
aws.config = {update: jest.fn()}
aws.config = { update: jest.fn() }
module.exports = aws
}

View File

@ -5,15 +5,14 @@ module MongoMock {
this.connect = jest.fn()
this.close = jest.fn()
this.insertOne = jest.fn()
this.insertMany = jest.fn(() => ({toArray: () => []}))
this.find = jest.fn(() => ({toArray: () => []}))
this.insertMany = jest.fn(() => ({ toArray: () => [] }))
this.find = jest.fn(() => ({ toArray: () => [] }))
this.findOne = jest.fn()
this.count = jest.fn()
this.deleteOne = jest.fn()
this.deleteMany = jest.fn(() => ({toArray: () => []}))
this.deleteMany = jest.fn(() => ({ toArray: () => [] }))
this.updateOne = jest.fn()
this.updateMany = jest.fn(() => ({toArray: () => []}))
this.updateMany = jest.fn(() => ({ toArray: () => [] }))
this.collection = jest.fn(() => ({
insertOne: this.insertOne,

View File

@ -10,12 +10,12 @@ module MsSqlMock {
],
}))
// mssql.connect = jest.fn(() => ({ recordset: [] }))
// mssql.connect = jest.fn(() => ({ recordset: [] }))
mssql.ConnectionPool = jest.fn(() => ({
connect: jest.fn(() => ({
request: jest.fn(() => ({
query: jest.fn(sql => ({ recordset: [ sql ] })),
query: jest.fn(sql => ({ recordset: [sql] })),
})),
})),
}))

View File

@ -62,7 +62,8 @@ module FetchMock {
return json({
url,
opts,
value: "<!doctype html><html itemscope=\"\" itemtype=\"http://schema.org/WebPage\" lang=\"en-GB\"></html>",
value:
'<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-GB"></html>',
})
} else if (url.includes("failonce.com")) {
failCount++

View File

@ -10,16 +10,14 @@ module PgMock {
],
}))
// constructor
function Client() {
}
// constructor
function Client() {}
Client.prototype.query = query
Client.prototype.connect = jest.fn()
Client.prototype.release = jest.fn()
function Pool() {
}
function Pool() {}
const on = jest.fn()
Pool.prototype.query = query

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,7 @@
"emit": true,
"key": true
},
"parser": "@typescript-eslint/parser",
"env": {
"node": true
},

View File

@ -1,3 +1,4 @@
node_modules/
.env
watchtower-hook.json
dist/

View File

@ -1,3 +1,6 @@
{
"watch": ["src", "../backend-core"]
"watch": ["src", "../backend-core"],
"ext": "js,ts,json",
"ignore": ["src/**/*.spec.ts", "src/**/*.spec.js"],
"exec": "ts-node src/index.ts"
}

View File

@ -3,7 +3,7 @@
"email": "hi@budibase.com",
"version": "1.0.49-alpha.4",
"description": "Budibase background service",
"main": "src/index.js",
"main": "src/index.ts",
"repository": {
"type": "git",
"url": "https://github.com/Budibase/budibase.git"
@ -12,10 +12,15 @@
"budibase"
],
"scripts": {
"run:docker": "node src/index.js",
"build": "rimraf dist/ && tsc",
"postbuild": "copyfiles -u 1 src/**/*.hbs dist/",
"run:docker": "node dist/index.js",
"build:docker": "docker build . -t worker-service --label version=$BUDIBASE_RELEASE_VERSION",
"dev:stack:init": "node ./scripts/dev/manage.js init",
"dev:builder": "npm run dev:stack:init && nodemon",
"format": "prettier --config ../../.prettierrc.json 'src/**/*.ts' --write",
"lint": "eslint --fix src/",
"lint:fix": "yarn run format && yarn run lint",
"test": "jest --runInBand",
"env:multi:enable": "node scripts/multiTenancy.js enable",
"env:multi:disable": "node scripts/multiTenancy.js disable",
@ -58,13 +63,26 @@
"server-destroy": "^1.0.1"
},
"devDependencies": {
"jest": "^26.6.3",
"@types/jest": "^26.0.23",
"@types/koa": "^2.13.3",
"@types/koa-router": "^7.4.2",
"@types/node": "^15.12.4",
"@typescript-eslint/parser": "4.28.0",
"copyfiles": "^2.4.1",
"eslint": "^6.8.0",
"jest": "^27.0.5",
"nodemon": "^2.0.7",
"pouchdb-adapter-memory": "^7.2.2",
"prettier": "2.3.1",
"rimraf": "^3.0.2",
"supertest": "^6.1.3",
"ts-jest": "^27.0.3",
"ts-node": "^10.0.0",
"typescript": "4.3.5",
"update-dotenv": "^1.1.1"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"setupFiles": [
"./scripts/jestSetup.js"

View File

@ -1,10 +1,9 @@
jest.mock("nodemailer")
const setup = require("./utilities")
const sendMailMock = setup.emailMock()
const TENANT_ID = "default"
jest.mock("nodemailer")
const sendMailMock = setup.emailMock()
describe("/api/global/auth", () => {
let request = setup.getRequest()
let config = setup.getConfig()

View File

@ -1,11 +1,7 @@
const setup = require("./utilities")
// mock the email system
jest.mock("nodemailer")
const nodemailer = require("nodemailer")
nodemailer.createTransport.mockReturnValue({
verify: jest.fn(),
})
const setup = require("./utilities")
setup.emailMock()
describe("/api/global/configs/checklist", () => {
let request = setup.getRequest()

View File

@ -1,16 +1,10 @@
jest.mock("nodemailer")
const setup = require("./utilities")
const sendMailMock = setup.emailMock()
const { EmailTemplatePurpose } = require("../../../constants")
const { TENANT_ID } = require("./utilities/structures")
// mock the email system
const sendMailMock = jest.fn()
jest.mock("nodemailer")
const nodemailer = require("nodemailer")
nodemailer.createTransport.mockReturnValue({
sendMail: sendMailMock,
verify: jest.fn(),
})
describe("/api/global/email", () => {
let request = setup.getRequest()
let config = setup.getConfig()

View File

@ -1,7 +1,5 @@
const setup = require("./utilities")
const { TENANT_ID } = require("./utilities/structures")
jest.mock("nodemailer")
const setup = require("./utilities")
const sendMailMock = setup.emailMock()
describe("/api/global/users", () => {

View File

@ -1,4 +1,8 @@
// need to load environment first
import { Scope } from "@sentry/node"
import { Event } from "@sentry/types/dist/event"
import Application from "koa"
const env = require("./environment")
const CouchDB = require("./db")
require("@budibase/backend-core").init(CouchDB)
@ -13,7 +17,7 @@ const api = require("./api")
const redis = require("./utilities/redis")
const Sentry = require("@sentry/node")
const app = new Koa()
const app: Application = new Koa()
app.keys = ["secret", "key"]
@ -42,8 +46,8 @@ if (env.isProd()) {
Sentry.init()
app.on("error", (err, ctx) => {
Sentry.withScope(function (scope) {
scope.addEventProcessor(function (event) {
Sentry.withScope(function (scope: Scope) {
scope.addEventProcessor(function (event: Event) {
return Sentry.Handlers.parseRequest(event, ctx.request)
})
Sentry.captureException(err)

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": ["es2019"],
"allowJs": true,
"outDir": "dist",
"strict": true,
"noImplicitAny": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"incremental": true
},
"include": [
"./src/**/*"
],
"exclude": [
"node_modules",
"**/*.json",
"**/*.spec.ts",
"**/*.spec.js"
]
}

File diff suppressed because it is too large Load Diff