Skip to content

Commit

Permalink
Update deno std to 0.132 and enable last tests
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed Apr 2, 2022
1 parent e5b8554 commit 50762d4
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 34 deletions.
2 changes: 1 addition & 1 deletion deno/polyfills.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global Deno */

import { Buffer } from 'https://deno.land/std@0.120.0/node/buffer.ts'
import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts'

const events = () => ({ data: [], error: [], drain: [], connect: [], secureConnect: [], close: [] })

Expand Down
2 changes: 1 addition & 1 deletion deno/src/bytes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Buffer } from 'https://deno.land/std@0.120.0/node/buffer.ts'
import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts'
const size = 256
let buffer = Buffer.allocUnsafe(size)

Expand Down
8 changes: 4 additions & 4 deletions deno/src/connection.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { HmacSha256 } from 'https://deno.land/std@0.120.0/hash/sha256.ts'
import { Buffer } from 'https://deno.land/std@0.120.0/node/buffer.ts'
import { HmacSha256 } from 'https://deno.land/std@0.132.0/hash/sha256.ts'
import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts'
import { setImmediate, clearImmediate } from '../polyfills.js'
import { net } from '../polyfills.js'
import { tls } from '../polyfills.js'
import crypto from 'https://deno.land/std@0.120.0/node/crypto.ts'
import Stream from 'https://deno.land/std@0.120.0/node/stream.ts'
import crypto from 'https://deno.land/std@0.132.0/node/crypto.ts'
import Stream from 'https://deno.land/std@0.132.0/node/stream.ts'

import { Identifier, Builder, handleValue, arrayParser, arraySerializer } from './types.js'
import { Errors } from './errors.js'
Expand Down
6 changes: 3 additions & 3 deletions deno/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import process from 'https://deno.land/std@0.120.0/node/process.ts'
import os from 'https://deno.land/std@0.120.0/node/os.ts'
import fs from 'https://deno.land/std@0.120.0/node/fs.ts'
import process from 'https://deno.land/std@0.132.0/node/process.ts'
import os from 'https://deno.land/std@0.132.0/node/os.ts'
import fs from 'https://deno.land/std@0.132.0/node/fs.ts'

import {
mergeUserTypes,
Expand Down
2 changes: 1 addition & 1 deletion deno/src/large.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Stream from 'https://deno.land/std@0.120.0/node/stream.ts'
import Stream from 'https://deno.land/std@0.132.0/node/stream.ts'

export default function largeObject(sql, oid, mode = 0x00020000 | 0x00040000) {
return new Promise(async(resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion deno/src/subscribe.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Buffer } from 'https://deno.land/std@0.120.0/node/buffer.ts'
import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts'
export default function Subscribe(postgres, options) {
const listeners = new Map()

Expand Down
2 changes: 1 addition & 1 deletion deno/src/types.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Buffer } from 'https://deno.land/std@0.120.0/node/buffer.ts'
import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts'
import { Query } from './query.js'
import { Errors } from './errors.js'

Expand Down
2 changes: 1 addition & 1 deletion deno/tests/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spawn } from 'https://deno.land/std@0.120.0/node/child_process.ts'
import { spawn } from 'https://deno.land/std@0.132.0/node/child_process.ts'

await exec('psql', ['-c', 'alter system set ssl=on'])
await exec('psql', ['-c', 'create user postgres_js_test'])
Expand Down
12 changes: 6 additions & 6 deletions deno/tests/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Buffer } from 'https://deno.land/std@0.120.0/node/buffer.ts'
import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts'
/* eslint no-console: 0 */

import { exec } from './bootstrap.js'

import { t, nt, ot } from './test.js' // eslint-disable-line
import { net } from '../polyfills.js'
import fs from 'https://deno.land/std@0.120.0/node/fs.ts'
import crypto from 'https://deno.land/std@0.120.0/node/crypto.ts'
import fs from 'https://deno.land/std@0.132.0/node/fs.ts'
import crypto from 'https://deno.land/std@0.132.0/node/crypto.ts'

import postgres from '../src/index.js'
const delay = ms => new Promise(r => setTimeout(r, ms))
Expand Down Expand Up @@ -1632,7 +1632,7 @@ t('Copy write as first works', async() => {
]
})

nt('Copy from file works', async() => {
t('Copy from file works', async() => {
await sql`create table test (x int, y int, z int)`
await new Promise(async r => fs
.createReadStream(rel('copy.csv'))
Expand Down Expand Up @@ -1662,7 +1662,7 @@ t('Copy from works in transaction', async() => {
]
})

nt('Copy from abort works', async() => {
t('Copy from abort works', async() => {
const sql = postgres(options)
const readable = fs.createReadStream(rel('copy.csv'))

Expand Down Expand Up @@ -1827,7 +1827,7 @@ t('Describe a statement without columns', async() => {
]
})

nt('Large object', async() => {
t('Large object', async() => {
const file = rel('index.js')
, md5 = crypto.createHash('md5').update(fs.readFileSync(file)).digest('hex')

Expand Down
4 changes: 2 additions & 2 deletions deno/tests/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import process from 'https://deno.land/std@0.120.0/node/process.ts'
import process from 'https://deno.land/std@0.132.0/node/process.ts'
/* eslint no-console: 0 */

import util from 'https://deno.land/std@0.120.0/node/util.ts'
import util from 'https://deno.land/std@0.132.0/node/util.ts'

let done = 0
let only = false
Expand Down
23 changes: 10 additions & 13 deletions transpile.deno.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import fs from 'fs'
import path from 'path'

const empty = x => fs.readdirSync(x).forEach(f => fs.unlinkSync(path.join(x, f)))
const std = 'https://deno.land/std@0.132.0/'
, empty = x => fs.readdirSync(x).forEach(f => fs.unlinkSync(path.join(x, f)))
, ensureEmpty = x => !fs.existsSync(x) ? fs.mkdirSync(x) : empty(x)
, root = 'deno'
, src = path.join(root, 'src')
Expand Down Expand Up @@ -49,33 +50,29 @@ function transpile(x, name, folder) {
.replace(/\nexec\(/g, '\nawait exec(')
.replace('{ spawnSync }', '{ spawn }')
}

if (name === 'index.js') {
// Ignore tests that use node create stream functions not supported in deno yet
x = x.replace(/(t\('Copy from file works)/, 'n$1')
.replace(/(t\('Copy from abort works)/, 'n$1')
.replace(/(t\('Large object)/, 'n$1')
}
}

const buffer = x.includes('Buffer')
? 'import { Buffer } from \'https://deno.land/std@0.120.0/node/buffer.ts\'\n'
? 'import { Buffer } from \'' + std + 'node/buffer.ts\'\n'
: ''

const process = x.includes('process.')
? 'import process from \'https://deno.land/std@0.120.0/node/process.ts\'\n'
? 'import process from \'' + std + 'node/process.ts\'\n'
: ''

const timers = x.includes('setImmediate')
? 'import { setImmediate, clearImmediate } from \'../polyfills.js\'\n'
: ''

const hmac = x.includes('createHmac')
? 'import { HmacSha256 } from \'https://deno.land/std@0.120.0/hash/sha256.ts\'\n'
? 'import { HmacSha256 } from \'' + std + 'hash/sha256.ts\'\n'
: ''

return hmac + buffer + process + timers + x
.replace(/setTimeout\((.*)\)\.unref\(\)/g, '(window.timer = setTimeout($1), Deno.unrefTimer(window.timer), window.timer)')
.replace(
/setTimeout\((.*)\)\.unref\(\)/g,
'(window.timer = setTimeout($1), Deno.unrefTimer(window.timer), window.timer)'
)
.replace(
'crypto.createHmac(\'sha256\', key).update(x).digest()',
'Buffer.from(new HmacSha256(key).update(x).digest())'
Expand All @@ -87,5 +84,5 @@ function transpile(x, name, folder) {
.replace(/.setKeepAlive\([^)]+\)/g, '')
.replace(/import net from 'net'/, 'import { net } from \'../polyfills.js\'')
.replace(/import tls from 'tls'/, 'import { tls } from \'../polyfills.js\'')
.replace(/ from '([a-z_]+)'/g, ' from \'https://deno.land/std@0.120.0/node/$1.ts\'')
.replace(/ from '([a-z_]+)'/g, ' from \'' + std + 'node/$1.ts\'')
}

0 comments on commit 50762d4

Please sign in to comment.