mirror of
https://github.com/BillyOutlast/posthog.git
synced 2026-02-04 03:01:23 +01:00
feat(node): Swap to tsx (#37171)
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
module.exports = {
|
||||
transform: {
|
||||
'^.+\\.(t|j)s$': ['@swc/jest'],
|
||||
'^.+\\.(t|j)s$': [
|
||||
'ts-jest',
|
||||
{
|
||||
tsconfig: './tsconfig.json',
|
||||
},
|
||||
],
|
||||
},
|
||||
testEnvironment: 'node',
|
||||
clearMocks: true,
|
||||
coverageProvider: 'v8',
|
||||
setupFilesAfterEnv: ['./jest.setup.js'],
|
||||
setupFilesAfterEnv: ['./jest.setup.ts'],
|
||||
testMatch: ['<rootDir>/tests/**/*.test.ts', '<rootDir>/src/**/*.test.ts'],
|
||||
testTimeout: 60000,
|
||||
modulePathIgnorePatterns: ['<rootDir>/.tmp/'],
|
||||
|
||||
@@ -32,7 +32,7 @@ beforeEach(() => {
|
||||
jest.mocked(logger.debug).mockClear()
|
||||
jest.mocked(logger.error).mockClear()
|
||||
|
||||
const responsesToUrls = {
|
||||
const responsesToUrls: Record<string, any> = {
|
||||
'https://google.com/results.json?query=fetched': { count: 2, query: 'bla', results: [true, true] },
|
||||
'https://mmdbcdn.posthog.net/': readFileSync(join(__dirname, 'tests', 'assets', 'GeoLite2-City-Test.mmdb.br')),
|
||||
'https://app.posthog.com/api/event?token=THIS+IS+NOT+A+TOKEN+FOR+TEAM+2': { hello: 'world' },
|
||||
@@ -40,7 +40,7 @@ beforeEach(() => {
|
||||
'https://www.example.com': { example: 'data' },
|
||||
}
|
||||
|
||||
const headersToUrls = {
|
||||
const headersToUrls: Record<string, Map<string, string>> = {
|
||||
'https://mmdbcdn.posthog.net/': new Map([
|
||||
['content-type', 'vnd.maxmind.maxmind-db'],
|
||||
['content-disposition', `attachment; filename="GeoLite2-City-${DateTime.local().toISODate()}.mmdb"`],
|
||||
@@ -48,7 +48,7 @@ beforeEach(() => {
|
||||
}
|
||||
|
||||
// Create a proper Response-like object factory
|
||||
const createMockResponse = (url, options = {}) => {
|
||||
const createMockResponse = (url: string, options: any = {}): any => {
|
||||
const responseBody = responsesToUrls[url] || { fetch: 'mock' }
|
||||
const responseHeaders = headersToUrls[url] || new Map()
|
||||
const responseText =
|
||||
@@ -63,13 +63,13 @@ beforeEach(() => {
|
||||
statusText: 'OK',
|
||||
ok: true,
|
||||
headers: {
|
||||
get: (name) => {
|
||||
get: (name: string) => {
|
||||
if (responseHeaders instanceof Map) {
|
||||
return responseHeaders.get(name) || null
|
||||
}
|
||||
return null
|
||||
},
|
||||
forEach: (callback) => {
|
||||
forEach: (callback: (value: string, key: string) => void) => {
|
||||
if (responseHeaders instanceof Map) {
|
||||
responseHeaders.forEach((value, key) => callback(value, key))
|
||||
}
|
||||
@@ -88,7 +88,7 @@ beforeEach(() => {
|
||||
}
|
||||
}
|
||||
|
||||
jest.mocked(fetch).mockImplementation((url, options = {}) => {
|
||||
jest.mocked(fetch as any).mockImplementation((url: string, options: any = {}) => {
|
||||
return Promise.resolve(createMockResponse(url, options))
|
||||
})
|
||||
})
|
||||
@@ -10,9 +10,9 @@
|
||||
"scripts": {
|
||||
"test": "SHARD_IDX=${SHARD_INDEX:-1}; SHARD_TOTAL=${SHARD_COUNT:-1}; echo $SHARD_IDX/$SHARD_TOTAL; jest --runInBand --forceExit --shard=$SHARD_IDX/$SHARD_TOTAL",
|
||||
"start": "pnpm start:dev",
|
||||
"start:dist": "BASE_DIR=.. node dist/index.js",
|
||||
"start:dev": "NODE_ENV=dev BASE_DIR=.. nodemon --exitcrash --watch src/ --exec node -r @swc-node/register src/index.ts",
|
||||
"start:devNoWatch": "NODE_ENV=dev BASE_DIR=.. node -r @swc-node/register src/index.ts",
|
||||
"start:dist": "node dist/index.js",
|
||||
"start:dev": "NODE_ENV=dev tsx watch src/index.ts",
|
||||
"start:devNoWatch": "NODE_ENV=dev tsx src/index.ts",
|
||||
"prestart:dev": "pnpm build:cyclotron",
|
||||
"prestart:devNoWatch": "pnpm build:cyclotron",
|
||||
"build": "pnpm clean && pnpm typescript:compile && pnpm typescript:compile-cleanup",
|
||||
@@ -129,9 +129,8 @@
|
||||
"@babel/cli": "^7.22.5",
|
||||
"@babel/types": "^7.20.2",
|
||||
"@segment/actions-core": "^3.151.0",
|
||||
"@swc-node/register": "^1.10.9",
|
||||
"@swc/core": "^1.10.14",
|
||||
"@swc/jest": "^0.2.37",
|
||||
"tsx": "^4.7.0",
|
||||
"ts-jest": "^29.1.0",
|
||||
"@types/adm-zip": "^0.4.34",
|
||||
"@types/babel__core": "^7.1.19",
|
||||
"@types/babel__standalone": "^7.1.4",
|
||||
@@ -169,7 +168,6 @@
|
||||
"eslint-plugin-promise": "^6.1.1",
|
||||
"jest": "^30.0.0",
|
||||
"node-pg-migrate": "^8.0.3",
|
||||
"nodemon": "^3.1.10",
|
||||
"pino-pretty": "^9.1.0",
|
||||
"prettier": "^3.6.2",
|
||||
"supertest": "^7.0.0",
|
||||
|
||||
527
pnpm-lock.yaml
generated
527
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user