diff --git a/package.json b/package.json index 37f70c0f40..310065e2c5 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/full.test.mjs b/test/full.test.mjs new file mode 100644 index 0000000000..1ad80e9d8b --- /dev/null +++ b/test/full.test.mjs @@ -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' diff --git a/test/index.test.mjs b/test/index.test.mjs index a212f5e9f1..7d9e58da45 100755 --- a/test/index.test.mjs +++ b/test/index.test.mjs @@ -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')) { @@ -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(() => { @@ -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() diff --git a/test/test-utils.mjs b/test/test-utils.mjs index ebf2789f83..fce8c2c211 100644 --- a/test/test-utils.mjs +++ b/test/test-utils.mjs @@ -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 `) + ) +} diff --git a/test/zx.test.mjs b/test/zx.test.mjs index c9238e3f62..416bb1e71c 100644 --- a/test/zx.test.mjs +++ b/test/zx.test.mjs @@ -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) } @@ -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')) } @@ -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()