Skip to content

Commit 89d1177

Browse files
authored
test(core): check $ uses defaults store (#1079)
* test(core): check $ uses defaults store * test: enhance vendor test
1 parent bf26083 commit 89d1177

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

test/core.test.js

+26-15
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
$,
2525
ProcessPromise,
2626
ProcessOutput,
27+
defaults,
2728
resolveDefaults,
2829
cd,
2930
syncProcessCwd,
@@ -221,6 +222,20 @@ describe('core', () => {
221222
})
222223

223224
describe('$({opts}) API', () => {
225+
it('$ proxy uses `defaults` store', () => {
226+
assert.equal($.foo, undefined)
227+
defaults.foo = 'bar'
228+
$.baz = 'qux'
229+
assert.equal($.foo, 'bar')
230+
assert.equal($.baz, 'qux')
231+
assert.equal(defaults.baz, 'qux')
232+
delete defaults.foo
233+
$.baz = undefined
234+
assert.equal($.foo, undefined)
235+
assert.equal($.baz, undefined)
236+
assert.equal(defaults.baz, undefined)
237+
})
238+
224239
test('provides presets', async () => {
225240
const $1 = $({ nothrow: true })
226241
assert.equal((await $1`exit 1`).exitCode, 1)
@@ -396,7 +411,7 @@ describe('core', () => {
396411
describe('ProcessPromise', () => {
397412
test('getters', async () => {
398413
const p = $`echo foo`
399-
assert.ok(p.pid > 0)
414+
assert.ok(typeof p.pid === 'number')
400415
assert.ok(typeof p.id === 'string')
401416
assert.ok(typeof p.cmd === 'string')
402417
assert.ok(typeof p.fullCmd === 'string')
@@ -439,24 +454,20 @@ describe('core', () => {
439454
assert.equal(p.stage, 'fulfilled')
440455
})
441456

442-
it('all transition', async () => {
457+
it('all transitions', async () => {
443458
const { promise, resolve, reject } = Promise.withResolvers()
444-
const process = new ProcessPromise(noop, noop)
445-
446-
assert.equal(process.stage, 'initial')
447-
process._bind('echo foo', 'test', resolve, reject, {
448-
...resolveDefaults(),
459+
const p = new ProcessPromise(noop, noop)
460+
assert.equal(p.stage, 'initial')
461+
p._bind('echo foo', 'test', resolve, reject, {
462+
...defaults,
449463
halt: true,
450464
})
451-
452-
assert.equal(process.stage, 'halted')
453-
process.run()
454-
455-
assert.equal(process.stage, 'running')
465+
assert.equal(p.stage, 'halted')
466+
p.run()
467+
assert.equal(p.stage, 'running')
456468
await promise
457-
458-
assert.equal(process.stage, 'fulfilled')
459-
assert.equal(process.output?.stdout, 'foo\n')
469+
assert.equal(p.stage, 'fulfilled')
470+
assert.equal(p.output.stdout, 'foo\n')
460471
})
461472
})
462473

test/vendor.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ describe('vendor API', () => {
3737

3838
test('fetch() works', async () => {
3939
assert.match(
40-
await fetch('https://medv.io').then((res) => res.text()),
41-
/Anton Medvedev/
40+
await fetch('https://example.com').then((res) => res.text()),
41+
/Example Domain/
4242
)
4343
})
4444

0 commit comments

Comments
 (0)