Skip to content

Commit

Permalink
test: add setImmediate polyfill for deno
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Oct 17, 2024
1 parent b682547 commit 365de0b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main/ts/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as cp from 'node:child_process'
import process from 'node:process'
import EventEmitter from 'node:events'
import { Readable, Writable, Stream, Transform } from 'node:stream'
import { assign, noop, randomId } from './util.js'
import { assign, noop, randomId, g } from './util.js'

export * from './util.js'

Expand Down Expand Up @@ -102,7 +102,7 @@ export const defaults: TSpawnCtxNormalized = {
get stdout(){ return new VoidStream() },
get stderr(){ return new VoidStream() },
stdio: ['pipe', 'pipe', 'pipe'],
run: setImmediate,
run: g.setImmediate,
}

export const normalizeCtx = (...ctxs: TSpawnCtx[]): TSpawnCtxNormalized => assign({
Expand Down
2 changes: 2 additions & 0 deletions src/main/ts/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Stream } from 'node:stream'

export const g = global || globalThis

export const noop = () => { /* noop */ }

export const randomId = () => Math.random().toString(36).slice(2)
Expand Down
5 changes: 2 additions & 3 deletions src/main/ts/x.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
assign,
quote,
buildCmd,
parseInput
parseInput,
g
} from './util.js'
import { pipeMixin } from './mixin/pipe.js'
import { killMixin } from './mixin/kill.js'
Expand Down Expand Up @@ -85,8 +86,6 @@ export interface TShellSync {
(opts: TShellOptions): TShellSync
}

const g = global || globalThis

export const $: TShell = function(this: any, pieces?: any, ...args: any): any {
const self = (this !== g) && this
const preset = self || {}
Expand Down
4 changes: 4 additions & 0 deletions src/test/smoke/invoke.test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import assert from 'node:assert'
import { zurk, $ } from '../../../target/esm/index.mjs'

if (globalThis.Deno) {
globalThis.setImmediate = (cb) => setTimeout(cb, 0)
globalThis.global = globalThis
}
const keepAlive = setInterval(() => {}, 1000 * 60 * 60)

const r1 = zurk({ sync: true, cmd: 'echo', args: ['foo'] })
Expand Down

0 comments on commit 365de0b

Please sign in to comment.