Skip to content

Commit

Permalink
test: check preset helpers (#791)
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub authored Apr 30, 2024
1 parent 18e8e13 commit bc2a08c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export function usePwsh() {
export function useBash() {
$.shell = which.sync('bash')
$.prefix = 'set -euo pipefail;'
$.postfix = ''
$.quote = quote
}

Expand Down
43 changes: 33 additions & 10 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import assert from 'node:assert'
import { test, describe } from 'node:test'
import { test, describe, before, after } from 'node:test'
import { inspect } from 'node:util'
import { basename } from 'node:path'
import { Readable, Writable } from 'node:stream'
Expand Down Expand Up @@ -584,15 +584,38 @@ describe('core', () => {
assert.ok(ok, 'Expected failure!')
})

test('usePwsh() sets proper defaults', () => {
describe('presets', () => {
const originalWhichSync = which.sync
which.sync = (bin) => (bin === 'pwsh' ? 'pwsh' : originalWhichSync(bin))
usePwsh()
assert.equal($.shell, 'pwsh')
assert.equal($.prefix, '')
assert.equal($.postfix, '; exit $LastExitCode')
assert.equal($.quote, quotePowerShell)
which.sync = originalWhichSync
useBash()
before(() => {
which.sync = (bin) => bin
})
after(() => {
which.sync = originalWhichSync
useBash()
})

test('usePwsh()', () => {
usePwsh()
assert.equal($.shell, 'pwsh')
assert.equal($.prefix, '')
assert.equal($.postfix, '; exit $LastExitCode')
assert.equal($.quote, quotePowerShell)
})

test('usePowerShell()', () => {
usePowerShell()
assert.equal($.shell, 'powershell.exe')
assert.equal($.prefix, '')
assert.equal($.postfix, '; exit $LastExitCode')
assert.equal($.quote, quotePowerShell)
})

test('useBash()', () => {
useBash()
assert.equal($.shell, 'bash')
assert.equal($.prefix, 'set -euo pipefail;')
assert.equal($.postfix, '')
assert.equal($.quote, quote)
})
})
})
2 changes: 1 addition & 1 deletion test/fixtures/js-project/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bc2a08c

Please sign in to comment.