Skip to content

Commit

Permalink
fixes after upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Razon committed Mar 25, 2024
1 parent d00063d commit e3310ee
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 43 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/drivers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kubePod from '@preevy/driver-kube-pod'
import { Flag } from '@oclif/core/lib/interfaces'
import { Interfaces } from '@oclif/core'
import { formatFlagsToArgs } from '@preevy/cli-common'
import {} from '@preevy/core' // https://github.com/microsoft/TypeScript/issues/47663#issuecomment-1270716220

export const machineDrivers = {
lightsail,
Expand Down
46 changes: 34 additions & 12 deletions packages/compose-tunnel-agent/src/api-server/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { AddressInfo } from 'node:net'
import { describe, expect, beforeAll, afterAll, jest, it } from '@jest/globals'
import { ChildProcess, spawn, exec } from 'child_process'
import { pino } from 'pino'
import pinoPrettyModule from 'pino-pretty'
import * as pino from 'pino'
import pinoPretty from 'pino-pretty'
import Dockerode from 'dockerode'
import { inspect, promisify } from 'node:util'
import waitForExpectModule from 'wait-for-expect'
import waitForExpect from 'wait-for-expect'
import WebSocket from 'ws'
import stripAnsi from 'strip-ansi'
import { createApp } from './index.js'
import { filteredClient } from '../docker/index.js'
import { SshState } from '../ssh/index.js'
import { COMPOSE_PROJECT_LABEL } from '../docker/labels.js'

const PinoPretty = pinoPrettyModule.default

const waitForExpect = waitForExpectModule.default
const TEST_COMPOSE_PROJECT = 'my-project'

const setupDockerContainer = () => {
Expand Down Expand Up @@ -57,9 +54,12 @@ const setupDockerContainer = () => {
}

const setupApiServer = () => {
const log = pino({
level: 'debug',
}, PinoPretty({ destination: pino.destination(process.stderr) }))
const log = pino.pino(
{ level: 'debug' },
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
pinoPretty({ destination: pino.destination(process.stderr) }),
)

let app: Awaited<ReturnType<typeof createApp>>
let serverBaseUrl: string
Expand Down Expand Up @@ -134,6 +134,8 @@ describe('docker api', () => {

const waitForContainerId = async () => {
let containerId = ''
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await waitForExpect(async () => {
const containers = await fetchJson(`http://${serverBaseUrl()}/containers`) as { Id: string; Names: string[] }[]
const container = containers.find(({ Names: names }) => names.includes(`/${containerName()}`))
Expand All @@ -153,8 +155,14 @@ describe('docker api', () => {
describe('tty=true', () => {
it('should communicate via websocket', async () => {
const { receivedBuffers, send, close } = await openWebSocket(`ws://${serverBaseUrl()}/containers/${containerId}/exec`)
await waitForExpect(() => expect(receivedBuffers.length).toBeGreaterThan(0))
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await waitForExpect(
() => expect(receivedBuffers.length).toBeGreaterThan(0),
)
await send('ls \n')
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await waitForExpect(() => {
const received = stripAnsi(Buffer.concat(receivedBuffers).toString('utf-8'))
expect(received).toMatch(/#/)
Expand All @@ -168,6 +176,8 @@ describe('docker api', () => {
describe('tty=false', () => {
it('should communicate via websocket', async () => {
const { receivedBuffers, send, close } = await openWebSocket(`ws://${serverBaseUrl()}/containers/${containerId}/exec`)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await waitForExpect(async () => {
await send('ls\n')
const received = Buffer.concat(receivedBuffers).toString('utf-8')
Expand All @@ -191,8 +201,14 @@ describe('docker api', () => {
describe(`${s.join(' and ')}`, () => {
it(`should show the ${s.join(' and ')} logs via websocket`, async () => {
const { receivedBuffers, close } = await openWebSocket(`ws://${serverBaseUrl()}/containers/${containerId}/logs?${s.map(st => `${st}=true`).join('&')}`)
await waitForExpect(() => expect(receivedBuffers.length).toBeGreaterThan(0))
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await waitForExpect(
() => expect(receivedBuffers.length).toBeGreaterThan(0),
)
const length1 = receivedBuffers.length
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await waitForExpect(() => {
const received = Buffer.concat(receivedBuffers).toString('utf-8')
s.forEach(st => {
Expand All @@ -202,6 +218,8 @@ describe('docker api', () => {
expect(received).not.toContain(`hello ${st}`)
})
})
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await waitForExpect(() => {
expect(receivedBuffers.length).toBeGreaterThan(length1)
})
Expand All @@ -217,7 +235,11 @@ describe('docker api', () => {
describe('timestamps', () => {
it('should show the logs with a timestamp', async () => {
const { receivedBuffers, close } = await openWebSocket(`ws://${serverBaseUrl()}/containers/${containerId}/logs?stdout=true&timestamps=true`)
await waitForExpect(() => expect(receivedBuffers.length).toBeGreaterThan(0))
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await waitForExpect(
() => expect(receivedBuffers.length).toBeGreaterThan(0),
)
const received = Buffer.concat(receivedBuffers).toString('utf-8')
expect(received).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d*Z/)
await close()
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"ora": "5.4.1",
"p-limit": "^3.1.0",
"p-memoize": "^4",
"p-queue": "^6.6.2",
"p-queue": "^8.0.1",
"p-retry": "^4.6.2",
"rimraf": "^5.0.5",
"shell-escape": "^0.2.0",
Expand Down Expand Up @@ -67,7 +67,7 @@
"jest": "29.7.0",
"lint-staged": "^15.2.0",
"shx": "^0.3.3",
"ts-jest": "29.1.1",
"ts-jest": "29.1.2",
"ts-node": "^10.9.1",
"tslib": "^2.5.0",
"typescript": "^5.4.3"
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/upload-files/walk.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fs from 'fs'
import PQueueModule from 'p-queue'
import PQueue from 'p-queue'
import { DirInfo, FileInfo } from './files.js'

const PQueue = PQueueModule.default
const readDir = async (filename: string) => await fs.promises.readdir(filename)

const normalizeFile = async (local: string | FileInfo | DirInfo) => {
Expand Down
2 changes: 1 addition & 1 deletion tunnel-server/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest/presets/default-esm',
// preset: 'ts-jest/presets/default-esm',
testEnvironment: 'node',
testMatch: ['!dist/', '**/*.test.ts'],
extensionsToTreatAsEsm: ['.ts'],
Expand Down
2 changes: 1 addition & 1 deletion tunnel-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"eslint": "^8.57.0",
"jest": "29.7.0",
"nodemon": "^2.0.20",
"ts-jest": "29.1.1",
"ts-jest": "29.1.2",
"typescript": "^5.4.3",
"undici": "^6.4.0",
"wait-for-expect": "^3.0.2"
Expand Down
15 changes: 8 additions & 7 deletions tunnel-server/src/app/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import http from 'http'
import fs from 'fs'
import events from 'node:events'
import path from 'path'
import pino, { Level } from 'pino'
import pinoPrettyModule from 'pino-pretty'
import * as pino from 'pino'
import pinoPretty from 'pino-pretty'
import { promisify } from 'node:util'
import { request, Dispatcher } from 'undici'
import { calculateJwkThumbprintUri, exportJWK, JWTPayload, SignJWT } from 'jose'
Expand All @@ -17,8 +17,6 @@ import { EntryWatcher } from '../memory-store.js'
import { authHintQueryParam, proxy } from '../proxy/index.js'
import { calcLoginUrl } from './urls.js'

const pinoPretty = pinoPrettyModule.default

const mockFunction = <T extends (...args: never[]) => unknown>(): jest.MockedFunction<T> => (
jest.fn() as unknown as jest.MockedFunction<T>
)
Expand Down Expand Up @@ -74,9 +72,12 @@ describe('app', () => {
let activeTunnelStore: MockInterface<Pick<ActiveTunnelStore, 'get' | 'getByPkThumbprint'>>
let user: Claims | undefined

const log = pino.default<Level>({
level: 'debug',
}, pinoPretty({ destination: pino.destination(process.stderr) }))
const log = pino.pino<pino.Level>(
{ level: 'debug' },
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
pinoPretty({ destination: pino.destination(process.stderr) }),
)

beforeEach(async () => {
user = undefined
Expand Down
8 changes: 6 additions & 2 deletions tunnel-server/src/destroy-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ describe('createDestroy', () => {
})

it('emits the close event immediately', async () => {
await waitForExpect.default(async () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await waitForExpect(async () => {
expect(closed).toBe(true)
}, 1000, 100)
})
Expand Down Expand Up @@ -83,7 +85,9 @@ describe('createDestroy', () => {
})

it('emits the close event immediately', async () => {
await waitForExpect.default(async () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await waitForExpect(async () => {
expect(closed).toBe(true)
}, 1000, 100)
})
Expand Down
15 changes: 8 additions & 7 deletions tunnel-server/src/proxy/router.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { describe, it, expect, beforeEach, jest } from '@jest/globals'
import pino, { Level } from 'pino'
import pinoPrettyModule from 'pino-pretty'
import * as pino from 'pino'
import pinoPretty from 'pino-pretty'
import { IncomingMessage } from 'http'
import { Socket } from 'net'
import { TunnelFinder, proxyRouter } from './router.js'
import { ActiveTunnelStore } from '../tunnel-store/index.js'

const PinoPretty = pinoPrettyModule.default

const log = pino.default<Level>({
level: 'debug',
}, PinoPretty({ destination: pino.destination(process.stderr) }))
const log = pino.pino<pino.Level>(
{ level: 'debug' },
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
pinoPretty({ destination: pino.destination(process.stderr) }),
)

const mockFunction = <T extends (...args: never[]) => unknown>(): jest.MockedFunction<T> => (
jest.fn() as unknown as jest.MockedFunction<T>
Expand Down
7 changes: 6 additions & 1 deletion tunnel-server/src/tunnel-store/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ describe('inMemoryActiveTunnelStore', () => {
let log: Logger<Level>

beforeEach(() => {
log = pino({ level: 'silent' }, pinoPretty.default())
log = pino(
{ level: 'silent' },
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
pinoPretty(),
)
store = inMemoryActiveTunnelStore({ log })
})

Expand Down
8 changes: 4 additions & 4 deletions tunnel-server/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3802,10 +3802,10 @@ ts-api-utils@^1.0.1:
resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.0.3.tgz#f12c1c781d04427313dbac808f453f050e54a331"
integrity sha512-wNMeqtMz5NtwpT/UZGY5alT+VoKdSsOOP/kqHFcUW1P/VRhH2wJ48+DN2WwUliNbQ976ETwDL0Ifd2VVvgonvg==

[email protected].1:
version "29.1.1"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.1.1.tgz#f58fe62c63caf7bfcc5cc6472082f79180f0815b"
integrity sha512-D6xjnnbP17cC85nliwGiL+tpoKN0StpgE0TeOjXQTU6MVCfsB4v7aW05CgQ/1OywGb0x/oy9hHFnN+sczTiRaA==
[email protected].2:
version "29.1.2"
resolved "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.2.tgz#7613d8c81c43c8cb312c6904027257e814c40e09"
integrity sha512-br6GJoH/WUX4pu7FbZXuWGKGNDuU7b8Uj77g/Sp7puZV6EXzuByl6JrECvm0MzVzSTkSHWTihsXt+5XYER5b+g==
dependencies:
bs-logger "0.x"
fast-json-stable-stringify "2.x"
Expand Down
21 changes: 17 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11129,6 +11129,14 @@ [email protected], p-queue@^6.6.2:
eventemitter3 "^4.0.4"
p-timeout "^3.2.0"

p-queue@^8.0.1:
version "8.0.1"
resolved "https://registry.npmjs.org/p-queue/-/p-queue-8.0.1.tgz#718b7f83836922ef213ddec263ff4223ce70bef8"
integrity sha512-NXzu9aQJTAzbBqOt2hwsR63ea7yvxJc0PwN/zobNAudYfb1B7R08SzB4TsLeSbUCuG467NhnoT0oO6w1qRO+BA==
dependencies:
eventemitter3 "^5.0.1"
p-timeout "^6.1.2"

[email protected], p-reduce@^2.0.0, p-reduce@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/p-reduce/-/p-reduce-2.1.0.tgz#09408da49507c6c274faa31f28df334bc712b64a"
Expand Down Expand Up @@ -11162,6 +11170,11 @@ p-timeout@^3.2.0:
dependencies:
p-finally "^1.0.0"

p-timeout@^6.1.2:
version "6.1.2"
resolved "https://registry.npmjs.org/p-timeout/-/p-timeout-6.1.2.tgz#22b8d8a78abf5e103030211c5fc6dee1166a6aa5"
integrity sha512-UbD77BuZ9Bc9aABo74gfXhNvzC9Tx7SxtHSh1fxvx3jTLLYvmVhiQZZrJzqqU0jKbN32kb5VOKiLEQI/3bIjgQ==

p-transform@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/p-transform/-/p-transform-1.3.0.tgz#2da960ba92c6a56efbe75cbd1edf3ea7b3191049"
Expand Down Expand Up @@ -13160,10 +13173,10 @@ ts-api-utils@^1.0.1:
resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.0.3.tgz#f12c1c781d04427313dbac808f453f050e54a331"
integrity sha512-wNMeqtMz5NtwpT/UZGY5alT+VoKdSsOOP/kqHFcUW1P/VRhH2wJ48+DN2WwUliNbQ976ETwDL0Ifd2VVvgonvg==

[email protected].1:
version "29.1.1"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.1.1.tgz#f58fe62c63caf7bfcc5cc6472082f79180f0815b"
integrity sha512-D6xjnnbP17cC85nliwGiL+tpoKN0StpgE0TeOjXQTU6MVCfsB4v7aW05CgQ/1OywGb0x/oy9hHFnN+sczTiRaA==
[email protected].2:
version "29.1.2"
resolved "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.2.tgz#7613d8c81c43c8cb312c6904027257e814c40e09"
integrity sha512-br6GJoH/WUX4pu7FbZXuWGKGNDuU7b8Uj77g/Sp7puZV6EXzuByl6JrECvm0MzVzSTkSHWTihsXt+5XYER5b+g==
dependencies:
bs-logger "0.x"
fast-json-stable-stringify "2.x"
Expand Down

0 comments on commit e3310ee

Please sign in to comment.