diff --git a/sdk/cosmosdb/cosmos/package.json b/sdk/cosmosdb/cosmos/package.json index 97c89a26f366..4137b75328cb 100644 --- a/sdk/cosmosdb/cosmos/package.json +++ b/sdk/cosmosdb/cosmos/package.json @@ -72,7 +72,7 @@ "test:signoff": "npm run integration-test:node -- --fgrep \"nosignoff\" --invert", "unit-test": "npm run unit-test:node && npm run unit-test:browser", "unit-test:browser": "echo skipped", - "unit-test:node": "echo skipped", + "unit-test:node": "dev-tool run vendored cross-env NODE_OPTIONS='--dns-result-order=ipv4first' mocha -r test/mocha.env.ts -r ts-node/register -r dotenv/config -r ./test/public/common/setup.ts --reporter ../../../common/tools/mocha-multi-reporter.js --reporter-option output=test-results.xml \"./test/internal/**/*.spec.ts\" --timeout 100000", "update-snippets": "echo skipped" }, "repository": "github:Azure/azure-sdk-for-js", diff --git a/sdk/cosmosdb/cosmos/test/internal/unit/platform.spec.ts b/sdk/cosmosdb/cosmos/test/internal/unit/platform.spec.ts index 3c7052ef9be9..7b9fbee2a704 100644 --- a/sdk/cosmosdb/cosmos/test/internal/unit/platform.spec.ts +++ b/sdk/cosmosdb/cosmos/test/internal/unit/platform.spec.ts @@ -14,6 +14,8 @@ describe("getUserAgent", function () { }); it("should contain the current node version", () => { + console.log(getUserAgent()); + console.log(process.version.replace("v", "")); assert(getUserAgent().includes(process.version.replace("v", ""))); }); diff --git a/sdk/cosmosdb/cosmos/test/public/common/TestHelpers.ts b/sdk/cosmosdb/cosmos/test/public/common/TestHelpers.ts index a278593e2583..c24af42235cf 100644 --- a/sdk/cosmosdb/cosmos/test/public/common/TestHelpers.ts +++ b/sdk/cosmosdb/cosmos/test/public/common/TestHelpers.ts @@ -44,18 +44,22 @@ import path from "path"; const defaultRoutingGatewayPort: string = ":8081"; const defaultComputeGatewayPort: string = ":8903"; -export const defaultClient = new CosmosClient({ - endpoint, - key: masterKey, - connectionPolicy: { enableBackgroundEndpointRefreshing: false }, - diagnosticLevel: CosmosDbDiagnosticLevel.info, -}); - -export const defaultComputeGatewayClient = new CosmosClient({ - endpoint: endpoint.replace(defaultRoutingGatewayPort, defaultComputeGatewayPort), - key: masterKey, - connectionPolicy: { enableBackgroundEndpointRefreshing: false }, -}); +export function getDefaultClient(): CosmosClient { + return new CosmosClient({ + endpoint, + key: masterKey, + connectionPolicy: { enableBackgroundEndpointRefreshing: false }, + diagnosticLevel: CosmosDbDiagnosticLevel.info, + }); +} + +export function getDefaultComputeGatewayClient(): CosmosClient { + return new CosmosClient({ + endpoint: endpoint.replace(defaultRoutingGatewayPort, defaultComputeGatewayPort), + key: masterKey, + connectionPolicy: { enableBackgroundEndpointRefreshing: false }, + }); +} export function addEntropy(name: string): string { return name + getEntropy(); @@ -65,8 +69,11 @@ export function getEntropy(): string { return `${Math.floor(Math.random() * 10000)}`; } -export async function removeAllDatabases(client: CosmosClient = defaultClient): Promise { +export async function removeAllDatabases(client?: CosmosClient): Promise { try { + if (!client) { + client = getDefaultClient(); + } const { resources: databases } = await client.databases.readAll().fetchAll(); const length = databases.length; @@ -424,9 +431,12 @@ function validateRequestStartTimeForDiagnostics( export async function getTestDatabase( testName: string, - client: CosmosClient = defaultClient, + client?: CosmosClient, attrs?: Partial, ): Promise { + if (!client) { + client = getDefaultClient(); + } const entropy = Math.floor(Math.random() * 10000); const id = `${testName.replace(" ", "").substring(0, 30)}${entropy}`; await client.databases.create({ id, ...attrs }); @@ -435,10 +445,13 @@ export async function getTestDatabase( export async function getTestContainer( testName: string, - client: CosmosClient = defaultClient, + client?: CosmosClient, containerDef?: ContainerRequest, options?: RequestOptions, ): Promise { + if (!client) { + client = getDefaultClient(); + } const db = await getTestDatabase(testName, client); const entropy = Math.floor(Math.random() * 10000); const id = `${testName.replace(" ", "").substring(0, 30)}${entropy}`; diff --git a/sdk/cosmosdb/cosmos/test/public/functional/item/itemIdEncoding.spec.ts b/sdk/cosmosdb/cosmos/test/public/functional/item/itemIdEncoding.spec.ts index 25572e24a183..154ed723a3a5 100644 --- a/sdk/cosmosdb/cosmos/test/public/functional/item/itemIdEncoding.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/functional/item/itemIdEncoding.spec.ts @@ -6,8 +6,8 @@ import type { Container, CosmosClient } from "../../../../src"; import { getTestContainer, removeAllDatabases, - defaultClient, - defaultComputeGatewayClient, + getDefaultClient, + getDefaultComputeGatewayClient, } from "../../common/TestHelpers"; interface ItemPayload { @@ -36,7 +36,9 @@ const executeTestCase = async function ( scenario: TestScenario, useComputeGateway: boolean = false, ) { - const client: CosmosClient = useComputeGateway ? defaultComputeGatewayClient : defaultClient; + const client: CosmosClient = useComputeGateway + ? getDefaultComputeGatewayClient() + : getDefaultClient(); const container: Container = await getTestContainer(scenario.name, client, { partitionKey: { paths: ["/pk"], diff --git a/sdk/cosmosdb/cosmos/test/internal/unit/client.spec.ts b/sdk/cosmosdb/cosmos/test/public/integration/client.spec.ts similarity index 100% rename from sdk/cosmosdb/cosmos/test/internal/unit/client.spec.ts rename to sdk/cosmosdb/cosmos/test/public/integration/client.spec.ts diff --git a/sdk/cosmosdb/cosmos/test/internal/session.spec.ts b/sdk/cosmosdb/cosmos/test/public/integration/session.spec.ts similarity index 94% rename from sdk/cosmosdb/cosmos/test/internal/session.spec.ts rename to sdk/cosmosdb/cosmos/test/public/integration/session.spec.ts index f4ab194981c9..7ce652ee1080 100644 --- a/sdk/cosmosdb/cosmos/test/internal/session.spec.ts +++ b/sdk/cosmosdb/cosmos/test/public/integration/session.spec.ts @@ -3,17 +3,17 @@ /* eslint-disable no-unused-expressions */ import assert from "assert"; import type { Suite } from "mocha"; -import type { ClientContext, Container, PluginConfig } from "../../src"; -import { PluginOn } from "../../src"; -import { OperationType, ResourceType } from "../../src/common"; -import { ConsistencyLevel } from "../../src"; -import { CosmosClient } from "../../src"; -import type { SessionContainer } from "../../src/session/sessionContainer"; -import { endpoint } from "../public/common/_testConfig"; -import { masterKey } from "../public/common/_fakeTestSecrets"; -import { addEntropy, getTestDatabase, removeAllDatabases } from "../public/common/TestHelpers"; -import type { RequestContext } from "../../src"; -import type { Response } from "../../src/request/Response"; +import type { ClientContext, Container, PluginConfig } from "../../../src"; +import { PluginOn } from "../../../src"; +import { OperationType, ResourceType } from "../../../src/common"; +import { ConsistencyLevel } from "../../../src"; +import { CosmosClient } from "../../../src"; +import type { SessionContainer } from "../../../src/session/sessionContainer"; +import { endpoint } from "../../public/common/_testConfig"; +import { masterKey } from "../../public/common/_fakeTestSecrets"; +import { addEntropy, getTestDatabase, removeAllDatabases } from "../../public/common/TestHelpers"; +import type { RequestContext } from "../../../src"; +import type { Response } from "../../../src/request/Response"; import { expect } from "chai"; describe("New session token", function () { diff --git a/sdk/cosmosdb/cosmos/tsconfig.strict.json b/sdk/cosmosdb/cosmos/tsconfig.strict.json index 2f36c9c1d9dd..e7d76b6ba3f8 100644 --- a/sdk/cosmosdb/cosmos/tsconfig.strict.json +++ b/sdk/cosmosdb/cosmos/tsconfig.strict.json @@ -158,7 +158,7 @@ "src/request/globalStatistics.ts", "src/request/hybridSearchQueryResult.ts", "test/public/common/TestHelpers.ts", - "test/internal/session.spec.ts", + "test/public/integration/session.spec.ts", "test/internal/unit/auth.spec.ts", "test/internal/unit/defaultQueryExecutionContext.spec.ts", "test/internal/unit/helper.spec.ts", @@ -177,7 +177,7 @@ "test/internal/unit/utils/batch.spec.ts", "test/internal/unit/utils/checkURL.spec.ts", "test/internal/unit/utils/offer.spec.ts", - "test/internal/unit/client.spec.ts", + "test/public/integration/client.spec.ts", "test/internal/unit/timeoutFailoverRetryPolicy.spec.ts", "test/internal/unit/nonStreamingOrderByMap.spec.ts", "test/internal/unit/utils/supportedQueryFeaturesBuilder.spec.ts",