Skip to content

Commit a950a05

Browse files
authored
test: fix flaky test (google#754)
1 parent 9d5b3e4 commit a950a05

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

examples/parallel.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// See the License for the specific language governing permissions and
1515
// limitations under the License.
1616

17-
import { spinner } from 'zx/experimental'
17+
import { spinner } from 'zx'
1818

1919
const tests = await glob('test/*.test.js')
2020
await spinner('running tests', async () => {

src/core.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ function syncCwd() {
556556

557557
export function cd(dir: string | ProcessOutput) {
558558
if (dir instanceof ProcessOutput) {
559-
dir = dir.toString().replace(/\n+$/, '')
559+
dir = dir.toString().trim()
560560
}
561561

562562
$.log({ kind: 'cd', dir })

test/core.test.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
// limitations under the License.
1414

1515
import assert from 'node:assert'
16-
import { test, describe, beforeEach } from 'node:test'
16+
import { test, describe } from 'node:test'
1717
import { inspect } from 'node:util'
18+
import { basename } from 'node:path'
1819
import { Readable, Writable } from 'node:stream'
1920
import { Socket } from 'node:net'
2021
import { ProcessPromise, ProcessOutput } from '../build/index.js'
@@ -297,10 +298,13 @@ describe('core', () => {
297298
})
298299

299300
test('cd() accepts ProcessOutput in addition to string', async () => {
300-
within(async () => {
301+
await within(async () => {
301302
const tmpDir = await $`mktemp -d`
302303
cd(tmpDir)
303-
assert.equal(process.cwd(), tmpDir.toString().trimEnd())
304+
assert.equal(
305+
basename(process.cwd()),
306+
basename(tmpDir.toString().trimEnd())
307+
)
304308
})
305309
})
306310

0 commit comments

Comments
 (0)