mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 04:39:10 +00:00
add assertResources sanitizer to cli/js/ unit tests (#4161)
This commit is contained in:
parent
199fb195f3
commit
f55b22e195
11 changed files with 95 additions and 36 deletions
|
@ -1,23 +1,11 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { test, testPerm, assert, assertEquals } from "./test_util.ts";
|
||||
|
||||
export interface ResolvableMethods<T> {
|
||||
resolve: (value?: T | PromiseLike<T>) => void;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
reject: (reason?: any) => void;
|
||||
}
|
||||
|
||||
export type Resolvable<T> = Promise<T> & ResolvableMethods<T>;
|
||||
|
||||
export function createResolvable<T>(): Resolvable<T> {
|
||||
let methods: ResolvableMethods<T>;
|
||||
const promise = new Promise<T>((resolve, reject): void => {
|
||||
methods = { resolve, reject };
|
||||
});
|
||||
// TypeScript doesn't know that the Promise callback occurs synchronously
|
||||
// therefore use of not null assertion (`!`)
|
||||
return Object.assign(promise, methods!) as Resolvable<T>;
|
||||
}
|
||||
import {
|
||||
test,
|
||||
testPerm,
|
||||
assert,
|
||||
assertEquals,
|
||||
createResolvable
|
||||
} from "./test_util.ts";
|
||||
|
||||
test(async function workersBasic(): Promise<void> {
|
||||
const promise = createResolvable();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue