Skip to content

Commit

Permalink
refactor: move to std assert
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Feb 13, 2024
1 parent 5b45806 commit f8ab89e
Show file tree
Hide file tree
Showing 24 changed files with 46 additions and 58 deletions.
3 changes: 1 addition & 2 deletions application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// deno-lint-ignore-file

import {
assert,
assertEquals,
assertRejects,
assertStrictEquals,
Expand All @@ -17,7 +16,7 @@ import type {
State,
} from "./application.ts";
import { Context } from "./context.ts";
import { errors, KeyStack, Status } from "./deps.ts";
import { assert, errors, KeyStack, Status } from "./deps.ts";
import { Server } from "./http_server_native.ts";
import { NativeRequest } from "./http_server_native_request.ts";
import type {
Expand Down
9 changes: 2 additions & 7 deletions application.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2018-2024 the oak authors. All rights reserved. MIT license.

import { Context } from "./context.ts";
import { KeyStack, Status, STATUS_TEXT } from "./deps.ts";
import { assert, KeyStack, Status, STATUS_TEXT } from "./deps.ts";
import { type NativeRequest } from "./http_server_native_request.ts";
import {
compose,
Expand All @@ -17,12 +17,7 @@ import {
ServerConstructor,
ServerRequest,
} from "./types.ts";
import {
assert,
createPromiseWithResolvers,
isNetAddr,
isNode,
} from "./util.ts";
import { createPromiseWithResolvers, isNetAddr, isNode } from "./util.ts";

export interface ListenOptionsBase {
/** The port to listen on. If not specified, defaults to `0`, which allows the
Expand Down
10 changes: 8 additions & 2 deletions body.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { Body } from "./body.ts";
import { concat, isHttpError, Status, timingSafeEqual } from "./deps.ts";
import { assert, assertEquals, assertRejects } from "./test_deps.ts";
import {
assert,
concat,
isHttpError,
Status,
timingSafeEqual,
} from "./deps.ts";
import { assertEquals, assertRejects } from "./test_deps.ts";
import { type ServerRequest } from "./types.ts";

const MULTIPART_BODY_FIXTURE =
Expand Down
14 changes: 3 additions & 11 deletions context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@

// deno-lint-ignore-file

import {
assert,
assertEquals,
assertStrictEquals,
assertThrows,
} from "./test_deps.ts";
import { assertEquals, assertStrictEquals, assertThrows } from "./test_deps.ts";
import type { Application, State } from "./application.ts";
import { Context } from "./context.ts";
import { errors, SecureCookieMap, Status } from "./deps.ts";
import {
isNativeRequest,
NativeRequest,
} from "./http_server_native_request.ts";
import { assert, errors, SecureCookieMap, Status } from "./deps.ts";
import { NativeRequest } from "./http_server_native_request.ts";
import type {} from "./http_server_native.ts";
import { Request as OakRequest } from "./request.ts";
import { Response as OakResponse } from "./response.ts";
Expand Down
2 changes: 1 addition & 1 deletion context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import type { Application, State } from "./application.ts";
import {
assert,
createHttpError,
type ErrorStatus,
type HttpErrorOptions,
Expand All @@ -15,7 +16,6 @@ import { Request } from "./request.ts";
import { Response } from "./response.ts";
import { send, SendOptions } from "./send.ts";
import type { ServerRequest, UpgradeWebSocketOptions } from "./types.ts";
import { assert } from "./util.ts";

export interface ContextOptions<
S extends AS = State,
Expand Down
1 change: 1 addition & 0 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// `std` dependencies

export { assert } from "https://deno.land/[email protected]/assert/assert.ts";
export { concat } from "https://deno.land/[email protected]/bytes/concat.ts";
export { copy as copyBytes } from "https://deno.land/[email protected]/bytes/copy.ts";
export { timingSafeEqual } from "https://deno.land/[email protected]/crypto/timing_safe_equal.ts";
Expand Down
3 changes: 2 additions & 1 deletion etag.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018-2024 the oak authors. All rights reserved. MIT license.

import { assert, assertEquals } from "./test_deps.ts";
import { assert } from "./deps.ts";
import { assertEquals } from "./test_deps.ts";
import {
createMockApp,
createMockContext,
Expand Down
2 changes: 1 addition & 1 deletion forwarded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @module
*/

import { assert } from "./util.ts";
import { assert } from "./deps.ts";

/**
* Unescape a string.
Expand Down
4 changes: 2 additions & 2 deletions middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

// deno-lint-ignore-file

import { assert, assertEquals, assertStrictEquals } from "./test_deps.ts";
import { errors } from "./deps.ts";
import { assertEquals, assertStrictEquals } from "./test_deps.ts";
import { assert, errors } from "./deps.ts";
import { createMockContext } from "./testing.ts";
import {
compose,
Expand Down
3 changes: 2 additions & 1 deletion middleware/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import { Application } from "../application.ts";
import { type Context } from "../context.ts";
import { assert } from "../deps.ts";
import { Router } from "../router.ts";
import { createMockContext, createMockNext } from "../testing.ts";
import { assert, assertEquals, assertStrictEquals } from "../test_deps.ts";
import { assertEquals, assertStrictEquals } from "../test_deps.ts";

import { proxy } from "./proxy.ts";

Expand Down
3 changes: 2 additions & 1 deletion middleware/serve.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { type State } from "../application.ts";
import { Context } from "../context.ts";
import { assert } from "../deps.ts";
import { NativeRequest } from "../http_server_native_request.ts";
import { type Next } from "../middleware.ts";
import { type RouteParams, Router, type RouterContext } from "../router.ts";
import { assert, assertEquals, assertStrictEquals } from "../test_deps.ts";
import { assertEquals, assertStrictEquals } from "../test_deps.ts";
import { createMockApp, createMockNext } from "../testing.ts";
import { isNode } from "../util.ts";

Expand Down
3 changes: 2 additions & 1 deletion mod.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018-2024 the oak authors. All rights reserved. MIT license.

import { assert, assertEquals } from "./test_deps.ts";
import { assert } from "./deps.ts";
import { assertEquals } from "./test_deps.ts";
import * as mod from "./mod.ts";

Deno.test({
Expand Down
4 changes: 2 additions & 2 deletions range.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2018-2024 the oak authors. All rights reserved. MIT license.

import { assert, assertEquals, assertThrows } from "./test_deps.ts";
import { assertEquals, assertThrows } from "./test_deps.ts";

import { concat, copyBytes, errors } from "./deps.ts";
import { assert, concat, copyBytes, errors } from "./deps.ts";
import { calculate } from "./etag.ts";
import { ifRange, MultiPartStream, parseRange } from "./range.ts";

Expand Down
3 changes: 2 additions & 1 deletion range.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018-2024 the oak authors. All rights reserved. MIT license.

import {
assert,
concat,
contentType,
copyBytes,
Expand All @@ -9,7 +10,7 @@ import {
} from "./deps.ts";
import { calculate } from "./etag.ts";
import type { FileInfo } from "./etag.ts";
import { assert, DEFAULT_CHUNK_SIZE } from "./util.ts";
import { DEFAULT_CHUNK_SIZE } from "./util.ts";

const ETAG_RE = /(?:W\/)?"[ !#-\x7E\x80-\xFF]+"/;

Expand Down
3 changes: 1 addition & 2 deletions request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

// deno-lint-ignore-file

import { isHttpError, Status } from "./deps.ts";
import { assert, isHttpError, Status } from "./deps.ts";
import {
assert,
assertEquals,
assertRejects,
assertStrictEquals,
Expand Down
4 changes: 2 additions & 2 deletions response.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2018-2024 the oak authors. All rights reserved. MIT license.

import { Status } from "./deps.ts";
import { assert, assertEquals, assertThrows } from "./test_deps.ts";
import { assert, Status } from "./deps.ts";
import { assertEquals, assertThrows } from "./test_deps.ts";
import type { Request } from "./request.ts";
import { REDIRECT_BACK, Response } from "./response.ts";
import { isNode } from "./util.ts";
Expand Down
3 changes: 2 additions & 1 deletion router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import type { State } from "./application.ts";
import type { Context } from "./context.ts";
import {
assert,
compile,
errors,
type HTTPMethods,
Expand All @@ -40,7 +41,7 @@ import {
TokensToRegexpOptions,
} from "./deps.ts";
import { compose, Middleware } from "./middleware.ts";
import { assert, decodeComponent } from "./util.ts";
import { decodeComponent } from "./util.ts";

interface Matches<R extends string> {
path: Layer<R>[];
Expand Down
4 changes: 2 additions & 2 deletions send.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018-2024 the oak authors. All rights reserved. MIT license.

import { assert, assertEquals, assertStrictEquals } from "./test_deps.ts";
import { assertEquals, assertStrictEquals } from "./test_deps.ts";
import {
createMockApp,
createMockContext,
Expand All @@ -9,7 +9,7 @@ import {

import type { Application } from "./application.ts";
import type { Context } from "./context.ts";
import { errors } from "./deps.ts";
import { assert, errors } from "./deps.ts";
import * as etag from "./etag.ts";
import type { RouteParams } from "./router.ts";
import { send } from "./send.ts";
Expand Down
9 changes: 2 additions & 7 deletions send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import type { Context } from "./context.ts";
import { calculate, FileInfo, ifNoneMatch } from "./etag.ts";
import {
assert,
basename,
createHttpError,
extname,
Expand All @@ -16,13 +17,7 @@ import {
} from "./deps.ts";
import { ifRange, MultiPartStream, parseRange } from "./range.ts";
import type { Response } from "./response.ts";
import {
assert,
decodeComponent,
getBoundary,
isNode,
resolvePath,
} from "./util.ts";
import { decodeComponent, getBoundary, isNode, resolvePath } from "./util.ts";

if (isNode()) {
console.warn("oak send() does not work under Node.js.");
Expand Down
3 changes: 2 additions & 1 deletion structured_clone.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2018-2024 the oak authors. All rights reserved. MIT license.

import { assert, assertEquals } from "./test_deps.ts";
import { assertEquals } from "./test_deps.ts";

import { assert } from "./deps.ts";
import { cloneState } from "./structured_clone.ts";

Deno.test({
Expand Down
1 change: 0 additions & 1 deletion test_deps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2018-2024 the oak authors. All rights reserved. MIT license.

export { assert } from "https://deno.land/[email protected]/assert/assert.ts";
export { assertEquals } from "https://deno.land/[email protected]/assert/assert_equals.ts";
export { assertInstanceOf } from "https://deno.land/[email protected]/assert/assert_instance_of.ts";
export { assertRejects } from "https://deno.land/[email protected]/assert/assert_rejects.ts";
Expand Down
3 changes: 2 additions & 1 deletion testing.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018-2024 the oak authors. All rights reserved. MIT license.

import { assert, assertEquals, assertStrictEquals } from "./test_deps.ts";
import { assert } from "./deps.ts";
import { assertEquals, assertStrictEquals } from "./test_deps.ts";

import {
createMockApp,
Expand Down
4 changes: 2 additions & 2 deletions util.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2018-2024 the oak authors. All rights reserved. MIT license.

import { errors } from "./deps.ts";
import { assert, assertEquals, assertThrows } from "./test_deps.ts";
import { assert, errors } from "./deps.ts";
import { assertEquals, assertThrows } from "./test_deps.ts";
import { decodeComponent, getRandomFilename, resolvePath } from "./util.ts";

Deno.test({
Expand Down
6 changes: 0 additions & 6 deletions util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ export const DEFAULT_CHUNK_SIZE = 16_640; // 17 Kib
/** Body types which will be coerced into strings before being sent. */
export const BODY_TYPES = ["string", "number", "bigint", "boolean", "symbol"];

export function assert(cond: unknown, msg = "Assertion failed"): asserts cond {
if (!cond) {
throw new Error(msg);
}
}

const hasPromiseWithResolvers = "withResolvers" in Promise;

/** Offloads to the native `Promise.withResolvers` when available.
Expand Down

0 comments on commit f8ab89e

Please sign in to comment.