Skip to content

Commit

Permalink
make snapshots more linux compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkal committed Mar 2, 2024
1 parent d646e50 commit 2101f62
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
15 changes: 7 additions & 8 deletions packages/client/test/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ const repoRoot = path.resolve(process.cwd(), '../..')
expect.addSnapshotSerializer({
test: (val: unknown) => typeof val === 'string' && val.includes(repoRoot),
print: (val: any) =>
(val as string).replaceAll(repoRoot, '<repo>').replaceAll(/file:\/\/.*:\d+:\d+/g, '<file>:<line>:<col>'),
(val as string)
.replaceAll(repoRoot, '<repo>')
.replaceAll(/file:\/\/.*:\d+:\d+/g, '<file>:<line>:<col>')
.split('\n')
.filter(line => !line.includes('(node:'))
.join('\n'),
})

let pool: Awaited<ReturnType<typeof createPool>>
Expand Down Expand Up @@ -137,8 +142,7 @@ test('syntax error', async () => {
expect(err.stack).toMatchInlineSnapshot(`
Error: [Query select_fb83277]: syntax error at or near "frooom"
at Object.query (<repo>/packages/client/src/index.ts:375:13)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at <repo>/packages/client/test/errors.test.ts:135:22
at <repo>/packages/client/test/errors.test.ts:140:22
at runTest (<file>:<line>:<col>)
at runSuite (<file>:<line>:<col>)
at runFiles (<file>:<line>:<col>)
Expand All @@ -154,10 +158,5 @@ test('syntax error', async () => {
at Parser.handlePacket (<repo>/node_modules/.pnpm/[email protected]/node_modules/pg-protocol/src/parser.ts:188:21)
at Parser.parse (<repo>/node_modules/.pnpm/[email protected]/node_modules/pg-protocol/src/parser.ts:103:30)
at Socket.<anonymous> (<repo>/node_modules/.pnpm/[email protected]/node_modules/pg-protocol/src/index.ts:7:48)
at Socket.emit (node:events:514:28)
at addChunk (node:internal/streams/readable:376:12)
at readableAddChunk (node:internal/streams/readable:349:9)
at Socket.Readable.push (node:internal/streams/readable:286:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
`)
})
3 changes: 2 additions & 1 deletion packages/client/test/pgp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ test('any keyword', async () => {

test('date', async () => {
const result = await db.query(`select $1 as foo`, [new Date('2000-01-01T12:00:00Z')])
expect(result[0].foo).toMatchInlineSnapshot(`"2000-01-01T07:00:00.000-05:00"`)
expect(result[0].foo).toMatch(/2000-01-01T\d\d:00:00.000.*/)
expect(new Date(result[0].foo as string).toISOString()).toMatchInlineSnapshot(`"2000-01-01T12:00:00.000Z"`)
})

test('identifiers', async () => {
Expand Down
25 changes: 14 additions & 11 deletions packages/client/test/slonik23.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ beforeAll(async () => {
pool = createPool('postgresql://postgres:postgres@localhost:5432/postgres')
})

// codegen:start {preset: custom, source: ./generate.ts, export: generate, dev: true, removeTests: [interval, jsonb, literalValue, fragment, type parsers]}
// codegen:start {preset: custom, source: ./generate.ts, export: generate, dev: true, removeTests: [interval, jsonb, literalValue, fragment, type parsers, query timeout]}
beforeEach(async () => {
await pool.query(sql`DROP TABLE IF EXISTS test_slonik23`)
await pool.query(sql`CREATE TABLE test_slonik23 (id int, name text)`)
Expand Down Expand Up @@ -144,14 +144,17 @@ test('type parsers', async () => {
(select count(*) from test_slonik23 where id = -1) as count
`)

expect(result).toMatchInlineSnapshot(`
{
"count": 0,
"date": "2000-01-01",
"day_interval": 86400,
"hour_interval": 3600,
"timestamp": 946746000000,
"timestamptz": 946728000000,
}
`)
expect(result).toMatchInlineSnapshot(
{timestamp: expect.any(Number)},
`
{
"count": 0,
"date": "2000-01-01",
"day_interval": 86400,
"hour_interval": 3600,
"timestamp": Any<Number>,
"timestamptz": 946728000000,
}
`,
)
})

0 comments on commit 2101f62

Please sign in to comment.