Skip to content

Commit

Permalink
wip: passover realtime tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gamemaker1 committed Sep 30, 2023
1 parent e902b90 commit 8e40688
Show file tree
Hide file tree
Showing 9 changed files with 481 additions and 570 deletions.
3 changes: 2 additions & 1 deletion jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"moduleFileExtensions": ["js", "jsx", "json", "ts", "tsx"],
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
}
},
"setupFilesAfterEnv": ["jest-expect-message"]
}
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"express": "4.18.2",
"husky": "8.0.3",
"jest": "29.7.0",
"jest-expect-message": "1.1.3",
"lint-staged": "14.0.1",
"npm-run-all": "4.1.5",
"prettier": "3.0.3",
Expand Down
8 changes: 4 additions & 4 deletions test/helpers/mock-stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export class InvalidStore {}

export class MockStore implements Store {
store: { [key: string]: number } = {}
incrWasCalled = false
incrementWasCalled = false
resetKeyWasCalled = false
decrementWasCalled = false

async increment(key: string) {
this.incrWasCalled = true
this.incrementWasCalled = true
this.store[key] = (this.store[key] ?? 0) + 1

return {
Expand All @@ -34,14 +34,14 @@ export class MockStore implements Store {
}

export class MockLegacyStore implements LegacyStore {
incrWasCalled = false
incrementWasCalled = false
resetKeyWasCalled = false
decrementWasCalled = false
counter = 0

incr(key: string, cb: IncrementCallback): void {
this.counter++
this.incrWasCalled = true
this.incrementWasCalled = true

cb(undefined, this.counter, new Date())
}
Expand Down
43 changes: 43 additions & 0 deletions test/helpers/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// /test/helpers/server.ts
// Create an Express server for testing

import createApp, {
type Application,
type Request,
type Response,
type RequestHandler,
} from 'express'

/**
* Create an Express server with the given middleware.
*/
export const createServer = (
middleware: RequestHandler | RequestHandler[],
): Application => {
// Create an Express server, and register the middleware.
const app = createApp()
app.use(middleware)

// Register test routes.
app.all('/', (_request: Request, response: Response) =>
response.send('Hi there!'),
)
app.get('/ip', (request: Request, response: Response) => {
response.setHeader('x-your-ip', request.ip)
response.sendStatus(204)
})
app.all('/sleepy', middleware, (_request: Request, response: Response) => {
const timerId = setTimeout(() => response.send('Hallo there!'), 100)
response.on('close', () => clearTimeout(timerId))
})
app.get('/error', (_request: Request, response: Response) =>
response.sendStatus(400),
)
app.post('/crash', (_request: Request, response: Response) => {
response.emit('error', new Error('Oops!'))
response.on('error', () => response.end())
})

// Return the application instance.
return app
}
Loading

0 comments on commit 8e40688

Please sign in to comment.