-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
utils.common.ts
37 lines (30 loc) · 1 KB
/
utils.common.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { env } from "@azure/test-utils-recorder";
import * as assert from "assert";
// Async iterator's polyfill for Node 8
if (!Symbol || !(Symbol as any).asyncIterator) {
(Symbol as any).asyncIterator = Symbol.for("Symbol.asyncIterator");
}
export function getKeyvaultName(): string {
const keyVaultEnvVarName = "KEYVAULT_NAME";
const keyVaultName: string | undefined = env[keyVaultEnvVarName];
if (!keyVaultName) {
throw new Error(`${keyVaultEnvVarName} environment variable not specified.`);
}
return keyVaultName;
}
export async function assertThrowsAbortError(cb: () => Promise<any>): Promise<void> {
let passed = false;
try {
await cb();
passed = true;
} catch (e) {
console.log(`name: ${e.name}, message: ${e.message}`);
assert.equal(e.name, "AbortError");
assert.equal(e.message, "The operation was aborted.");
}
if (passed) {
throw new Error("Expected cb to throw an AbortError");
}
}