-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[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
base: main
Are you sure you want to change the base?
Conversation
ad8dbac
to
8f99b70
Compare
8f99b70
to
ced0a2a
Compare
There was a problem hiding this 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
andinternal/*
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 |
There was a problem hiding this 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\/(.*)$/, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in 4e9bd19
sdk/identity/identity/src/errors.ts
Outdated
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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))) { |
There was a problem hiding this comment.
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 if
s?
There was a problem hiding this comment.
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: [ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
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:
build-package
dev-tool command and another using thebuild-test
command.Key Changes:
tsconfig.test.node.json
) and browser (tsconfig.browser.config.json
) configurations to enable precise type-checking.@azure/identity
andinternal/*
aliases across all test files. This aliasing enables testing built code or source code in a modular way.