Skip to content

Commit

Permalink
monorepo tests enablement
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Jun 21, 2024
1 parent 2d356cb commit cca5ac9
Show file tree
Hide file tree
Showing 51 changed files with 145 additions and 166 deletions.
3 changes: 3 additions & 0 deletions core/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"./unsafe_tests/**/*"
]
},
"tasks": {
"clean": "rm -rf ./lib ./cjs ./esm"
},
"imports": {
"@nats-io/nkeys": "jsr:@nats-io/[email protected]",
"@nats-io/nuid": "jsr:@nats-io/[email protected]"
Expand Down
19 changes: 13 additions & 6 deletions core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,14 @@ export interface Server {
tlsName: string;

resolve(
opts: Partial<{ fn: DnsResolveFn; randomize: boolean; debug?: boolean, resolve?: boolean }>,
opts: Partial<
{
fn: DnsResolveFn;
randomize: boolean;
debug?: boolean;
resolve?: boolean;
}
>,
): Promise<Server[]>;
}

Expand Down Expand Up @@ -1050,11 +1057,11 @@ export interface ConnectionOptions {
noAsyncTraces?: boolean;

/**
* When false, the connect function will not perform any hostname resolution. Note that
* by default this option will be true if the client supports hostname resolution.
* Note that on clients that don't supported (mainly the websocket client, setting this
* option to true, will throw an exception as this option is not available.
*/
* When false, the connect function will not perform any hostname resolution. Note that
* by default this option will be true if the client supports hostname resolution.
* Note that on clients that don't supported (mainly the websocket client, setting this
* option to true, will throw an exception as this option is not available.
*/
resolve?: boolean;
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/internal_mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export { Nuid, nuid } from "./nuid.ts";
export type { TypedSubscriptionOptions } from "./types.ts";

export { MsgImpl } from "./msg.ts";
export { setTransportFactory, getResolveFn } from "./transport.ts";
export { getResolveFn, setTransportFactory } from "./transport.ts";
export type { Transport, TransportFactory } from "./transport.ts";
export { Connect, INFO, ProtocolHandler } from "./protocol.ts";
export type { Backoff, Deferred, Delay, Perf, Timeout } from "./util.ts";
Expand Down
2 changes: 1 addition & 1 deletion core/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ export class ProtocolHandler implements Dispatcher<ParserEvent> {
fn: getResolveFn(),
debug: this.options.debug,
randomize: !this.options.noRandomize,
resolve
resolve,
});

let lastErr: Error | null = null;
Expand Down
7 changes: 1 addition & 6 deletions core/tests/auth_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
_setup,
assertErrorCode,
cleanup,
NatsServer,
} from "../../test_helpers/mod.ts";
import { _setup, assertErrorCode, cleanup, NatsServer } from "test_helpers";
import {
assert,
assertArrayIncludes,
Expand Down
11 changes: 8 additions & 3 deletions core/tests/authenticator_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

import { _setup, cleanup } from "../../test_helpers/mod.ts";
import { _setup, cleanup } from "test_helpers";
import { connect } from "./connect.ts";

import {
Expand All @@ -28,7 +28,12 @@ import {
tokenAuthenticator,
usernamePasswordAuthenticator,
} from "../src/internal_mod.ts";
import type { NatsConnectionImpl, Auth, Authenticator, NatsConnection } from "../src/internal_mod.ts";
import type {
Auth,
Authenticator,
NatsConnection,
NatsConnectionImpl,
} from "../src/internal_mod.ts";

import { assertEquals } from "jsr:@std/assert";
import {
Expand All @@ -37,7 +42,7 @@ import {
encodeUser,
fmtCreds,
} from "jsr:@nats-io/[email protected]";
import { assertBetween } from "../../test_helpers/mod.ts";
import { assertBetween } from "test_helpers";

function disconnectReconnect(nc: NatsConnection): Promise<void> {
const done = deferred<void>();
Expand Down
2 changes: 1 addition & 1 deletion core/tests/autounsub_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { assert, assertEquals } from "jsr:@std/assert";

import { createInbox, Empty, ErrorCode } from "../src/internal_mod.ts";
import type { NatsConnectionImpl, Subscription } from "../src/internal_mod.ts";
import { _setup, cleanup, Lock } from "../../test_helpers/mod.ts";
import { _setup, cleanup, Lock } from "test_helpers";
import { connect } from "./connect.ts";

Deno.test("autounsub - max option", async () => {
Expand Down
9 changes: 4 additions & 5 deletions core/tests/basics_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ import type {
Msg,
MsgHdrs,
NatsConnectionImpl,
NatsError,
Payload,
Publisher,
PublishOptions,
SubscriptionImpl,
NatsError,
} from "../src/internal_mod.ts";
import {
_setup,
Expand All @@ -58,7 +58,7 @@ import {
disabled,
Lock,
NatsServer,
} from "../../test_helpers/mod.ts";
} from "test_helpers";
import { connect } from "./connect.ts";

Deno.test("basics - connect port", async () => {
Expand Down Expand Up @@ -1207,7 +1207,7 @@ Deno.test("basics - msg typed payload", async () => {
const nc = await connect({ port: ns.port });

nc.subscribe("echo", {
callback: (_err: Error|null, msg: Msg) => {
callback: (_err: Error | null, msg: Msg) => {
msg.respond(msg.data);
},
});
Expand Down Expand Up @@ -1423,12 +1423,11 @@ Deno.test("basics - respond message", async () => {
await cleanup(ns, nc);
});


Deno.test("basics - resolve", async () => {
const token = Deno.env.get("NGS_CI_USER");
if (token === undefined) {
disabled(
`skipping: NGS_CI_USER is not available in the environment`,
`skipping: NGS_CI_USER is not available in the environment`,
);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion core/tests/binary_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { assertEquals } from "jsr:@std/assert";
import { createInbox, deferred } from "../src/internal_mod.ts";
import type { Msg } from "../src/internal_mod.ts";
import { _setup, cleanup } from "../../test_helpers/mod.ts";
import { _setup, cleanup } from "test_helpers";
import { connect } from "./connect.ts";

function macro(input: Uint8Array) {
Expand Down
7 changes: 6 additions & 1 deletion core/tests/buffer_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
// in a browser environment

import { assert, assertEquals, assertThrows } from "jsr:@std/assert";
import { DenoBuffer, MAX_SIZE, readAll, writeAll } from "../src/internal_mod.ts";
import {
DenoBuffer,
MAX_SIZE,
readAll,
writeAll,
} from "../src/internal_mod.ts";

// N controls how many iterations of certain checks are performed.
const N = 100;
Expand Down
2 changes: 1 addition & 1 deletion core/tests/disconnect_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import { connect } from "./connect.ts";
import { Lock, NatsServer } from "../../test_helpers/mod.ts";
import { Lock, NatsServer } from "test_helpers";
import type { NatsConnectionImpl } from "../src/internal_mod.ts";

Deno.test("disconnect - close handler is called on close", async () => {
Expand Down
10 changes: 3 additions & 7 deletions core/tests/drain_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@
* limitations under the License.
*/
import { assert, assertEquals, fail } from "jsr:@std/assert";
import {
createInbox,
ErrorCode,
StringCodec,
} from "../src/internal_mod.ts";
import { createInbox, ErrorCode, StringCodec } from "../src/internal_mod.ts";
import type { Msg } from "../src/internal_mod.ts";
import {
assertThrowsAsyncErrorCode,
assertThrowsErrorCode,
Lock,
} from "../../test_helpers/mod.ts";
import { _setup, cleanup } from "../../test_helpers/mod.ts";
} from "test_helpers";
import { _setup, cleanup } from "test_helpers";
import { connect } from "./connect.ts";

Deno.test("drain - connection drains when no subs", async () => {
Expand Down
11 changes: 7 additions & 4 deletions core/tests/events_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Lock, NatsServer, ServerSignals } from "../../test_helpers/mod.ts";
import { Lock, NatsServer, ServerSignals } from "test_helpers";
import { connect } from "./connect.ts";
import { assertEquals } from "jsr:@std/assert";
import { delay, Events } from "../src/internal_mod.ts";
import type { NatsConnectionImpl, ServersChanged } from "../src/internal_mod.ts";
import { _setup } from "../../test_helpers/mod.ts";
import { delay, Events } from "../src/internal_mod.ts";
import type {
NatsConnectionImpl,
ServersChanged,
} from "../src/internal_mod.ts";
import { _setup } from "test_helpers";

Deno.test("events - close on close", async () => {
const { ns, nc } = await _setup(connect);
Expand Down
2 changes: 1 addition & 1 deletion core/tests/headers_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import type {
import { NatsServer } from "../../test_helpers/launcher.ts";
import { assert, assertEquals, assertThrows } from "jsr:@std/assert";
import { TestDispatcher } from "./parser_test.ts";
import { _setup, cleanup } from "../../test_helpers/mod.ts";
import { _setup, cleanup } from "test_helpers";

Deno.test("headers - illegal key", () => {
const h = headers();
Expand Down
2 changes: 1 addition & 1 deletion core/tests/heartbeats_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
delay,
Heartbeat,
} from "../src/internal_mod.ts";
import type { Status, PH } from "../src/internal_mod.ts";
import type { PH, Status } from "../src/internal_mod.ts";

function pm(
lag: number,
Expand Down
4 changes: 2 additions & 2 deletions core/tests/iterators_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
import { connect } from "./connect.ts";
import { assert, assertEquals, assertRejects } from "jsr:@std/assert";
import { assertErrorCode, Lock, NatsServer } from "../../test_helpers/mod.ts";
import { assertErrorCode, Lock, NatsServer } from "test_helpers";
import {
createInbox,
delay,
Expand All @@ -24,7 +24,7 @@ import {
syncIterator,
} from "../src/internal_mod.ts";
import type { NatsConnectionImpl } from "../src/internal_mod.ts";
import { _setup, cleanup } from "../../test_helpers/mod.ts";
import { _setup, cleanup } from "test_helpers";

Deno.test("iterators - unsubscribe breaks and closes", async () => {
const { ns, nc } = await _setup(connect);
Expand Down
10 changes: 3 additions & 7 deletions core/tests/json_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@
*/
import { connect } from "./connect.ts";
import { assertEquals } from "jsr:@std/assert";
import {
createInbox,
ErrorCode,
JSONCodec,
} from "../src/internal_mod.ts";
import { createInbox, ErrorCode, JSONCodec } from "../src/internal_mod.ts";
import type { Msg, NatsError } from "../src/internal_mod.ts";
import { Lock } from "../../test_helpers/mod.ts";
import { Lock } from "test_helpers";
import { assertThrowsErrorCode } from "../../test_helpers/asserts.ts";
import { _setup, cleanup } from "../../test_helpers/mod.ts";
import { _setup, cleanup } from "test_helpers";

Deno.test("json - bad json error in callback", () => {
const o = {};
Expand Down
2 changes: 1 addition & 1 deletion core/tests/mrequest_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { _setup, cleanup } from "../../test_helpers/mod.ts";
import { _setup, cleanup } from "test_helpers";
import { connect } from "./connect.ts";
import type { NatsConnectionImpl } from "../src/internal_mod.ts";
import {
Expand Down
9 changes: 2 additions & 7 deletions core/tests/noresponders_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@
*/

import { connect } from "./connect.ts";
import {
createInbox,
Empty,
ErrorCode,
headers,
} from "@nats-io/nats-core";
import { assertErrorCode, Lock, NatsServer } from "../../test_helpers/mod.ts";
import { createInbox, Empty, ErrorCode, headers } from "@nats-io/nats-core";
import { assertErrorCode, Lock, NatsServer } from "test_helpers";
import { assert, assertEquals, fail } from "jsr:@std/assert";

Deno.test("noresponders - option", async () => {
Expand Down
2 changes: 1 addition & 1 deletion core/tests/protocol_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
Subscriptions,
} from "../src/internal_mod.ts";
import type { Msg, ProtocolHandler } from "../src/internal_mod.ts";
import { assertErrorCode } from "../../test_helpers/mod.ts";
import { assertErrorCode } from "test_helpers";
import { assertEquals, equal } from "jsr:@std/assert";

Deno.test("protocol - mux subscription unknown return null", async () => {
Expand Down
2 changes: 1 addition & 1 deletion core/tests/queues_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { createInbox } from "../src/internal_mod.ts";
import type { Subscription } from "../src/internal_mod.ts";
import { assertEquals } from "jsr:@std/assert";
import { connect } from "./connect.ts";
import { _setup, cleanup } from "../../test_helpers/mod.ts";
import { _setup, cleanup } from "test_helpers";

Deno.test("queues - deliver to single queue", async () => {
const { ns, nc } = await _setup(connect);
Expand Down
4 changes: 2 additions & 2 deletions core/tests/reconnect_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
import { assert, assertEquals, fail } from "jsr:@std/assert";
import { connect } from "./connect.ts";
import { assertErrorCode, Lock, NatsServer } from "../../test_helpers/mod.ts";
import { assertErrorCode, Lock, NatsServer } from "test_helpers";
import {
createInbox,
DataBuffer,
Expand All @@ -27,7 +27,7 @@ import {
} from "../src/internal_mod.ts";
import type { NatsConnectionImpl, NatsError } from "../src/internal_mod.ts";

import { _setup, cleanup } from "../../test_helpers/mod.ts";
import { _setup, cleanup } from "test_helpers";
import { deadline } from "jsr:@std/async";

Deno.test("reconnect - should receive when some servers are invalid", async () => {
Expand Down
2 changes: 1 addition & 1 deletion core/tests/resub_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import { connect } from "./connect.ts";
import { _setup, cleanup } from "../../test_helpers/mod.ts";
import { _setup, cleanup } from "test_helpers";
import { createInbox } from "../src/internal_mod.ts";
import type {
Msg,
Expand Down
7 changes: 6 additions & 1 deletion core/tests/semver_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
* limitations under the License.
*/

import { compare, Feature, Features, parseSemVer } from "../src/internal_mod.ts";
import {
compare,
Feature,
Features,
parseSemVer,
} from "../src/internal_mod.ts";
import {
assert,
assertEquals,
Expand Down
2 changes: 1 addition & 1 deletion core/tests/sub_extensions_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { assert, assertEquals } from "jsr:@std/assert";
import { createInbox, deferred, StringCodec } from "../src/internal_mod.ts";
import type { Msg, SubscriptionImpl } from "../src/internal_mod.ts";
import { connect } from "./connect.ts";
import { _setup, cleanup } from "../../test_helpers/mod.ts";
import { _setup, cleanup } from "test_helpers";

Deno.test("extensions - cleanup fn called at auto unsub", async () => {
const { ns, nc } = await _setup(connect);
Expand Down
7 changes: 1 addition & 6 deletions core/tests/tls_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ import {
import { connect } from "./connect.ts";
import { ErrorCode } from "../src/internal_mod.ts";
import type { NatsConnectionImpl } from "../src/internal_mod.ts";
import {
assertErrorCode,
cleanup,
Lock,
NatsServer,
} from "../../test_helpers/mod.ts";
import { assertErrorCode, cleanup, Lock, NatsServer } from "test_helpers";

Deno.test("tls - fail if server doesn't support TLS", async () => {
const ns = await NatsServer.start();
Expand Down
Loading

0 comments on commit cca5ac9

Please sign in to comment.