| 322 | } |
| 323 | |
| 324 | async main(yamlFile) { |
| 325 | const data = yaml.load(fs.readFileSync(yamlFile, 'utf8')); |
| 326 | const globalVariables = data.variables || {}; |
| 327 | const tests = data.tests || []; |
| 328 | |
| 329 | const port = process.env.PGPORT || 8812; |
| 330 | |
| 331 | // Run all tests twice - once with prepare: false and once with prepare: true |
| 332 | for (const prepareMode of [true, false]) { |
| 333 | console.log(`\n=============================`); |
| 334 | console.log(`Running tests with prepare: ${prepareMode}`); |
| 335 | console.log(`=============================\n`); |
| 336 | this.sql = postgres({ |
| 337 | prepare: prepareMode, |
| 338 | host: 'localhost', |
| 339 | port: port, |
| 340 | user: 'admin', |
| 341 | password: 'quest', |
| 342 | database: 'qdb', |
| 343 | // Force UTC timezone |
| 344 | timezone: 'UTC', |
| 345 | // Configure custom type parsers |
| 346 | types: { |
| 347 | // Custom parsers for integers to ensure they're returned as numbers |
| 348 | int2: { |
| 349 | from: [21], |
| 350 | parse: value => parseInt(value, 10) |
| 351 | }, |
| 352 | int4: { |
| 353 | from: [23], |
| 354 | parse: value => parseInt(value, 10) |
| 355 | }, |
| 356 | int8: { |
| 357 | from: [20], |
| 358 | parse: value => parseInt(value, 10) |
| 359 | }, |
| 360 | // Custom parser for timestamps to match expected microsecond precision |
| 361 | timestamp: { |
| 362 | from: [1114], |
| 363 | parse: value => { |
| 364 | // Split on the decimal point if it exists |
| 365 | const [dateTimePart, fractionPart = '000000'] = value.split('.'); |
| 366 | // Pad or truncate to exactly 6 digits |
| 367 | const normalizedFraction = (fractionPart + '000000').slice(0, 6); |
| 368 | // Replace space with T and add normalized fraction and Z |
| 369 | return `${dateTimePart.replace(' ', 'T')}.${normalizedFraction}Z`; |
| 370 | } |
| 371 | } |
| 372 | }, |
| 373 | // Error handling |
| 374 | onnotice: message => console.log(`NOTICE: ${message}`) |
| 375 | }); |
| 376 | |
| 377 | for (const test of tests) { |
| 378 | const exclusions = test.exclude || []; |
| 379 | if (exclusions.includes('nodejs-postgres')) { |
| 380 | console.log(`Skipping test '${test.name}' because it is excluded for nodejs-postgres.`); |
| 381 | continue; |