Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion async/abortable_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Deno.test("abortable.AsyncIterable() handles already aborted signal", async () =
Deno.test("abortable.AsyncIterable() calls return before throwing", async () => {
const c = new AbortController();
let returnCalled = false;
let timeoutId: number;
let timeoutId;
const iterable: AsyncIterable<string> = {
[Symbol.asyncIterator]: () => ({
next: () =>
Expand Down
2 changes: 1 addition & 1 deletion async/unstable_abortable_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Deno.test("abortable.AsyncIterable() handles already aborted signal", async () =
Deno.test("abortable.AsyncIterable() calls return before throwing", async () => {
const c = new AbortController();
let returnCalled = false;
let timeoutId: number;
let timeoutId;
const iterable: AsyncIterable<string> = {
[Symbol.asyncIterator]: () => ({
next: () =>
Expand Down
2 changes: 1 addition & 1 deletion async/unstable_throttle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function throttle<T extends Array<any>>(
options?: ThrottleOptions,
): ThrottledFunction<T> {
const ensureLast = Boolean(options?.ensureLastCall);
let timeout = -1;
let timeout: ReturnType<typeof setTimeout> | undefined;

let lastExecution = -Infinity;
let flush: (() => void) | null = null;
Expand Down
2 changes: 1 addition & 1 deletion async/unstable_wait_for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function waitFor(
const { step = 100 } = options;

// Create a new promise that resolves when the predicate is true
let timer: number;
let timer: ReturnType<typeof setTimeout>;
const p: Promise<void> = new Promise(function (resolve) {
const setTimer = () => {
timer = setTimeout(async () => {
Expand Down
2 changes: 1 addition & 1 deletion cache/ttl_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export interface TtlCacheOptions<K, V> {
export class TtlCache<K, V> extends Map<K, V>
implements MemoizationCache<K, V> {
#defaultTtl: number;
#timeouts = new Map<K, number>();
#timeouts = new Map();
#eject?: ((ejectedKey: K, ejectedValue: V) => void) | undefined;
#slidingExpiration: boolean;
#entryTtls?: Map<K, number>;
Expand Down
2 changes: 1 addition & 1 deletion cli/unstable_progress_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class ProgressBar {
max: number;

#writer: WritableStreamDefaultWriter;
#id: number;
#id;
#startTime: number;
#previousTime: number;
#previousValue: number;
Expand Down
2 changes: 1 addition & 1 deletion cli/unstable_spinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class Spinner {

#interval: number;
#color: Color | undefined;
#intervalId: number | null = null;
#intervalId: ReturnType<typeof setInterval> | null = null;
#output: typeof Deno.stdout | typeof Deno.stderr;

/**
Expand Down
2 changes: 1 addition & 1 deletion testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This package provides utilities for testing.
import { assertSpyCalls, spy } from "@std/testing/mock";
import { FakeTime } from "@std/testing/time";

function secondInterval(cb: () => void): number {
function secondInterval(cb: () => void) {
return setInterval(cb, 1000);
}

Expand Down
2 changes: 1 addition & 1 deletion testing/bdd_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface GlobalContext {
}

let timerIdx = 1;
const timers = new Map<number, number>();
const timers = new Map();
function hookFns() {
timerIdx = 1;
timers.clear();
Expand Down
2 changes: 1 addition & 1 deletion testing/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
* } from "@std/testing/mock";
* import { FakeTime } from "@std/testing/time";
*
* function secondInterval(cb: () => void): number {
* function secondInterval(cb: () => void) {
* return setInterval(cb, 1000);
* }
*
Expand Down
39 changes: 20 additions & 19 deletions testing/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* } from "@std/testing/mock";
* import { FakeTime } from "@std/testing/time";
*
* function secondInterval(cb: () => void): number {
* function secondInterval(cb: () => void) {
* return setInterval(cb, 1000);
* }
*
Expand Down Expand Up @@ -138,15 +138,15 @@ function assertIsCallbackFunction(
}
}

const fakeSetTimeout: typeof globalThis.setTimeout = function (
callback,
function fakeSetTimeout(
callback: string | ((...args: unknown[]) => unknown),
delay = 0,
...args
) {
...args: unknown[]
): number {
assertIsCallbackFunction(callback, "setTimeout");
if (!time) throw new TimeError("Cannot set timeout: time is not faked");
return setTimer(callback, delay, args, false);
};
}

function fakeClearTimeout(id?: unknown) {
if (!time) throw new TimeError("Cannot clear timeout: time is not faked");
Expand All @@ -155,15 +155,15 @@ function fakeClearTimeout(id?: unknown) {
}
}

const fakeSetInterval: typeof globalThis.setInterval = function (
callback,
function fakeSetInterval(
callback: string | ((...args: unknown[]) => unknown),
delay = 0,
...args
) {
...args: unknown[]
): number {
assertIsCallbackFunction(callback, "setInterval");
if (!time) throw new TimeError("Cannot set interval: time is not faked");
return setTimer(callback, delay, args, true);
};
}

function fakeClearInterval(id?: unknown) {
if (!time) throw new TimeError("Cannot clear interval: time is not faked");
Expand All @@ -173,8 +173,7 @@ function fakeClearInterval(id?: unknown) {
}

function setTimer(
// deno-lint-ignore no-explicit-any
callback: (...args: any[]) => void,
callback: (...args: unknown[]) => unknown,
delay = 0,
args: unknown[],
repeat = false,
Expand Down Expand Up @@ -209,9 +208,11 @@ function fakeAbortSignalTimeout(delay: number): AbortSignal {

function overrideGlobals() {
globalThis.Date = FakeDate;
globalThis.setTimeout = fakeSetTimeout;
globalThis.setTimeout =
fakeSetTimeout as unknown as typeof globalThis.setTimeout;
globalThis.clearTimeout = fakeClearTimeout;
globalThis.setInterval = fakeSetInterval;
globalThis.setInterval =
fakeSetInterval as unknown as typeof globalThis.setInterval;
globalThis.clearInterval = fakeClearInterval;
AbortSignal.timeout = fakeAbortSignalTimeout;
}
Expand Down Expand Up @@ -245,7 +246,7 @@ let now: number;
let initializedAt: number;
let advanceRate: number;
let advanceFrequency: number;
let advanceIntervalId: number | undefined;
let advanceIntervalId: ReturnType<typeof setInterval> | undefined;
let timerId: Generator<number>;
let dueNodes: Map<number, DueNode>;
let dueTree: RedBlackTree<DueNode>;
Expand All @@ -265,7 +266,7 @@ let dueTree: RedBlackTree<DueNode>;
* } from "@std/testing/mock";
* import { FakeTime } from "@std/testing/time";
*
* function secondInterval(cb: () => void): number {
* function secondInterval(cb: () => void) {
* return setInterval(cb, 1000);
* }
*
Expand Down Expand Up @@ -575,7 +576,7 @@ export class FakeTime {
);
}
return await new Promise((resolve, reject) => {
let timer: number | null = null;
let timer: ReturnType<typeof setTimeout> | null = null;
const abort = () =>
FakeTime
.restoreFor(() => {
Expand Down Expand Up @@ -629,7 +630,7 @@ export class FakeTime {
* } from "@std/testing/mock";
* import { FakeTime } from "@std/testing/time";
*
* function secondInterval(cb: () => void): number {
* function secondInterval(cb: () => void) {
* return setInterval(cb, 1000);
* }
*
Expand Down
6 changes: 3 additions & 3 deletions testing/time_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Deno.test("FakeTime controls timeouts", () => {

setTimeout(cb, 1000, "a");
setTimeout(cb, 1500, "b");
const timeout: number = setTimeout(cb, 1750, "c");
const timeout = setTimeout(cb, 1750, "c");
setTimeout(cb, 2000, "d");
time.tick(1250);
expected.push({ args: ["a"], returned: 7000 });
Expand Down Expand Up @@ -199,7 +199,7 @@ Deno.test("FakeTime controls intervals", () => {
const cb = spy(fromNow());
const expected: SpyCall[] = [];

const interval: number = setInterval(cb, 1000);
const interval = setInterval(cb, 1000);
time.tick(250);
assertEquals(cb.calls, expected);
time.tick(250);
Expand All @@ -226,7 +226,7 @@ Deno.test("FakeTime calls timeout and interval callbacks in correct order", () =
const timeoutExpected: SpyCall[] = [];
const intervalExpected: SpyCall[] = [];

const interval: number = setInterval(intervalCb, 1000);
const interval = setInterval(intervalCb, 1000);
setTimeout(timeoutCb, 500);
time.tick(250);
assertEquals(intervalCb.calls, intervalExpected);
Expand Down
4 changes: 2 additions & 2 deletions toml/_parser_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ Deno.test({
Deno.test({
name: "(private) deepAssign() works correctly",
fn() {
const source = {
const source: Record<string, unknown> = {
foo: {
items: [
{
Expand Down Expand Up @@ -528,7 +528,7 @@ Deno.test({
email: {
x: { main: "mail@example.com" },
},
} as unknown,
},
},
],
},
Expand Down
Loading