Commit bc2a08c

Anton Golub <antongolub@antongolub.com>
2024-04-30 16:45:27
test: check preset helpers (#791)
1 parent 18e8e13
Changed files (3)
src/core.ts
@@ -127,6 +127,7 @@ export function usePwsh() {
 export function useBash() {
   $.shell = which.sync('bash')
   $.prefix = 'set -euo pipefail;'
+  $.postfix = ''
   $.quote = quote
 }
 
test/fixtures/js-project/package-lock.json
@@ -9,7 +9,7 @@
       }
     },
     "../../..": {
-      "version": "8.0.1",
+      "version": "8.0.2",
       "license": "Apache-2.0",
       "bin": {
         "zx": "build/cli.js"
test/core.test.js
@@ -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'
@@ -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)
+    })
   })
 })