From ec3cb6bbb2795c571869cacd3ba5034b88ab06a0 Mon Sep 17 00:00:00 2001 From: Deyaaeldeen Almahallawi Date: Thu, 5 Dec 2024 00:30:12 +0200 Subject: [PATCH] [Identity] Precise Typechecking (#31870) Follows the same recipe in https://github.com/Azure/azure-sdk-for-js/pull/31786, more specifically: - Enables typechecking tests and fix errors - Fixes lint warnings in tests - Removes unneeded tsconfig compiler options - Uses modern ES2023 target when building samples and tests - Fix npm commands for running tests to conform to how vitest tests are configured Live run: https://dev.azure.com/azure-sdk/internal/_build/results?buildId=4385664&view=results --- .../dev-tool/src/commands/run/testVitest.ts | 14 +++++++---- sdk/identity/identity/eslint.config.mjs | 16 +++++++++++++ sdk/identity/identity/package.json | 5 ++-- .../managedIdentityCredential/imdsMsi.ts | 2 +- .../managedIdentityCredential/index.ts | 4 ++-- .../src/msal/browserFlows/msalAuthCode.ts | 1 - sdk/identity/identity/src/plugins/provider.ts | 2 ++ .../node/azureApplicationCredential.spec.ts | 2 +- .../node/azurePowerShellCredential.spec.ts | 3 +-- .../node/chainedTokenCredential.spec.ts | 2 +- .../node/clientAssertionCredential.spec.ts | 2 +- .../node/clientCertificateCredential.spec.ts | 6 ++--- .../node/clientSecretCredential.spec.ts | 2 +- .../node/deviceCodeCredential.spec.ts | 2 +- .../node/interactiveBrowserCredential.spec.ts | 3 ++- .../msalMsiProvider.spec.ts | 4 ++-- .../test/internal/node/msalPlugins.spec.ts | 2 +- .../node/usernamePasswordCredential.spec.ts | 6 ++--- .../node/workloadIdentityCredential.spec.ts | 8 +++---- .../identity/test/node/msalNodeTestSetup.ts | 2 +- .../public/node/authorityValidation.spec.ts | 2 +- .../node/azurePipelinesCredential.spec.ts | 2 +- .../identity/test/public/node/caeARM.spec.ts | 6 ++--- .../node/clientCertificateCredential.spec.ts | 10 ++++---- .../node/clientSecretCredential.spec.ts | 8 +++---- .../public/node/deviceCodeCredential.spec.ts | 2 +- .../public/node/environmentCredential.spec.ts | 10 +++++--- .../test/public/node/extensions.spec.ts | 8 +++---- .../node/multiTenantAuthentication.spec.ts | 8 +++---- .../test/public/node/tokenProvider.spec.ts | 7 ++---- .../node/usernamePasswordCredential.spec.ts | 10 ++++---- .../node/workloadIdentityCredential.spec.ts | 10 ++++---- .../identity/tsconfig.browser.config.json | 8 +++---- sdk/identity/identity/tsconfig.json | 24 ++++--------------- sdk/identity/identity/tsconfig.samples.json | 14 +++++++++++ sdk/identity/identity/tsconfig.src.json | 10 ++++++++ sdk/identity/identity/tsconfig.tests.json | 14 +++++++++++ .../identity/vitest.browser.config.ts | 5 ++++ sdk/identity/identity/vitest.config.ts | 5 ++++ sdk/identity/identity/vitest.esm.config.ts | 23 ++++++++++++++++++ 40 files changed, 177 insertions(+), 97 deletions(-) create mode 100644 sdk/identity/identity/tsconfig.samples.json create mode 100644 sdk/identity/identity/tsconfig.src.json create mode 100644 sdk/identity/identity/tsconfig.tests.json create mode 100644 sdk/identity/identity/vitest.esm.config.ts diff --git a/common/tools/dev-tool/src/commands/run/testVitest.ts b/common/tools/dev-tool/src/commands/run/testVitest.ts index f7661e2b60ed..60bc8a66f2ee 100644 --- a/common/tools/dev-tool/src/commands/run/testVitest.ts +++ b/common/tools/dev-tool/src/commands/run/testVitest.ts @@ -25,6 +25,11 @@ export const commandInfo = makeCommandInfo( default: false, description: "whether to use browser to run tests", }, + esm: { + kind: "boolean", + default: false, + description: "whether to use esm to run tests", + }, "relay-server": { shortName: "rs", description: @@ -64,12 +69,11 @@ export default leafCommand(commandInfo, async (options) => { let args = ""; // Only set if we didn't provide a config file path - if ( - options["browser"] && - updatedArgs?.indexOf("-c") === -1 && - updatedArgs?.indexOf("--config") === -1 - ) { + const providedConfig = updatedArgs?.find((arg) => arg === "-c" || arg === "--config"); + if (options["browser"] && !providedConfig) { args = "-c vitest.browser.config.ts"; + } else if (options["esm"] && !providedConfig) { + args = "-c vitest.esm.config.ts"; } const vitestArgs = updatedArgs?.length ? updatedArgs.join(" ") : ""; diff --git a/sdk/identity/identity/eslint.config.mjs b/sdk/identity/identity/eslint.config.mjs index 819d9824d963..ad219fb0cc16 100644 --- a/sdk/identity/identity/eslint.config.mjs +++ b/sdk/identity/identity/eslint.config.mjs @@ -15,4 +15,20 @@ export default [ "@typescript-eslint/no-unused-vars": "off", }, }, + { + files: ["**/*.ts", "**/*.cts", "**/*.mts"], + languageOptions: { + parserOptions: { + project: ["./tsconfig.src.json", "./tsconfig.tests.json"], + }, + }, + }, + { + files: ["*.md/*.ts"], + languageOptions: { + parserOptions: { + project: null, + }, + }, + }, ]; diff --git a/sdk/identity/identity/package.json b/sdk/identity/identity/package.json index 54d7aff0dcba..2a7a289d3586 100644 --- a/sdk/identity/identity/package.json +++ b/sdk/identity/identity/package.json @@ -30,7 +30,7 @@ "integration-test": "npm run integration-test:node && npm run integration-test:browser", "integration-test:browser": "echo skipped", "integration-test:managed-identity": "dev-tool run test:vitest -- --test-timeout 180000 --config ./vitest.managed-identity.config.ts", - "integration-test:node": "dev-tool run test:vitest -- --test-timeout 180000 'test/public/node/*.spec.ts' 'test/internal/node/*.spec.ts'", + "integration-test:node": "dev-tool run test:vitest --esm", "lint": "eslint package.json api-extractor.json src test", "lint:fix": "eslint package.json api-extractor.json src test --fix --fix-type [problem,suggestion]", "pack": "npm pack 2>&1", @@ -40,7 +40,7 @@ "unit-test": "npm run unit-test:node && npm run unit-test:browser", "unit-test:browser": "npm run clean && dev-tool run build-package && dev-tool run build-test && dev-tool run test:vitest --browser", "unit-test:node": "dev-tool run test:vitest", - "unit-test:node:no-timeouts": "dev-tool run test:node-ts-input -- --timeout Infinite --exclude 'test/snippets.spec.ts' --exclude 'test/**/browser/**/*.spec.ts' 'test/**/**/*.spec.ts'", + "unit-test:node:no-timeouts": "dev-tool run test:vitest -- --test-timeout=0", "update-snippets": "dev-tool run update-snippets" }, "files": [ @@ -119,6 +119,7 @@ }, "type": "module", "tshy": { + "project": "./tsconfig.src.json", "exports": { "./package.json": "./package.json", ".": "./src/index.ts" diff --git a/sdk/identity/identity/src/credentials/managedIdentityCredential/imdsMsi.ts b/sdk/identity/identity/src/credentials/managedIdentityCredential/imdsMsi.ts index 020432ece877..576280257579 100644 --- a/sdk/identity/identity/src/credentials/managedIdentityCredential/imdsMsi.ts +++ b/sdk/identity/identity/src/credentials/managedIdentityCredential/imdsMsi.ts @@ -9,7 +9,7 @@ import type { GetTokenOptions } from "@azure/core-auth"; import { credentialLogger } from "../../util/logging.js"; import { mapScopesToResource } from "./utils.js"; import { tracingClient } from "../../util/tracing.js"; -import { IdentityClient } from "../../client/identityClient.js"; +import type { IdentityClient } from "../../client/identityClient.js"; const msiName = "ManagedIdentityCredential - IMDS"; const logger = credentialLogger(msiName); diff --git a/sdk/identity/identity/src/credentials/managedIdentityCredential/index.ts b/sdk/identity/identity/src/credentials/managedIdentityCredential/index.ts index 742d17209eca..67d9e052d1ac 100644 --- a/sdk/identity/identity/src/credentials/managedIdentityCredential/index.ts +++ b/sdk/identity/identity/src/credentials/managedIdentityCredential/index.ts @@ -10,13 +10,13 @@ import { IdentityClient } from "../../client/identityClient.js"; import { AuthenticationRequiredError, CredentialUnavailableError } from "../../errors.js"; import { getMSALLogLevel, defaultLoggerCallback } from "../../msal/utils.js"; import { imdsRetryPolicy } from "./imdsRetryPolicy.js"; -import { MSIConfiguration } from "./models.js"; +import type { MSIConfiguration } from "./models.js"; import { formatSuccess, formatError, credentialLogger } from "../../util/logging.js"; import { tracingClient } from "../../util/tracing.js"; import { imdsMsi } from "./imdsMsi.js"; import { tokenExchangeMsi } from "./tokenExchangeMsi.js"; import { mapScopesToResource } from "./utils.js"; -import { MsalToken, ValidMsalToken } from "../../msal/types.js"; +import type { MsalToken, ValidMsalToken } from "../../msal/types.js"; const logger = credentialLogger("ManagedIdentityCredential"); diff --git a/sdk/identity/identity/src/msal/browserFlows/msalAuthCode.ts b/sdk/identity/identity/src/msal/browserFlows/msalAuthCode.ts index dadec04e8f2d..32976ca6c306 100644 --- a/sdk/identity/identity/src/msal/browserFlows/msalAuthCode.ts +++ b/sdk/identity/identity/src/msal/browserFlows/msalAuthCode.ts @@ -28,7 +28,6 @@ const redirectHash = self.location.hash; * @internal */ export class MSALAuthCode extends MsalBrowser { - protected app?: msalBrowser.IPublicClientApplication; private loginHint?: string; /** diff --git a/sdk/identity/identity/src/plugins/provider.ts b/sdk/identity/identity/src/plugins/provider.ts index 494afe012401..94932cc4ee1b 100644 --- a/sdk/identity/identity/src/plugins/provider.ts +++ b/sdk/identity/identity/src/plugins/provider.ts @@ -17,11 +17,13 @@ export interface CachePluginControl { setPersistence( persistenceFactory: ( options?: TokenCachePersistenceOptions, + // eslint-disable-next-line @typescript-eslint/consistent-type-imports ) => Promise, ): void; } export interface NativeBrokerPluginControl { + // eslint-disable-next-line @typescript-eslint/consistent-type-imports setNativeBroker(nativeBroker: import("@azure/msal-node").INativeBrokerPlugin): void; } diff --git a/sdk/identity/identity/test/internal/node/azureApplicationCredential.spec.ts b/sdk/identity/identity/test/internal/node/azureApplicationCredential.spec.ts index 8d7d9dd53fa1..faf48b31aebe 100644 --- a/sdk/identity/identity/test/internal/node/azureApplicationCredential.spec.ts +++ b/sdk/identity/identity/test/internal/node/azureApplicationCredential.spec.ts @@ -5,7 +5,7 @@ import { AzureApplicationCredential } from "../../../src/credentials/azureApplic import { createDefaultHttpClient, createHttpHeaders, - HttpClient, + type HttpClient, RestError, } from "@azure/core-rest-pipeline"; import { ManagedIdentityApplication } from "@azure/msal-node"; diff --git a/sdk/identity/identity/test/internal/node/azurePowerShellCredential.spec.ts b/sdk/identity/identity/test/internal/node/azurePowerShellCredential.spec.ts index c7cdbc7f4fda..303766f738d1 100644 --- a/sdk/identity/identity/test/internal/node/azurePowerShellCredential.spec.ts +++ b/sdk/identity/identity/test/internal/node/azurePowerShellCredential.spec.ts @@ -189,8 +189,7 @@ describe("AzurePowerShellCredential", function () { Type: "Bearer", }; - const stub = vi - .spyOn(processUtils, "execFile") + vi.spyOn(processUtils, "execFile") .mockResolvedValueOnce("") // The first call checks that the command is available. .mockResolvedValueOnce(JSON.stringify(tokenResponse)); diff --git a/sdk/identity/identity/test/internal/node/chainedTokenCredential.spec.ts b/sdk/identity/identity/test/internal/node/chainedTokenCredential.spec.ts index a822fc203809..0e75d629da2b 100644 --- a/sdk/identity/identity/test/internal/node/chainedTokenCredential.spec.ts +++ b/sdk/identity/identity/test/internal/node/chainedTokenCredential.spec.ts @@ -4,7 +4,7 @@ import type { AccessToken, TokenCredential } from "../../../src/index.js"; import { ChainedTokenCredential } from "../../../src/index.js"; import { logger as chainedTokenCredentialLogger } from "../../../src/credentials/chainedTokenCredential.js"; -import { describe, it, assert, expect, vi, beforeEach, afterEach } from "vitest"; +import { describe, it, assert, expect, vi, afterEach } from "vitest"; class TestMockCredential implements TokenCredential { constructor(public returnPromise: Promise) {} diff --git a/sdk/identity/identity/test/internal/node/clientAssertionCredential.spec.ts b/sdk/identity/identity/test/internal/node/clientAssertionCredential.spec.ts index eb75384760bc..63676881fb69 100644 --- a/sdk/identity/identity/test/internal/node/clientAssertionCredential.spec.ts +++ b/sdk/identity/identity/test/internal/node/clientAssertionCredential.spec.ts @@ -10,7 +10,7 @@ import { ClientAssertionCredential } from "../../../src/index.js"; import { ConfidentialClientApplication } from "@azure/msal-node"; import { createJWTTokenFromCertificate } from "../../public/node/utils/utils.js"; import { env } from "@azure-tools/test-recorder"; -import { describe, it, assert, expect, vi, beforeEach, afterEach, MockInstance } from "vitest"; +import { describe, it, assert, expect, vi, beforeEach, afterEach, type MockInstance } from "vitest"; describe("ClientAssertionCredential (internal)", function () { let cleanup: MsalTestCleanup; diff --git a/sdk/identity/identity/test/internal/node/clientCertificateCredential.spec.ts b/sdk/identity/identity/test/internal/node/clientCertificateCredential.spec.ts index 943d94a7d7f4..69bb8b401627 100644 --- a/sdk/identity/identity/test/internal/node/clientCertificateCredential.spec.ts +++ b/sdk/identity/identity/test/internal/node/clientCertificateCredential.spec.ts @@ -10,7 +10,7 @@ import { env } from "@azure-tools/test-recorder"; import { ClientCertificateCredential } from "../../../src/index.js"; import { parseCertificate } from "../../../src/credentials/clientCertificateCredential.js"; -import { describe, it, assert, expect, vi, beforeEach, afterEach } from "vitest"; +import { describe, it, assert, beforeEach, afterEach } from "vitest"; const ASSET_PATH = "assets"; @@ -100,7 +100,7 @@ describe("ClientCertificateCredential (internal)", function () { ); }); - it("throws when given a file that doesn't contain a PEM-formatted certificate", async function (ctx) { + it("throws when given a file that doesn't contain a PEM-formatted certificate", async function () { const fullPath = path.resolve("./clientCertificateCredential.spec.ts"); const credential = new ClientCertificateCredential("tenant", "client", { certificatePath: fullPath, @@ -117,7 +117,7 @@ describe("ClientCertificateCredential (internal)", function () { assert.deepEqual(error?.message, `ENOENT: no such file or directory, open '${fullPath}'`); }); - it("throws when given a certificate that isn't PEM-formatted", async function (ctx) { + it("throws when given a certificate that isn't PEM-formatted", async function () { const credential = new ClientCertificateCredential("tenant", "client", { certificate: "not-pem-formatted", }); diff --git a/sdk/identity/identity/test/internal/node/clientSecretCredential.spec.ts b/sdk/identity/identity/test/internal/node/clientSecretCredential.spec.ts index 583445b6f405..f6400acb56fd 100644 --- a/sdk/identity/identity/test/internal/node/clientSecretCredential.spec.ts +++ b/sdk/identity/identity/test/internal/node/clientSecretCredential.spec.ts @@ -12,7 +12,7 @@ import { env, isLiveMode, isPlaybackMode } from "@azure-tools/test-recorder"; import { ClientSecretCredential } from "../../../src/index.js"; import { ConfidentialClientApplication } from "@azure/msal-node"; import type { GetTokenOptions } from "@azure/core-auth"; -import { describe, it, assert, expect, vi, beforeEach, afterEach, MockInstance } from "vitest"; +import { describe, it, assert, expect, vi, beforeEach, afterEach, type MockInstance } from "vitest"; describe("ClientSecretCredential (internal)", function () { let cleanup: MsalTestCleanup; diff --git a/sdk/identity/identity/test/internal/node/deviceCodeCredential.spec.ts b/sdk/identity/identity/test/internal/node/deviceCodeCredential.spec.ts index c3b61a8bb1ca..93f8499ccb7a 100644 --- a/sdk/identity/identity/test/internal/node/deviceCodeCredential.spec.ts +++ b/sdk/identity/identity/test/internal/node/deviceCodeCredential.spec.ts @@ -7,7 +7,7 @@ import type { Recorder } from "@azure-tools/test-recorder"; import { env, isLiveMode } from "@azure-tools/test-recorder"; import { DeviceCodeCredential } from "../../../src/index.js"; import { PublicClientApplication } from "@azure/msal-node"; -import { describe, it, expect, vi, beforeEach, afterEach, MockInstance } from "vitest"; +import { describe, it, expect, vi, beforeEach, afterEach, type MockInstance } from "vitest"; describe("DeviceCodeCredential (internal)", function () { let cleanup: MsalTestCleanup; diff --git a/sdk/identity/identity/test/internal/node/interactiveBrowserCredential.spec.ts b/sdk/identity/identity/test/internal/node/interactiveBrowserCredential.spec.ts index 727fd77d6fe0..54caf86af9c7 100644 --- a/sdk/identity/identity/test/internal/node/interactiveBrowserCredential.spec.ts +++ b/sdk/identity/identity/test/internal/node/interactiveBrowserCredential.spec.ts @@ -15,6 +15,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; declare global { namespace NodeJS { interface Global { + // eslint-disable-next-line @typescript-eslint/consistent-type-imports URL: typeof import("url").URL; } } @@ -50,7 +51,7 @@ describe("InteractiveBrowserCredential (internal)", function () { const scope = "https://vault.azure.net/.default"; - it("Throws an expected error if no browser is available", async function (ctx) { + it("Throws an expected error if no browser is available", async function () { const credential = new InteractiveBrowserCredential( recorder.configureClientOptions({ redirectUri: "http://localhost:8081", diff --git a/sdk/identity/identity/test/internal/node/managedIdentityCredential/msalMsiProvider.spec.ts b/sdk/identity/identity/test/internal/node/managedIdentityCredential/msalMsiProvider.spec.ts index 641222ef3329..efbe332279a3 100644 --- a/sdk/identity/identity/test/internal/node/managedIdentityCredential/msalMsiProvider.spec.ts +++ b/sdk/identity/identity/test/internal/node/managedIdentityCredential/msalMsiProvider.spec.ts @@ -8,8 +8,8 @@ import { imdsMsi } from "../../../../src/credentials/managedIdentityCredential/i import { RestError } from "@azure/core-rest-pipeline"; import { AuthenticationRequiredError, CredentialUnavailableError } from "../../../../src/errors.js"; import type { AccessToken, GetTokenOptions } from "@azure/core-auth"; -import { describe, it, assert, expect, vi, beforeEach, afterEach, MockInstance } from "vitest"; -import { IdentityClient } from "../../../../src/client/identityClient.js"; +import { describe, it, assert, expect, vi, beforeEach, afterEach, type MockInstance } from "vitest"; +import type { IdentityClient } from "../../../../src/client/identityClient.js"; describe("ManagedIdentityCredential (MSAL)", function () { let acquireTokenStub: MockInstance< diff --git a/sdk/identity/identity/test/internal/node/msalPlugins.spec.ts b/sdk/identity/identity/test/internal/node/msalPlugins.spec.ts index 3ef7126080f9..900673c4b40e 100644 --- a/sdk/identity/identity/test/internal/node/msalPlugins.spec.ts +++ b/sdk/identity/identity/test/internal/node/msalPlugins.spec.ts @@ -10,7 +10,7 @@ import { } from "../../../src/msal/nodeFlows/msalPlugins.js"; import type { MsalClientOptions } from "../../../src/msal/nodeFlows/msalClient.js"; -import { describe, it, assert, expect, vi, beforeEach, afterEach } from "vitest"; +import { describe, it, assert, vi, beforeEach, afterEach } from "vitest"; describe("#generatePluginConfiguration", function () { let options: MsalClientOptions; diff --git a/sdk/identity/identity/test/internal/node/usernamePasswordCredential.spec.ts b/sdk/identity/identity/test/internal/node/usernamePasswordCredential.spec.ts index 5786029df0e6..a88c79d1d881 100644 --- a/sdk/identity/identity/test/internal/node/usernamePasswordCredential.spec.ts +++ b/sdk/identity/identity/test/internal/node/usernamePasswordCredential.spec.ts @@ -11,7 +11,7 @@ import { isPlaybackMode } from "@azure-tools/test-recorder"; import { PublicClientApplication } from "@azure/msal-node"; import { UsernamePasswordCredential } from "../../../src/index.js"; import { getUsernamePasswordStaticResources } from "../../msalTestUtils.js"; -import { describe, it, assert, expect, vi, beforeEach, afterEach, MockInstance } from "vitest"; +import { describe, it, assert, expect, vi, beforeEach, afterEach, type MockInstance } from "vitest"; describe("UsernamePasswordCredential (internal)", function () { let cleanup: MsalTestCleanup; @@ -58,7 +58,7 @@ describe("UsernamePasswordCredential (internal)", function () { ); }); - it("Authenticates silently after the initial request", async function (ctx) { + it("Authenticates silently after the initial request", async function () { const { clientId, password, tenantId, username } = getUsernamePasswordStaticResources(); const credential = new UsernamePasswordCredential( tenantId, @@ -82,7 +82,7 @@ describe("UsernamePasswordCredential (internal)", function () { ).toHaveBeenCalledOnce(); }); - it("Authenticates with tenantId on getToken", async function (ctx) { + it("Authenticates with tenantId on getToken", async function () { const { clientId, password, tenantId, username } = getUsernamePasswordStaticResources(); const credential = new UsernamePasswordCredential( tenantId, diff --git a/sdk/identity/identity/test/internal/node/workloadIdentityCredential.spec.ts b/sdk/identity/identity/test/internal/node/workloadIdentityCredential.spec.ts index dbeb967fc16e..678d9835ea67 100644 --- a/sdk/identity/identity/test/internal/node/workloadIdentityCredential.spec.ts +++ b/sdk/identity/identity/test/internal/node/workloadIdentityCredential.spec.ts @@ -52,7 +52,7 @@ describe("WorkloadIdentityCredential", function () { await cleanup(); }); - it("authenticates with WorkloadIdentity Credential", async function (ctx) { + it("authenticates with WorkloadIdentity Credential", async function () { const credential = new WorkloadIdentityCredential({ tenantId, clientId, @@ -67,7 +67,7 @@ describe("WorkloadIdentityCredential", function () { }); }); - it("authenticates with ManagedIdentity Credential", async function (ctx) { + it("authenticates with ManagedIdentity Credential", async function () { vi.stubEnv("AZURE_FEDERATED_TOKEN_FILE", tokenFilePath); vi.stubEnv("AZURE_CLIENT_ID", clientId); vi.stubEnv("AZURE_TENANT_ID", tenantId); @@ -77,7 +77,7 @@ describe("WorkloadIdentityCredential", function () { assert.ok(token?.expiresOnTimestamp! > Date.now()); }); - it("authenticates with DefaultAzure Credential", async function (ctx) { + it("authenticates with DefaultAzure Credential", async function () { const credential = new DefaultAzureCredential(); try { const { token, successfulCredential } = await credential["getTokenInternal"](scope); @@ -98,7 +98,7 @@ describe("WorkloadIdentityCredential", function () { vi.restoreAllMocks(); } }); - it("authenticates with DefaultAzure Credential and client ID", async function (ctx) { + it("authenticates with DefaultAzure Credential and client ID", async function () { const credential = new DefaultAzureCredential({ managedIdentityClientId: "managedIdentityClientId", workloadIdentityClientId: "workloadIdentityClientId", diff --git a/sdk/identity/identity/test/node/msalNodeTestSetup.ts b/sdk/identity/identity/test/node/msalNodeTestSetup.ts index 3355d0d2270b..0e6b7b69b9a2 100644 --- a/sdk/identity/identity/test/node/msalNodeTestSetup.ts +++ b/sdk/identity/identity/test/node/msalNodeTestSetup.ts @@ -4,7 +4,7 @@ import type { AuthenticationResult } from "@azure/msal-node"; import { ConfidentialClientApplication, PublicClientApplication } from "@azure/msal-node"; import { PlaybackTenantId } from "../msalTestUtils.js"; -import { Recorder, VitestTestContext } from "@azure-tools/test-recorder"; +import { Recorder, type VitestTestContext } from "@azure-tools/test-recorder"; import { vi } from "vitest"; export type MsalTestCleanup = () => Promise; diff --git a/sdk/identity/identity/test/public/node/authorityValidation.spec.ts b/sdk/identity/identity/test/public/node/authorityValidation.spec.ts index 6e8021f27dc5..488da5ac424a 100644 --- a/sdk/identity/identity/test/public/node/authorityValidation.spec.ts +++ b/sdk/identity/identity/test/public/node/authorityValidation.spec.ts @@ -6,7 +6,7 @@ import { msalNodeTestSetup } from "../../node/msalNodeTestSetup.js"; import type { Recorder } from "@azure-tools/test-recorder"; import { env } from "@azure-tools/test-recorder"; import { ClientSecretCredential } from "../../../src/index.js"; -import { describe, it, assert, expect, vi, beforeEach, afterEach } from "vitest"; +import { describe, it, assert, beforeEach, afterEach } from "vitest"; describe("AuthorityValidation", function () { let cleanup: MsalTestCleanup; diff --git a/sdk/identity/identity/test/public/node/azurePipelinesCredential.spec.ts b/sdk/identity/identity/test/public/node/azurePipelinesCredential.spec.ts index c6e6a8b7160f..e22ab7491df5 100644 --- a/sdk/identity/identity/test/public/node/azurePipelinesCredential.spec.ts +++ b/sdk/identity/identity/test/public/node/azurePipelinesCredential.spec.ts @@ -3,7 +3,7 @@ import { AzurePipelinesCredential } from "../../../src/index.js"; import { isLiveMode } from "@azure-tools/test-recorder"; -import { describe, it, assert, expect, vi, beforeEach, afterEach } from "vitest"; +import { describe, it, assert, expect } from "vitest"; describe("AzurePipelinesCredential", function () { const scope = "https://vault.azure.net/.default"; diff --git a/sdk/identity/identity/test/public/node/caeARM.spec.ts b/sdk/identity/identity/test/public/node/caeARM.spec.ts index 462d93aba396..0a946f36a1d9 100644 --- a/sdk/identity/identity/test/public/node/caeARM.spec.ts +++ b/sdk/identity/identity/test/public/node/caeARM.spec.ts @@ -18,7 +18,7 @@ import { import { DeveloperSignOnClientId } from "../../../src/constants.js"; import { IdentityClient } from "../../../src/client/identityClient.js"; import { authorizeRequestOnClaimChallenge } from "@azure/core-client"; -import { describe, it, assert, expect, vi, beforeEach, afterEach } from "vitest"; +import { describe, it, assert, beforeEach, afterEach } from "vitest"; /** * Sequence of events needed to test the CAE challenges on the Graph endpoint. @@ -145,7 +145,7 @@ describe.skip("CAE", function () { await cleanup(); }); - it("DeviceCodeCredential", async function (ctx) { + it("DeviceCodeCredential", async function () { const [firstAccessToken, finalAccessToken] = await challengeFlow( new DeviceCodeCredential(recorder.configureClientOptions({ tenantId: env.AZURE_TENANT_ID })), recorder, @@ -154,7 +154,7 @@ describe.skip("CAE", function () { assert.notDeepEqual(firstAccessToken, finalAccessToken); }); - it("UsernamePasswordCredential", async function (ctx) { + it("UsernamePasswordCredential", async function () { // Important: Recording this test may only work in certain tenants. const [firstAccessToken, finalAccessToken] = await challengeFlow( diff --git a/sdk/identity/identity/test/public/node/clientCertificateCredential.spec.ts b/sdk/identity/identity/test/public/node/clientCertificateCredential.spec.ts index 7f9506f85a4e..a1f95cee2e4b 100644 --- a/sdk/identity/identity/test/public/node/clientCertificateCredential.spec.ts +++ b/sdk/identity/identity/test/public/node/clientCertificateCredential.spec.ts @@ -10,10 +10,10 @@ import { msalNodeTestSetup } from "../../node/msalNodeTestSetup.js"; import type { Recorder } from "@azure-tools/test-recorder"; import { delay, env, isLiveMode, isPlaybackMode } from "@azure-tools/test-recorder"; -import { ClientCertificateCredential } from "../../../src/index.js"; +import { ClientCertificateCredential, type GetTokenOptions } from "../../../src/index.js"; import type { PipelineResponse } from "@azure/core-rest-pipeline"; import fs from "node:fs"; -import { describe, it, assert, expect, vi, beforeEach, afterEach } from "vitest"; +import { describe, it, assert, expect, beforeEach, afterEach } from "vitest"; import { toSupportTracing } from "@azure-tools/test-utils-vitest"; expect.extend({ toSupportTracing }); @@ -41,7 +41,7 @@ describe("ClientCertificateCredential", function () { const certificatePath = env.IDENTITY_SP_CERT_PEM || path.join(ASSET_PATH, "fake-cert.pem"); const scope = "https://vault.azure.net/.default"; - it("authenticates", async function (ctx) { + it("authenticates", async function () { const credential = new ClientCertificateCredential( env.IDENTITY_SP_TENANT_ID || env.AZURE_TENANT_ID!, env.IDENTITY_SP_CLIENT_ID || env.AZURE_CLIENT_ID!, @@ -54,7 +54,7 @@ describe("ClientCertificateCredential", function () { assert.ok(token?.expiresOnTimestamp! > Date.now()); }); - it("authenticates with a PEM certificate string directly", async function (ctx) { + it("authenticates with a PEM certificate string directly", async function () { const credential = new ClientCertificateCredential( env.IDENTITY_SP_TENANT_ID || env.AZURE_TENANT_ID!, env.IDENTITY_SP_CLIENT_ID || env.AZURE_CLIENT_ID!, @@ -116,7 +116,7 @@ describe("ClientCertificateCredential", function () { // and I'm trying to avoid having to generate one ourselves. ctx.skip(); } - await expect(async (tracingOptions) => { + await expect(async (tracingOptions: GetTokenOptions) => { const credential = new ClientCertificateCredential( env.IDENTITY_SP_TENANT_ID || env.AZURE_TENANT_ID!, env.IDENTITY_SP_CLIENT_ID || env.AZURE_CLIENT_ID!, diff --git a/sdk/identity/identity/test/public/node/clientSecretCredential.spec.ts b/sdk/identity/identity/test/public/node/clientSecretCredential.spec.ts index 1eee413c93c2..741b160ccf5d 100644 --- a/sdk/identity/identity/test/public/node/clientSecretCredential.spec.ts +++ b/sdk/identity/identity/test/public/node/clientSecretCredential.spec.ts @@ -6,10 +6,10 @@ import type { MsalTestCleanup } from "../../node/msalNodeTestSetup.js"; import { msalNodeTestSetup } from "../../node/msalNodeTestSetup.js"; import type { Recorder } from "@azure-tools/test-recorder"; -import { delay, env, isRecordMode } from "@azure-tools/test-recorder"; +import { delay, env } from "@azure-tools/test-recorder"; -import { ClientSecretCredential } from "../../../src/index.js"; -import { describe, it, assert, expect, vi, beforeEach, afterEach } from "vitest"; +import { ClientSecretCredential, type GetTokenOptions } from "../../../src/index.js"; +import { describe, it, assert, expect, beforeEach, afterEach } from "vitest"; import { toSupportTracing } from "@azure-tools/test-utils-vitest"; expect.extend({ toSupportTracing }); @@ -83,7 +83,7 @@ describe("ClientSecretCredential", function () { }); it("supports tracing", async () => { - await expect(async (tracingOptions) => { + await expect(async (tracingOptions: GetTokenOptions) => { const credential = new ClientSecretCredential( env.AZURE_TENANT_ID!, env.AZURE_CLIENT_ID!, diff --git a/sdk/identity/identity/test/public/node/deviceCodeCredential.spec.ts b/sdk/identity/identity/test/public/node/deviceCodeCredential.spec.ts index acae7f747733..29198e558185 100644 --- a/sdk/identity/identity/test/public/node/deviceCodeCredential.spec.ts +++ b/sdk/identity/identity/test/public/node/deviceCodeCredential.spec.ts @@ -10,7 +10,7 @@ import type { MsalTestCleanup } from "../../node/msalNodeTestSetup.js"; import { msalNodeTestSetup } from "../../node/msalNodeTestSetup.js"; import type { Recorder } from "@azure-tools/test-recorder"; import { delay, env, isLiveMode, isPlaybackMode } from "@azure-tools/test-recorder"; -import { describe, it, assert, expect, vi, beforeEach, afterEach } from "vitest"; +import { describe, it, assert, expect, beforeEach, afterEach } from "vitest"; import { toSupportTracing } from "@azure-tools/test-utils-vitest"; expect.extend({ toSupportTracing }); diff --git a/sdk/identity/identity/test/public/node/environmentCredential.spec.ts b/sdk/identity/identity/test/public/node/environmentCredential.spec.ts index b7ab29af602b..5ef6151960ce 100644 --- a/sdk/identity/identity/test/public/node/environmentCredential.spec.ts +++ b/sdk/identity/identity/test/public/node/environmentCredential.spec.ts @@ -3,7 +3,11 @@ /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ -import { EnvironmentCredential, UsernamePasswordCredential } from "../../../src/index.js"; +import { + EnvironmentCredential, + type GetTokenOptions, + UsernamePasswordCredential, +} from "../../../src/index.js"; import type { MsalTestCleanup } from "../../node/msalNodeTestSetup.js"; import { msalNodeTestSetup } from "../../node/msalNodeTestSetup.js"; import type { Recorder } from "@azure-tools/test-recorder"; @@ -136,7 +140,7 @@ describe("EnvironmentCredential", function () { // Live test run not supported on CI at the moment. Locally should work though. ctx.skip(); } - await expect(async (tracingOptions) => { + await expect(async (tracingOptions: GetTokenOptions) => { // The following environment variables must be set for this to work. // On TEST_MODE="playback", the recorder automatically fills them with stubbed values. process.env.AZURE_TENANT_ID = cachedValues.AZURE_TENANT_ID; @@ -149,7 +153,7 @@ describe("EnvironmentCredential", function () { }); it("supports tracing with environment username/password", async () => { - await expect(async (tracingOptions) => { + await expect(async (tracingOptions: GetTokenOptions) => { // The following environment variables must be set for this to work. // On TEST_MODE="playback", the recorder automatically fills them with stubbed values. process.env.AZURE_TENANT_ID = cachedValues.AZURE_TENANT_ID; diff --git a/sdk/identity/identity/test/public/node/extensions.spec.ts b/sdk/identity/identity/test/public/node/extensions.spec.ts index 031223ffa1ed..4d39a3ae6a5f 100644 --- a/sdk/identity/identity/test/public/node/extensions.spec.ts +++ b/sdk/identity/identity/test/public/node/extensions.spec.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. import { DeviceCodeCredential } from "../../../src/index.js"; import { VisualStudioCodeCredential } from "../../../src/index.js"; -import { describe, it, assert } from "vitest"; +import { describe, it, assert, chai } from "vitest"; /** * A helper to assert that a Promise rejects. @@ -12,16 +12,16 @@ async function assertRejects(p: Promise, regexp: RegExp): Promise await p; } catch (e: any) { if (!regexp.test(e.message)) { - throw new AssertionError( + throw new chai.AssertionError( `The input did not match the regular expression ${regexp}. Input:\n\n'${e.message}'`, ); } return; } - throw new AssertionError("Expected the function body to throw."); + throw new chai.AssertionError("Expected the function body to throw."); } -describe("Plugin API", function (this: Mocha.Suite) { +describe("Plugin API", function () { it("Setting persistence options throws if not initialized", function () { assert.throws(() => { new DeviceCodeCredential({ diff --git a/sdk/identity/identity/test/public/node/multiTenantAuthentication.spec.ts b/sdk/identity/identity/test/public/node/multiTenantAuthentication.spec.ts index c3e542ee85a0..9e730ccc35f1 100644 --- a/sdk/identity/identity/test/public/node/multiTenantAuthentication.spec.ts +++ b/sdk/identity/identity/test/public/node/multiTenantAuthentication.spec.ts @@ -6,7 +6,7 @@ import { msalNodeTestSetup } from "../../node/msalNodeTestSetup.js"; import type { Recorder } from "@azure-tools/test-recorder"; import { env } from "@azure-tools/test-recorder"; import { createHttpHeaders, createPipelineRequest } from "@azure/core-rest-pipeline"; -import { ClientSecretCredential } from "../../../src/credentials/clientSecretCredential.js"; +import { ClientSecretCredential } from "../../../src/index.js"; import { IdentityClient } from "../../../src/client/identityClient.js"; import { describe, it, assert, beforeEach, afterEach } from "vitest"; @@ -38,9 +38,9 @@ describe("MultiTenantAuthentication", function () { } const credential = new ClientSecretCredential( - tenantId, - clientId, - clientSecret, + tenantId!, + clientId!, + clientSecret!, recorder.configureClientOptions({}), ); diff --git a/sdk/identity/identity/test/public/node/tokenProvider.spec.ts b/sdk/identity/identity/test/public/node/tokenProvider.spec.ts index abbf2716e0da..4f98d8487b28 100644 --- a/sdk/identity/identity/test/public/node/tokenProvider.spec.ts +++ b/sdk/identity/identity/test/public/node/tokenProvider.spec.ts @@ -1,20 +1,17 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { TokenCredential, getBearerTokenProvider } from "../../../src/index.js"; +import { type TokenCredential, getBearerTokenProvider } from "../../../src/index.js"; import type { MsalTestCleanup } from "../../node/msalNodeTestSetup.js"; import { msalNodeTestSetup } from "../../node/msalNodeTestSetup.js"; -import type { Recorder } from "@azure-tools/test-recorder"; import { delay, isPlaybackMode } from "@azure-tools/test-recorder"; -import { describe, it, assert, expect, vi, beforeEach, afterEach } from "vitest"; +import { describe, it, assert, beforeEach, afterEach } from "vitest"; describe("getBearerTokenProvider", function () { - let recorder: Recorder; let cleanup: MsalTestCleanup; beforeEach(async function (ctx) { const setup = await msalNodeTestSetup(ctx); - recorder = setup.recorder; cleanup = setup.cleanup; }); afterEach(async function () { diff --git a/sdk/identity/identity/test/public/node/usernamePasswordCredential.spec.ts b/sdk/identity/identity/test/public/node/usernamePasswordCredential.spec.ts index 6b9185d8aea0..094a2596d323 100644 --- a/sdk/identity/identity/test/public/node/usernamePasswordCredential.spec.ts +++ b/sdk/identity/identity/test/public/node/usernamePasswordCredential.spec.ts @@ -7,9 +7,9 @@ import type { MsalTestCleanup } from "../../node/msalNodeTestSetup.js"; import { msalNodeTestSetup } from "../../node/msalNodeTestSetup.js"; import type { Recorder } from "@azure-tools/test-recorder"; import { delay } from "@azure-tools/test-recorder"; -import { UsernamePasswordCredential } from "../../../src/index.js"; +import { type GetTokenOptions, UsernamePasswordCredential } from "../../../src/index.js"; import { getUsernamePasswordStaticResources } from "../../msalTestUtils.js"; -import { describe, it, assert, expect, vi, beforeEach, afterEach } from "vitest"; +import { describe, it, assert, expect, beforeEach, afterEach } from "vitest"; import { toSupportTracing } from "@azure-tools/test-utils-vitest"; expect.extend({ toSupportTracing }); @@ -29,7 +29,7 @@ describe("UsernamePasswordCredential", function () { const scope = "https://vault.azure.net/.default"; - it("authenticates", async function (ctx) { + it("authenticates", async function () { const { tenantId, clientId, username, password } = getUsernamePasswordStaticResources(); const credential = new UsernamePasswordCredential( @@ -76,10 +76,10 @@ describe("UsernamePasswordCredential", function () { assert.ok(error?.message.includes("endpoints_resolution_error")); }); - it("supports tracing", async function (ctx) { + it("supports tracing", async function () { const { clientId, tenantId, username, password } = getUsernamePasswordStaticResources(); - await expect(async (tracingOptions) => { + await expect(async (tracingOptions: GetTokenOptions) => { const credential = new UsernamePasswordCredential( tenantId, clientId, diff --git a/sdk/identity/identity/test/public/node/workloadIdentityCredential.spec.ts b/sdk/identity/identity/test/public/node/workloadIdentityCredential.spec.ts index 38faca72b928..d388940e1a7d 100644 --- a/sdk/identity/identity/test/public/node/workloadIdentityCredential.spec.ts +++ b/sdk/identity/identity/test/public/node/workloadIdentityCredential.spec.ts @@ -17,7 +17,7 @@ import { ManagedIdentityCredential, WorkloadIdentityCredential, } from "../../../src/index.js"; -import { describe, it, assert, expect, vi, beforeEach, afterEach } from "vitest"; +import { describe, it, assert, beforeEach, afterEach } from "vitest"; describe.skip("WorkloadIdentityCredential", function () { let cleanup: MsalTestCleanup; @@ -44,7 +44,7 @@ describe.skip("WorkloadIdentityCredential", function () { return jwtoken; } - it("authenticates with WorkloadIdentity Credential", async function (ctx) { + it("authenticates with WorkloadIdentity Credential", async function () { const fileDir = await setupFileandEnv("workload-identity"); const credential = new WorkloadIdentityCredential( recorder.configureClientOptions({ @@ -63,7 +63,7 @@ describe.skip("WorkloadIdentityCredential", function () { } }); - it("authenticates with ManagedIdentity Credential", async function (ctx) { + it("authenticates with ManagedIdentity Credential", async function () { const fileDir = await setupFileandEnv("token-exchange-msi"); const credential = new ManagedIdentityCredential(clientId, recorder.configureClientOptions({})); try { @@ -76,7 +76,7 @@ describe.skip("WorkloadIdentityCredential", function () { } }); - it("authenticates with DefaultAzure Credential", async function (ctx) { + it("authenticates with DefaultAzure Credential", async function () { const fileDir = await setupFileandEnv("token-exchange-msi"); const credential = new DefaultAzureCredential(recorder.configureClientOptions({})); try { @@ -90,7 +90,7 @@ describe.skip("WorkloadIdentityCredential", function () { rmdirSync(fileDir.tempDir); } }); - it("authenticates with DefaultAzure Credential and client ID", async function (ctx) { + it("authenticates with DefaultAzure Credential and client ID", async function () { const fileDir = await setupFileandEnv("token-exchange-msi"); const credential = new DefaultAzureCredential( recorder.configureClientOptions({ diff --git a/sdk/identity/identity/tsconfig.browser.config.json b/sdk/identity/identity/tsconfig.browser.config.json index f772e6eb3b76..084ca97b5edf 100644 --- a/sdk/identity/identity/tsconfig.browser.config.json +++ b/sdk/identity/identity/tsconfig.browser.config.json @@ -1,10 +1,10 @@ { - "extends": "./.tshy/build.json", - "include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.spec.ts", "./test/**/*.mts"], - "exclude": ["./test/**/node/**/*.ts"], + "extends": ["./.tshy/build.json", "./tsconfig.tests.json"], + "include": ["./src/**/*.ts", "./src/**/*.mts", "./test/**/*.ts", "./test/**/*.mts"], + "exclude": ["./test/**/node/**/*.ts", "./test/manual*"], "compilerOptions": { "outDir": "./dist-test/browser", "rootDir": ".", - "skipLibCheck": true + "noEmit": false } } diff --git a/sdk/identity/identity/tsconfig.json b/sdk/identity/identity/tsconfig.json index 07611f0f76a1..dc1db702a3b7 100644 --- a/sdk/identity/identity/tsconfig.json +++ b/sdk/identity/identity/tsconfig.json @@ -1,23 +1,9 @@ { "extends": "../../../tsconfig", - "compilerOptions": { - "lib": ["DOM"], - "resolveJsonModule": true, - "paths": { - "@azure/identity": ["./src/index"] - }, - "module": "NodeNext", - "moduleResolution": "NodeNext", - "rootDir": "." - }, - "include": [ - "src/**/*.ts", - "src/**/*.mts", - "src/**/*.cts", - "samples-dev/**/*.ts", - "test/**/*.ts", - "test/**/*.mts", - "test/**/*.cts" + "references": [ + { "path": "./tsconfig.src.json" }, + { "path": "./tsconfig.samples.json" }, + { "path": "./tsconfig.tests.json" } ], - "exclude": ["test/manual*/**/*", "integration/**", "node_modules"] + "files": [] } diff --git a/sdk/identity/identity/tsconfig.samples.json b/sdk/identity/identity/tsconfig.samples.json new file mode 100644 index 000000000000..9708cb8b7982 --- /dev/null +++ b/sdk/identity/identity/tsconfig.samples.json @@ -0,0 +1,14 @@ +{ + "extends": "../../../tsconfig", + "compilerOptions": { + "target": "ES2023", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "paths": { + "@azure/identity": ["./dist/esm"] + }, + "noEmit": true, + "composite": true + }, + "include": ["./samples-dev"] +} diff --git a/sdk/identity/identity/tsconfig.src.json b/sdk/identity/identity/tsconfig.src.json new file mode 100644 index 000000000000..d9224e6a6027 --- /dev/null +++ b/sdk/identity/identity/tsconfig.src.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../tsconfig", + "compilerOptions": { + "module": "NodeNext", + "moduleResolution": "NodeNext", + "lib": ["DOM"], + "composite": true + }, + "include": ["./src"] +} diff --git a/sdk/identity/identity/tsconfig.tests.json b/sdk/identity/identity/tsconfig.tests.json new file mode 100644 index 000000000000..77f309fc707a --- /dev/null +++ b/sdk/identity/identity/tsconfig.tests.json @@ -0,0 +1,14 @@ +{ + "extends": "../../../tsconfig", + "compilerOptions": { + "target": "ES2023", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "lib": ["DOM"], + "skipLibCheck": true, + "noEmit": true, + "composite": true + }, + "include": ["./test", "./src"], + "exclude": ["test/manual*"] +} diff --git a/sdk/identity/identity/vitest.browser.config.ts b/sdk/identity/identity/vitest.browser.config.ts index 2303fced5fd3..fa80ad423ea5 100644 --- a/sdk/identity/identity/vitest.browser.config.ts +++ b/sdk/identity/identity/vitest.browser.config.ts @@ -3,6 +3,7 @@ import { defineConfig, mergeConfig } from "vitest/config"; import viteConfig from "../../../vitest.browser.shared.config.ts"; +import { resolve } from "node:path"; export default mergeConfig( viteConfig, @@ -10,6 +11,10 @@ export default mergeConfig( test: { include: ["dist-test/browser/test/**/*.spec.js"], exclude: ["dist-test/browser/test/snippets.spec.js"], + alias: { + "@azure/identity": resolve("./dist/browser/index.js"), + "../../src": resolve("./dist/browser"), + }, hookTimeout: 500000, testTimeout: 500000, }, diff --git a/sdk/identity/identity/vitest.config.ts b/sdk/identity/identity/vitest.config.ts index 6f96ac13b36a..4ced3be87573 100644 --- a/sdk/identity/identity/vitest.config.ts +++ b/sdk/identity/identity/vitest.config.ts @@ -16,6 +16,11 @@ export default mergeConfig( ], hookTimeout: 500000, testTimeout: 500000, + typecheck: { + enabled: true, + tsconfig: "tsconfig.tests.json", + include: ["test/**/*.ts", "test/**/*.mts", "test/**/*.cts"], + } }, }), ); diff --git a/sdk/identity/identity/vitest.esm.config.ts b/sdk/identity/identity/vitest.esm.config.ts new file mode 100644 index 000000000000..af90f2eecaa6 --- /dev/null +++ b/sdk/identity/identity/vitest.esm.config.ts @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { defineConfig, mergeConfig } from "vitest/config"; +import viteConfig from "./vitest.config.ts"; +import { resolve } from "node:path"; + +const distPath = "./dist/esm"; +const distPathAbsolute = resolve(distPath); +export default mergeConfig( + viteConfig, + defineConfig({ + test: { + alias: { + "@azure/identity": resolve(`${distPath}/index.js`), + "../../../../src": distPathAbsolute, + "../../../src": distPathAbsolute, + "../../src": distPathAbsolute, + "../src": distPathAbsolute, + }, + }, + }), +);