Skip to content

Commit

Permalink
test: fix flaky test (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub authored Mar 29, 2024
1 parent 9d5b3e4 commit a950a05
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/parallel.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { spinner } from 'zx/experimental'
import { spinner } from 'zx'

const tests = await glob('test/*.test.js')
await spinner('running tests', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ function syncCwd() {

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

$.log({ kind: 'cd', dir })
Expand Down
10 changes: 7 additions & 3 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
// limitations under the License.

import assert from 'node:assert'
import { test, describe, beforeEach } from 'node:test'
import { test, describe } from 'node:test'
import { inspect } from 'node:util'
import { basename } from 'node:path'
import { Readable, Writable } from 'node:stream'
import { Socket } from 'node:net'
import { ProcessPromise, ProcessOutput } from '../build/index.js'
Expand Down Expand Up @@ -297,10 +298,13 @@ describe('core', () => {
})

test('cd() accepts ProcessOutput in addition to string', async () => {
within(async () => {
await within(async () => {
const tmpDir = await $`mktemp -d`
cd(tmpDir)
assert.equal(process.cwd(), tmpDir.toString().trimEnd())
assert.equal(
basename(process.cwd()),
basename(tmpDir.toString().trimEnd())
)
})
})

Expand Down

0 comments on commit a950a05

Please sign in to comment.