Files
speckle-server/packages/server/test/serverHelper.ts
T
Iain Sproat 96bed71022 fix(logging): Improves error logging and pretty-prints logs during dev & test (#1255)
* Improves error logging
- use pino error logger correctly by passing in error as first argument

* monitor deployment: Filter logging at INFO level and above
* Use structured logging to create parameters for monitoring results
* Add structured logging to obj fileimport service
* Fileimport service, fix and improve logging
    - use child logger with additional context where possible
    - select appropriate logging level
- fix duplicated context in log statement
* REST endpoints, add context to structured logging and remove same context from message
* Webhook service provides context to bound logger to properly use structured logging
    - Pass bound logger containing context to `makeNetworkRequest`
    - do not log url, as it may contain a secret (like Discord's webhook urls), instead log the webhook Id
     - log error message when network call fails
* upload: make better use of structured logging when recording data
* pino-pretty when in dev or test mode
    - pino-pretty configured to send to stderr
* LOG_PRETTY env var
* Silence structured logging during testing
     - can not rely on determining the port number by reading from stdout/stderr
     - instead we determine which port is free, then create our server on that port
     - we then poll that port until the server is ready before commencing tests
* Allow puppeteer to install chromium
* Do not need to install chromium separately
2022-12-13 09:18:28 +00:00

47 lines
1.0 KiB
TypeScript

import { buildApolloServer } from '@/app'
import { Roles, AllScopes } from '@/modules/core/helpers/mainConstants'
import { addLoadersToCtx } from '@/modules/shared/middleware'
import net from 'net'
/**
* Build an ApolloServer instance with an authenticated context
*/
export function buildAuthenticatedApolloServer(
userId: string,
role = Roles.Server.User,
scopes = AllScopes
) {
return buildApolloServer({
context: () =>
addLoadersToCtx({
auth: true,
userId,
role,
token: 'asd',
scopes
})
})
}
/**
* Build an unauthenticated ApolloServer instance
*/
export function buildUnauthenticatedApolloServer() {
return buildApolloServer({
context: () =>
addLoadersToCtx({
auth: false
})
})
}
export async function getFreeServerPort() {
return new Promise((res) => {
const srv = net.createServer()
srv.listen(0, () => {
const port = (srv?.address() as net.AddressInfo).port
srv.close(() => res(port))
})
})
}