Skip to content

Commit

Permalink
test: tweak up test utils
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Mar 18, 2022
1 parent de863f2 commit 11e3380
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"scripts": {
"test:cov": "c8 --reporter=html npm run test",
"test": "npm run test:index && npm run test:cli",
"test": "node zx.mjs test/full.test.mjs",
"test:cli": "node zx.mjs test/zx.test.mjs",
"test:index": "node zx.mjs test/index.test.mjs"
},
Expand Down
16 changes: 16 additions & 0 deletions test/full.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2022 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 './index.test.mjs'
import './zx.test.mjs'
11 changes: 3 additions & 8 deletions test/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import chalk from 'chalk'
import {Writable} from 'stream'
import {Socket} from 'net'

import {assert, test, testcount} from './test-utils.mjs'
import {assert, printTestDigest, test} from './test-utils.mjs'
import {retry, echo, startSpinner, withTimeout} from '../src/experimental.mjs'

if (test('Only stdout is used during command substitution')) {
Expand Down Expand Up @@ -117,7 +117,7 @@ if (test('Pipes are working')) {
}

// Works on macOS but fails oon ubuntu...
// if ('question') {
// if (test('question')) {
// let p = question('foo or bar? ', {choices: ['foo', 'bar']})
//
// setTimeout(() => {
Expand Down Expand Up @@ -324,15 +324,10 @@ if (test('spinner works (experimental)')) {
s()
}

let version
if (test('require() is working in ESM')) {
let data = require('../package.json')
version = data.version
assert.equal(data.name, 'zx')
assert.equal(data, require('zx/package.json'))
}

console.log('\n' +
chalk.black.bgYellowBright(` zx version is ${version} `) + '\n' +
chalk.greenBright(` 🍺 ${testcount()} tests passed `)
)
printTestDigest()
7 changes: 6 additions & 1 deletion test/test-utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ export function test(name) {
return false
}

export const testcount = () => всегоТестов
export const printTestDigest = () => {
console.log('\n' +
chalk.black.bgYellowBright(` zx version is ${require('../package.json').version} `) + '\n' +
chalk.greenBright(` 🍺 ${всегоТестов} tests passed `)
)
}
18 changes: 7 additions & 11 deletions test/zx.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {assert, test, testcount} from './test-utils.mjs'
import chalk from 'chalk'
import {assert, printTestDigest, test} from './test-utils.mjs'

if (test('supports `-v` flag / prints version')) {
let v = (await $`node zx.mjs -v`).toString().trim()
let v = (await $`node ./zx.mjs -v`).toString().trim()
assert.equal(v, require('../package.json').version)
}

Expand All @@ -31,11 +30,11 @@ if (test('prints help')) {
}

if (test('supports `--experimental` flag')) {
await $`echo 'echo("test")' | node zx.mjs --experimental`
await $`echo 'echo("test")' | node ./zx.mjs --experimental`
}

if (test('supports `--quiet` flag / Quiet mode is working')) {
let p = await $`node zx.mjs --quiet docs/markdown.md`
let p = await $`node ./zx.mjs --quiet docs/markdown.md`
assert(!p.stdout.includes('whoami'))
}

Expand All @@ -50,14 +49,11 @@ if (test('Scripts with no extension')) {
}

if (test('The require() is working from stdin')) {
await $`node zx.mjs <<< 'require("./package.json").name'`
await $`node ./zx.mjs <<< 'require("./package.json").name'`
}

if (test('Markdown scripts are working')) {
await $`node zx.mjs docs/markdown.md`
await $`node ./zx.mjs docs/markdown.md`
}

console.log('\n' +
chalk.black.bgYellowBright(` zx version is ${require('../package.json').version} `) + '\n' +
chalk.greenBright(` 🍺 ${testcount()} tests passed `)
)
printTestDigest()

0 comments on commit 11e3380

Please sign in to comment.