testing with jest

This commit is contained in:
Martin Berg Alstad 2024-12-16 21:25:36 +00:00
parent 9ed0a19393
commit c43bff3e15
5 changed files with 2706 additions and 46 deletions

19
jest.config.ts Normal file
View File

@ -0,0 +1,19 @@
import type { JestConfigWithTsJest } from "ts-jest"
const config: JestConfigWithTsJest = {
verbose: true,
transform: {
"^.+\\.ts?$": [
"ts-jest",
{
useESM: true,
},
],
},
extensionsToTreatAsEsm: [".ts"],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
}
export default config

View File

@ -5,23 +5,28 @@
"main": "index.js",
"scripts": {
"start": "node --import=tsx ./src/main.ts | pino-pretty",
"test": "node --test --experimental-strip-types ./tests/**",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"format": "prettier --write \"./**/*.{js,mjs,ts,md,json}\""
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@actual-app/api": "^24.11.0",
"cron": "^3.2.1",
"dotenv": "^16.4.5",
"@actual-app/api": "^24.12.0",
"cron": "^3.3.1",
"dotenv": "^16.4.7",
"pino": "^9.5.0",
"prettier": "^3.3.3"
"prettier": "^3.4.2"
},
"devDependencies": {
"@types/node": "^22.9.0",
"@jest/globals": "^29.7.0",
"@types/jest": "^29.5.14",
"@types/node": "^22.10.2",
"jest": "^29.7.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"tsx": "^4.19.2",
"typescript": "^5.6.3"
"typescript": "^5.7.2"
},
"prettier": {
"semi": false,

2696
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,12 @@
import { describe, it } from "node:test"
import { describe, expect, it } from "@jest/globals"
import { daily } from "@/main.ts"
import { ActualImpl } from "@/actual.ts"
import { BankStub } from "./stubs/bankStub.ts"
import assert from "node:assert"
describe("Main logic of the application", () => {
it("should import the transactions to Actual Budget", async () => {
await daily(await ActualImpl.init(), new BankStub())
assert.ok(true)
expect(true)
})
})

View File

@ -1,4 +1,8 @@
{
"include": [
"./src/**/*.ts",
"./tests/**/*.ts"
],
"compilerOptions": {
"target": "esnext",
"module": "ESNext",
@ -8,11 +12,15 @@
"strict": true,
"skipLibCheck": true,
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"paths": {
"@/*": [
"./src/*"
]
}
}
},
"exclude": [
"node_modules",
"./*.ts",
"__test__"
]
}