Testing Command Execution Patterns in google/zx
This test suite validates core functionality of the zx library’s command execution capabilities in TypeScript. It focuses on both synchronous and asynchronous command processing, along with error handling mechanisms.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
google/zx
test/smoke/ts.test.ts
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import * as assert from 'node:assert'
import 'zx/globals'
;(async () => {
// smoke test async
{
const p = await $`echo foo`
assert.match(p.stdout, /foo/)
}
// smoke test sync
{
const p = $.sync`echo foo`
assert.match(p.stdout, /foo/)
}
// captures err stack
{
const p = await $({ nothrow: true })`echo foo; exit 3`
assert.match(p.message, /exit code: 3/)
}
})()
console.log('smoke ts: ok')