-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: measure codecov, add missing tests (#359)
* test: measure codecov, add missing tests * test: relax some asserts * test: tweak up test utils * test: fixes * test: separate tests for experimental api * test: check withTimeout w/ 0 * test: suppress concurrency * test: use local server for http test * test: fix http hang * test: add test for econnrefused * test: replace localhost with 127.0.0.1 due to nodejs 17 requirement * test: check --prefix and --shell flags
- Loading branch information
1 parent
d7ed8c7
commit a203460
Showing
12 changed files
with
282 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/node_modules/ | ||
package-lock.json | ||
yarn.lock | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// 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 {echo, retry, startSpinner, withTimeout} from '../src/experimental.mjs' | ||
import {assert, test as t} from './test-utils.mjs' | ||
import chalk from 'chalk' | ||
|
||
const test = t.bind(null, 'experimental') | ||
|
||
if (test('Retry works')) { | ||
let exitCode = 0 | ||
let now = Date.now() | ||
try { | ||
await retry(5, 50)`exit 123` | ||
} catch (p) { | ||
exitCode = p.exitCode | ||
} | ||
assert.equal(exitCode, 123) | ||
assert(Date.now() >= now + 50 * (5 - 1)) | ||
} | ||
|
||
if (test('withTimeout works')) { | ||
let exitCode = 0 | ||
let signal | ||
try { | ||
await withTimeout(100, 'SIGKILL')`sleep 9999` | ||
} catch (p) { | ||
exitCode = p.exitCode | ||
signal = p.signal | ||
} | ||
assert.equal(exitCode, null) | ||
assert.equal(signal, 'SIGKILL') | ||
|
||
let p = await withTimeout(0)`echo 'test'` | ||
assert.equal(p.stdout.trim(), 'test') | ||
} | ||
|
||
if (test('echo works')) { | ||
echo(chalk.red('foo'), chalk.green('bar'), chalk.bold('baz')) | ||
echo`${chalk.red('foo')} ${chalk.green('bar')} ${chalk.bold('baz')}` | ||
echo(await $`echo ${chalk.red('foo')}`, await $`echo ${chalk.green('bar')}`, await $`echo ${chalk.bold('baz')}`) | ||
} | ||
|
||
if (test('spinner works')) { | ||
let s = startSpinner('waiting') | ||
|
||
await sleep(1000) | ||
s() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
HTTP/1.1 200 OK | ||
Content-Type: text/javascript; charset=UTF-8 | ||
Content-Length: 15 | ||
Server: netcat! | ||
|
||
$`echo 'test'` |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// 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 {printTestDigest} from './test-utils.mjs' | ||
await import('./zx.test.mjs') | ||
await import('./index.test.mjs') | ||
await import('./experimental.test.mjs') | ||
|
||
printTestDigest() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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 chalk from 'chalk' | ||
|
||
export {strict as assert} from 'assert' | ||
|
||
let всегоТестов = 0 | ||
|
||
export function test(group, name) { | ||
let фильтр = process.argv[3] || '.' | ||
if (RegExp(фильтр).test(name) || RegExp(фильтр).test(group)) { | ||
console.log('\n' + chalk.bgGreenBright.black(`${chalk.inverse(' ' + group + ' ')} ${name} `)) | ||
всегоТестов++ | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
export const printTestDigest = () => { | ||
console.log('\n' + | ||
chalk.black.bgYellowBright(` zx version is ${require('../package.json').version} `) + '\n' + | ||
chalk.greenBright(` 🍺 ${всегоТестов} tests passed `) | ||
) | ||
} |
Oops, something went wrong.