Skip to content
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

[identity] Use esm4mocha, re-enable IBC test, remove unnecessary stub #28580

Merged
merged 8 commits into from
Feb 15, 2024

Conversation

maorleger
Copy link
Member

@maorleger maorleger commented Feb 14, 2024

Packages impacted by this PR

@azure/identity

Issues associated with this PR

Describe the problem that is addressed by this PR

This PR addresses 3 things, all thanks to @jeremymeng's work on esm4mocha:

  1. Re-enables IBC test that was skipped due to [Identity] Re-enable interactiveBrowserCredential test #28373
  2. Removes sinon stubbing of uuid, replacing it with recorder replacer
  3. Fixes min/max tests for identity

Unfortunately we are not out of the woods regarding msal-node and esm. We would need to get everyone migrated over
to this loader before we can upgrade msal-node repo-wide :(

Provide a list of related PRs (if any)

#28556

Command used to generate this PR: (Applicable only to SDK release request PRs)

Checklists

  • Added impacted package name to the issue description.
  • Does this PR need any fixes in the SDK Generator?** (If so, create an Issue in the Autorest/typescript repository and link it here.)
  • Added a changelog (if necessary).

@@ -32,7 +33,8 @@ export async function load(url, context, defaultLoad) {
};
}
const { source } = await defaultLoad(url, context, defaultLoad);
return { format: context.format, source, shortCircuit: true };
const format = context.format ?? "builtin";
Copy link
Member Author

Choose a reason for hiding this comment

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

node:fs/promises wasn't importing correctly for me. I was thinking it's fine to default to builtin? Alternatively I can also do something like:

const format = context.format
if (format === undefined && url.startsWith("node:")) format = "builtin"

Or if anyone has a better suggestion, I am not too familiar with loader logic

Copy link
Member

Choose a reason for hiding this comment

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

interesting! My changes are barely minimum to get many packages test running. I am sure there are cases that aren't handled properly. If buildin works we will use it!

@@ -55,7 +55,7 @@
"format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
"check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
"integration-test:browser": "echo skipped",
"integration-test:node": "dev-tool run test:node-js-input -- --timeout 180000 'dist-esm/test/public/node/*.spec.js' 'dist-esm/test/internal/node/*.spec.js'",
"integration-test:node": "dev-tool run test:node-js-input --no-esm=true -- --loader=../../../common/tools/esm4mocha.mjs --timeout 180000 'dist-esm/test/public/node/*.spec.js' 'dist-esm/test/internal/node/*.spec.js'",
Copy link
Member Author

Choose a reason for hiding this comment

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

identity's integration tests use the recordings as well, for <reasons>, so we need the test proxy running. Easiest way is to keep using dev-tool commands

Copy link
Member

Choose a reason for hiding this comment

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

Yes I was going to add an option then switch most of our packages over to use that. Eventually also would like to make using the loader default behavior. --no-esm doesn't sound like a great name but I haven't got a better one either.

Copy link
Member Author

@maorleger maorleger Feb 14, 2024

Choose a reason for hiding this comment

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

I was thinking maybe something like "loader" with a default of esm?

Then, you could omit it for existing behavior or pass --loader=esm4mocha for the new mocha loader. Maybe that would be nicer? I'll push that up shortly because I also don't love "no-esm" - let me know how that looks once I push the changes up!

Once we are comfortable we can make the default value esm4mocha and everyone will just get it

Copy link
Member

Choose a reason for hiding this comment

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

I feel that --loader= may be confusing, sounding like you could pass any strings there but they get ignored. How about --use-esm-workaround=false with default value of true? I think there are only a handful packages that doesn't work immediately now with the esm4mocha loader. Once I switch majority over, I can make the default value false then added ``--use-esm-workaround=true` to those a few packages.

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 good point and I agree with loader being confusing... let me push up a change with your suggestion and we can see if that reads better 👍

@@ -95,7 +95,6 @@ describe("ClientAssertionCredential (internal)", function () {
await credential.getToken("https://vault.azure.net/.default");
} catch (e: any) {
// We're ignoring errors since our main goal here is to ensure that we send the correct parameters to MSAL.
console.log("error", e);
Copy link
Member Author

Choose a reason for hiding this comment

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

Adds noise, if we're ignoring it let's ignore it

@@ -114,7 +114,7 @@ describe("ClientCertificateCredential (internal)", function () {
});

it("throws when given a file that doesn't contain a PEM-formatted certificate", async function (this: Context) {
const fullPath = path.resolve(__dirname, "../src/index.ts");
const fullPath = path.resolve("./clientCertificateCredential.spec.ts");
Copy link
Member Author

Choose a reason for hiding this comment

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

__dirname is not supported, but it doesn't actually matter what file we send as long as it's not a proper cert

Copy link
Member

Choose a reason for hiding this comment

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

yeah __dirname is blocking some packages' test too. There's recommendation of const __dirname=path.dirname(url.fileURLToPath(import.meta.url) but import.meta.url requires "module" of "ES2020", which is at odds with our module of commonjs for test:node-ts-input :(

@@ -46,9 +44,6 @@ export async function msalNodeTestSetup(

const sandbox = createSandbox();

const stub = sandbox.stub(util, "randomUUID");
Copy link
Member Author

Choose a reason for hiding this comment

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

This is just a better world to live in, no weird wrapping and no concerns with immutable modules

import * as net from "net";
import * as tls from "tls";

import jwt from "jsonwebtoken";
Copy link
Member Author

Choose a reason for hiding this comment

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

this should be the default export to work

@maorleger
Copy link
Member Author

/azp run js - identity - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@maorleger
Copy link
Member Author

/azp run js - maps-geolocation-rest - tests

@maorleger
Copy link
Member Author

/azp run js - communication-identity - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

1 similar comment
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@azure-sdk
Copy link
Collaborator

API change check

API changes are not detected in this pull request.

},
);

export default leafCommand(commandInfo, async (options) => {
const reporterArgs =
"--reporter ../../../common/tools/mocha-multi-reporter.js --reporter-option output=test-results.xml";
const defaultMochaArgs = `${
(await isModuleProject())
options["no-esm"] === true || (await isModuleProject())
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking to use an option to toggle between the two workarounds, for example with --no-esm=true and if it is not module project, we would have "--loader=../../../esm4mocha.mjs -r source-map-support/register" so we don't have to pass the loader option in the package's NPM script.

@maorleger maorleger linked an issue Feb 14, 2024 that may be closed by this pull request
Copy link
Member

@jeremymeng jeremymeng left a comment

Choose a reason for hiding this comment

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

👍

@maorleger maorleger merged commit 2e50e2a into Azure:main Feb 15, 2024
23 checks passed
@maorleger maorleger deleted the esm4mocha-identity branch February 15, 2024 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

[Identity] Re-enable interactiveBrowserCredential test
3 participants