Skip to content

Commit

Permalink
test: add bun to test matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Jun 1, 2024
1 parent 2038562 commit b202b20
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 18 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,17 @@ jobs:

- name: Run smoke:cjs tests
run: npm run test:smoke:cjs

smoke-bun:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Setup Bun
uses: antongolub/action-setup-bun@v1
- uses: actions/download-artifact@v4
with:
name: build
- run: |
bun ./src/test/smoke/invoke.test.cjs
bun ./src/test/smoke/invoke.test.mjs
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# 🔬🧫

> This subproject is a kind of experiment, addressed to the [google/zx/issues/589](https://github.com/google/zx/issues/589).
Just a testing ground for verifying ideas and approaches aimed at improve the [zx](https://github.com/google/zx) architecture.
Just a testing ground for verifying ideas and approaches aimed at improve the [zx's](https://github.com/google/zx) architecture.

## Concepts
* **Layered** architecture:
Expand All @@ -20,6 +20,16 @@ Just a testing ground for verifying ideas and approaches aimed at improve the [z
* The context object at every layer is accessible fo modify.
* Typings are mostly represented by interfaces, so it's easy to tweak up if necessary.

## Requirements
* **OS**
* Linux
* MacOS
* Windows
* **JS Runtime**
* Node.js >= 6 (CJS)
* Node.js >= 12 (ESM)
* Bun >= 1.0.0

## Install
```bash
yarn add zurk
Expand Down
13 changes: 7 additions & 6 deletions src/main/ts/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,23 +182,23 @@ export const invoke = (c: TSpawnCtxNormalized): TSpawnCtxNormalized => {
})
processInput(child, c.input || c.stdin)

child.stdout?.pipe(c.stdout).on('data', d => {
child.stdout?.on('data', d => {
stdout.push(d)
stdall.push(d)
c.ee.emit('stdout', d, c)
})
child.stderr?.pipe(c.stderr).on('data', d => {
}).pipe(c.stdout)
child.stderr?.on('data', d => {
stderr.push(d)
stdall.push(d)
c.ee.emit('stderr', d, c)
})
}).pipe(c.stderr)
child
.on('error', (e: any) => {
error = e
c.ee.emit('err', error, c)
})
.on('close', (status, signal) => {
c.callback(error, c.fulfilled = {
c.fulfilled = {
error,
status,
signal,
Expand All @@ -208,7 +208,8 @@ export const invoke = (c: TSpawnCtxNormalized): TSpawnCtxNormalized => {
stdio: [c.stdin, c.stdout, c.stderr],
duration: Date.now() - now,
ctx: c
})
}
c.callback(error, c.fulfilled)
c.ee.emit('end', c.fulfilled, c)
})
}, c)
Expand Down
7 changes: 5 additions & 2 deletions src/main/ts/x.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@ export interface TShellSync {
(opts: TShellOptions): TShellSync
}

const g = global || globalThis

export const $: TShell = function(this: any, pieces?: any, ...args: any): any {
const preset = this || {}
const self = (this !== g) && this
const preset = self || {}

if (pieces === undefined) return applyMixins($, preset)

if (isStringLiteral(pieces)) return ignite(preset, pieces, ...args)

return (...args: any) => $.apply(this ? assign(this, pieces) : pieces, args)
return (...args: any) => $.apply(self ? assign(self, pieces) : pieces, args)
}

const ignite = (preset: any, pieces: TemplateStringsArray, ...args: any[]) => {
Expand Down
12 changes: 7 additions & 5 deletions src/test/smoke/invoke.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ const r2 = $({sync: true})`echo bar`
assert.ok(/bar/.test(r2.stdout))
assert.equal(r2.status, 0);

$`echo baz`.then((r3) => {
assert.ok(/baz/.test(r3.stdout))
assert.equal(r3.status, 0)
clearInterval(keepAlive)
})
$`echo baz`
.then((r3) => {
clearInterval(keepAlive)

assert.ok(/baz/.test(r3.stdout))
assert.equal(r3.status, 0)
})

console.log('nodejs:', process.versions.node)
console.log('smoke cjs: ok')
22 changes: 18 additions & 4 deletions src/test/smoke/invoke.test.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import assert from 'assert'
import { zurk } from 'zurk'
import { zurk, $ } from '../../../target/esm/index.mjs'

const result = zurk({ sync: true, cmd: 'echo', args: ['foo'] })
assert.match(result.stdout, /foo/)
assert.equal(result.status, 0)
const keepAlive = setInterval(() => {}, 1000 * 60 * 60)

const r1 = zurk({ sync: true, cmd: 'echo', args: ['foo'] })
assert.ok(/foo/.test(r1.stdout))
assert.equal(r1.status, 0)

const r2 = $({sync: true})`echo bar`
assert.ok(/bar/.test(r2.stdout))
assert.equal(r2.status, 0);

$`echo baz`
.then((r3) => {
clearInterval(keepAlive)
assert.ok(/baz/.test(r3.stdout))
assert.equal(r3.status, 0)
})

console.log('nodejs:', process.versions.node)
console.log('smoke mjs: ok')

0 comments on commit b202b20

Please sign in to comment.