Skip to content

Commit 2101f62

Browse files
committed
make snapshots more linux compatible
1 parent d646e50 commit 2101f62

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

packages/client/test/errors.test.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ const repoRoot = path.resolve(process.cwd(), '../..')
1414
expect.addSnapshotSerializer({
1515
test: (val: unknown) => typeof val === 'string' && val.includes(repoRoot),
1616
print: (val: any) =>
17-
(val as string).replaceAll(repoRoot, '<repo>').replaceAll(/file:\/\/.*:\d+:\d+/g, '<file>:<line>:<col>'),
17+
(val as string)
18+
.replaceAll(repoRoot, '<repo>')
19+
.replaceAll(/file:\/\/.*:\d+:\d+/g, '<file>:<line>:<col>')
20+
.split('\n')
21+
.filter(line => !line.includes('(node:'))
22+
.join('\n'),
1823
})
1924

2025
let pool: Awaited<ReturnType<typeof createPool>>
@@ -137,8 +142,7 @@ test('syntax error', async () => {
137142
expect(err.stack).toMatchInlineSnapshot(`
138143
Error: [Query select_fb83277]: syntax error at or near "frooom"
139144
at Object.query (<repo>/packages/client/src/index.ts:375:13)
140-
at processTicksAndRejections (node:internal/process/task_queues:95:5)
141-
at <repo>/packages/client/test/errors.test.ts:135:22
145+
at <repo>/packages/client/test/errors.test.ts:140:22
142146
at runTest (<file>:<line>:<col>)
143147
at runSuite (<file>:<line>:<col>)
144148
at runFiles (<file>:<line>:<col>)
@@ -154,10 +158,5 @@ test('syntax error', async () => {
154158
at Parser.handlePacket (<repo>/node_modules/.pnpm/[email protected]/node_modules/pg-protocol/src/parser.ts:188:21)
155159
at Parser.parse (<repo>/node_modules/.pnpm/[email protected]/node_modules/pg-protocol/src/parser.ts:103:30)
156160
at Socket.<anonymous> (<repo>/node_modules/.pnpm/[email protected]/node_modules/pg-protocol/src/index.ts:7:48)
157-
at Socket.emit (node:events:514:28)
158-
at addChunk (node:internal/streams/readable:376:12)
159-
at readableAddChunk (node:internal/streams/readable:349:9)
160-
at Socket.Readable.push (node:internal/streams/readable:286:10)
161-
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
162161
`)
163162
})

packages/client/test/pgp.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ test('any keyword', async () => {
3232

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

3839
test('identifiers', async () => {

packages/client/test/slonik23.test.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ beforeAll(async () => {
77
pool = createPool('postgresql://postgres:postgres@localhost:5432/postgres')
88
})
99

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

147-
expect(result).toMatchInlineSnapshot(`
148-
{
149-
"count": 0,
150-
"date": "2000-01-01",
151-
"day_interval": 86400,
152-
"hour_interval": 3600,
153-
"timestamp": 946746000000,
154-
"timestamptz": 946728000000,
155-
}
156-
`)
147+
expect(result).toMatchInlineSnapshot(
148+
{timestamp: expect.any(Number)},
149+
`
150+
{
151+
"count": 0,
152+
"date": "2000-01-01",
153+
"day_interval": 86400,
154+
"hour_interval": 3600,
155+
"timestamp": Any<Number>,
156+
"timestamptz": 946728000000,
157+
}
158+
`,
159+
)
157160
})

0 commit comments

Comments
 (0)