add assertResources sanitizer to cli/js/ unit tests (#4161)

This commit is contained in:
Bartek Iwańczuk 2020-02-29 18:45:47 +01:00 committed by GitHub
parent 199fb195f3
commit f55b22e195
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 95 additions and 36 deletions

View file

@ -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();