Skip to content

[identity] Improve the testing framework #35349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

deyaaeldeen
Copy link
Member

@deyaaeldeen deyaaeldeen commented Jul 25, 2025

This PR improves type-checking and efficiency of our tests and tightens the feedback loop for platform-specific issues. Some of the issues addressed in this PR:

  • browser tests build the source code twice unnecessarily, once using the build-package dev-tool command and another using the build-test command.
  • browser tests aren't being type-checked precisely, Node.js APIs calls aren't being forbidden by the typechecker.
  • Node.js tests aren't being type-checked precisely either, DOM calls aren't being forbidden by the typechecker.

Key Changes:

  • Splits test configurations into separate Node.js (tsconfig.test.node.json) and browser (tsconfig.browser.config.json) configurations to enable precise type-checking.
  • Implements consistent TypeScript path mappings using @azure/identity and internal/* aliases across all test files. This aliasing enables testing built code or source code in a modular way.
  • Updates Vitest configurations with dynamic path resolution for both Node.js and browser environments so that Node.js tests test against the source code locally and against the built code in test pipelines. Similarly, the browser tests test against the browser build. This reduces compilation overhead as there is no longer a need to rebuild the source code when building the browser tests.

@github-actions github-actions bot added Azure.Identity dev-tool Issues related to the Azure SDK for JS dev-tool labels Jul 25, 2025
@deyaaeldeen deyaaeldeen force-pushed the identity/modular-tests branch 4 times, most recently from ad8dbac to 8f99b70 Compare July 25, 2025 23:59
@deyaaeldeen deyaaeldeen force-pushed the identity/modular-tests branch from 8f99b70 to ced0a2a Compare July 25, 2025 23:59
@deyaaeldeen deyaaeldeen changed the title [identity] src/build testing [identity] Improve the testing framework Jul 26, 2025
@deyaaeldeen deyaaeldeen marked this pull request as ready for review July 28, 2025 16:57
@Copilot Copilot AI review requested due to automatic review settings July 28, 2025 16:57
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the testing framework for the Azure Identity package by implementing separate TypeScript configurations for Node.js and browser environments, enabling precise type-checking and reducing build overhead. The changes eliminate unnecessary double compilation in browser tests and provide better separation of concerns between different runtime environments.

Key changes:

  • Splits test configurations into separate Node.js and browser TypeScript configs with environment-specific type checking
  • Implements consistent path aliasing using @azure/identity and internal/* patterns across all test files
  • Updates Vitest configurations with dynamic path resolution to test against source code locally and built code in CI pipelines

Reviewed Changes

Copilot reviewed 60 out of 60 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
vitest.esm.config.ts Removed ESM-specific Vitest configuration file
vitest.config.ts Added dynamic path resolution and alias configuration for testing
vitest.browser.config.ts Updated browser test configuration with new alias pattern
tsconfig.test.node.json New Node.js-specific test configuration with precise type checking
tsconfig.test.json Converted to project references structure
tsconfig.browser.config.json New browser-specific test configuration
test/**/*.spec.ts Updated import statements to use new aliasing pattern
package.json Simplified test scripts by removing ESM-specific commands
build-test.ts Enhanced build tool with better TypeScript config handling

Copy link
Member

@xirzec xirzec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love being able to avoid the extra build step for browser! Left some minor comments.

replacement: resolve(__dirname, `./${dist}/${indexFile}`),
},
{
find: /^internal\/(.*)$/,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we rename this to something more obviously a pseudo-module like $internal or test:internal

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in 4e9bd19

import { defineConfig, mergeConfig } from "vitest/config";
import viteConfig from "../../../vitest.shared.config.ts";

const isCI = process.env["SYSTEM_TEAMPROJECTID"] !== undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would love to have a helper function/module for this we could share between vitest configs, maybe in the shared config itself?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in 4e9bd19

@@ -76,7 +76,7 @@ export const CredentialUnavailableErrorName = "CredentialUnavailableError";
*/
export class CredentialUnavailableError extends Error {
constructor(message?: string, options?: { cause?: unknown }) {
// @ts-expect-error - TypeScript does not recognize this until we use ES2022 as the target; however, all our major runtimes do support the `cause` property
// @ts-ignore - TypeScript does not recognize this until we use ES2022 as the target; however, all our major runtimes do support the `cause` property
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we don't need this anymore now that https://github.com/Azure/azure-sdk-for-js/pull/35387/files is merged?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, it is no longer needed, addressed in 4e9bd19

const browserConfigStat = statSync(browserConfig);
if (!browserConfigStat.isFile()) {
log.error(`The file ${browserConfig} does not exist.`);
if (!(await validateConfigFile(browserConfig))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe combine the two ifs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we still need to do other logic in the browser tests case.

exclude: [
"dist-test/browser/test/snippets.spec.js",
"dist-test/browser/test/integration/**/*.spec.js"
alias: [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I am not sure whether it would work well with these aliases is the "Add imports" IDE feature that allows you to Ctrl+<DOT> or mouse click to add missing imports. Would the IDE know to add/update imports to these aliased paths? If not would tests be broken when imports to, e.g., "../../*.js" are added by IDE?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that can be annoying. In my experience, more often than not, the IDE doesn't import from the right places anyway and you need to go and edit the import. For example, when importing a definition exported by the library, the IDE may decide to import it from the defining module instead of src/index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Identity dev-tool Issues related to the Azure SDK for JS dev-tool
Projects
Status: Untriaged
Development

Successfully merging this pull request may close these issues.

4 participants