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 d5226ba
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 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 `)
)
}
7 changes: 2 additions & 5 deletions test/zx.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

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

if (test('supports `-v` flag / prints version')) {
Expand Down Expand Up @@ -57,7 +57,4 @@ if (test('Markdown scripts are working')) {
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 d5226ba

Please sign in to comment.