From 96abb5f83e80605e7fb87ba344e198fd19275fd1 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Thu, 17 Oct 2024 22:34:15 +0300 Subject: [PATCH] test: add `setImmediate` polyfill for deno --- src/main/ts/spawn.ts | 4 ++-- src/main/ts/util.ts | 2 ++ src/main/ts/x.ts | 5 ++--- src/test/smoke/invoke.test.mjs | 5 +++++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/ts/spawn.ts b/src/main/ts/spawn.ts index 9792de8..7c787b4 100644 --- a/src/main/ts/spawn.ts +++ b/src/main/ts/spawn.ts @@ -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' @@ -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({ diff --git a/src/main/ts/util.ts b/src/main/ts/util.ts index 20769e6..d5fc326 100644 --- a/src/main/ts/util.ts +++ b/src/main/ts/util.ts @@ -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) diff --git a/src/main/ts/x.ts b/src/main/ts/x.ts index fb5e81b..065f5f3 100644 --- a/src/main/ts/x.ts +++ b/src/main/ts/x.ts @@ -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' @@ -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 || {} diff --git a/src/test/smoke/invoke.test.mjs b/src/test/smoke/invoke.test.mjs index 1fed14b..6355152 100644 --- a/src/test/smoke/invoke.test.mjs +++ b/src/test/smoke/invoke.test.mjs @@ -1,3 +1,8 @@ +if (globalThis.Deno) { + globalThis.setImmediate = (cb) => setTimeout(cb, 0) + globalThis.global = globalThis +} + import assert from 'node:assert' import { zurk, $ } from '../../../target/esm/index.mjs'