-
-
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: separate tests for experimental api
- Loading branch information
1 parent
24c4950
commit 813066a
Showing
6 changed files
with
73 additions
and
52 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
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,57 @@ | ||
// 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') | ||
} | ||
|
||
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
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