Skip to content

test(core): check $ uses defaults store #1079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
$,
ProcessPromise,
ProcessOutput,
defaults,
resolveDefaults,
cd,
syncProcessCwd,
Expand Down Expand Up @@ -221,6 +222,20 @@ describe('core', () => {
})

describe('$({opts}) API', () => {
it('$ proxy uses `defaults` store', () => {
assert.equal($.foo, undefined)
defaults.foo = 'bar'
$.baz = 'qux'
assert.equal($.foo, 'bar')
assert.equal($.baz, 'qux')
assert.equal(defaults.baz, 'qux')
delete defaults.foo
$.baz = undefined
assert.equal($.foo, undefined)
assert.equal($.baz, undefined)
assert.equal(defaults.baz, undefined)
})

test('provides presets', async () => {
const $1 = $({ nothrow: true })
assert.equal((await $1`exit 1`).exitCode, 1)
Expand Down Expand Up @@ -396,7 +411,7 @@ describe('core', () => {
describe('ProcessPromise', () => {
test('getters', async () => {
const p = $`echo foo`
assert.ok(p.pid > 0)
assert.ok(typeof p.pid === 'number')
assert.ok(typeof p.id === 'string')
assert.ok(typeof p.cmd === 'string')
assert.ok(typeof p.fullCmd === 'string')
Expand Down Expand Up @@ -439,24 +454,20 @@ describe('core', () => {
assert.equal(p.stage, 'fulfilled')
})

it('all transition', async () => {
it('all transitions', async () => {
const { promise, resolve, reject } = Promise.withResolvers()
const process = new ProcessPromise(noop, noop)

assert.equal(process.stage, 'initial')
process._bind('echo foo', 'test', resolve, reject, {
...resolveDefaults(),
const p = new ProcessPromise(noop, noop)
assert.equal(p.stage, 'initial')
p._bind('echo foo', 'test', resolve, reject, {
...defaults,
halt: true,
})

assert.equal(process.stage, 'halted')
process.run()

assert.equal(process.stage, 'running')
assert.equal(p.stage, 'halted')
p.run()
assert.equal(p.stage, 'running')
await promise

assert.equal(process.stage, 'fulfilled')
assert.equal(process.output?.stdout, 'foo\n')
assert.equal(p.stage, 'fulfilled')
assert.equal(p.output.stdout, 'foo\n')
})
})

Expand Down
4 changes: 2 additions & 2 deletions test/vendor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ describe('vendor API', () => {

test('fetch() works', async () => {
assert.match(
await fetch('https://medv.io').then((res) => res.text()),
/Anton Medvedev/
await fetch('https://example.com').then((res) => res.text()),
/Example Domain/
)
})

Expand Down
Loading