[identity] Use esm4mocha, re-enable IBC test, remove unnecessary stub (#28580)
### Packages impacted by this PR @azure/identity ### Issues associated with this PR Resolves #28373 ### 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 #28373 3. Removes sinon stubbing of uuid, replacing it with recorder replacer 4. 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
This commit is contained in:
Родитель
61341b7f03
Коммит
2e50e2a716
|
@ -1,8 +1,9 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license
|
||||
|
||||
import concurrently from "concurrently";
|
||||
import { leafCommand, makeCommandInfo } from "../../framework/command";
|
||||
|
||||
import concurrently from "concurrently";
|
||||
import { createPrinter } from "../../util/printer";
|
||||
import { isModuleProject } from "../../util/resolveProject";
|
||||
import { runTestsWithProxyTool } from "../../util/testUtils";
|
||||
|
@ -17,17 +18,31 @@ export const commandInfo = makeCommandInfo(
|
|||
default: false,
|
||||
description: "whether to run with test-proxy",
|
||||
},
|
||||
"use-esm-workaround": {
|
||||
shortName: "esm",
|
||||
kind: "boolean",
|
||||
default: true,
|
||||
description:
|
||||
"when true, uses the `esm` npm package for tests. Otherwise uses esm4mocha if needed",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
export default leafCommand(commandInfo, async (options) => {
|
||||
const isModule = await isModuleProject();
|
||||
let esmLoaderArgs = "";
|
||||
|
||||
if (isModule === false) {
|
||||
if (options["use-esm-workaround"] === false) {
|
||||
esmLoaderArgs = "--loader=../../../common/tools/esm4mocha.mjs";
|
||||
} else {
|
||||
esmLoaderArgs = "-r ../../../common/tools/esm-workaround -r esm";
|
||||
}
|
||||
}
|
||||
|
||||
const reporterArgs =
|
||||
"--reporter ../../../common/tools/mocha-multi-reporter.js --reporter-option output=test-results.xml";
|
||||
const defaultMochaArgs = `${
|
||||
(await isModuleProject())
|
||||
? "-r source-map-support/register.js"
|
||||
: "-r ../../../common/tools/esm-workaround -r esm -r source-map-support/register"
|
||||
} ${reporterArgs} --full-trace`;
|
||||
const defaultMochaArgs = `${esmLoaderArgs} -r source-map-support/register.js ${reporterArgs} --full-trace`;
|
||||
const updatedArgs = options["--"]?.map((opt) =>
|
||||
opt.includes("**") && !opt.startsWith("'") && !opt.startsWith('"') ? `"${opt}"` : opt,
|
||||
);
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import { readFile, stat, constants } from "node:fs/promises";
|
||||
import { constants, readFile, stat } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
import { Project } from "./dev-tool/node_modules/ts-morph/dist/ts-morph.js";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
// if modules are loaded from dist-esm/ treat them as ESM
|
||||
export async function resolve(specifier, context, defaultResolve) {
|
||||
|
@ -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";
|
||||
return { format, source, shortCircuit: true };
|
||||
}
|
||||
|
||||
async function updateSpecifierValueIfRelative(declaration, base) {
|
||||
|
|
|
@ -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 --use-esm-workaround=false -- --timeout 180000 'dist-esm/test/public/node/*.spec.js' 'dist-esm/test/internal/node/*.spec.js'",
|
||||
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
|
||||
"lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]",
|
||||
"lint": "eslint package.json api-extractor.json src test --ext .ts",
|
||||
|
@ -159,7 +159,6 @@
|
|||
"sinon": "^17.0.0",
|
||||
"ts-node": "^10.0.0",
|
||||
"typescript": "~5.3.3",
|
||||
"util": "^0.12.1",
|
||||
"esm": "^3.2.18"
|
||||
"util": "^0.12.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
assert.equal(getTokenSilentSpy.callCount, 1);
|
||||
|
|
|
@ -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");
|
||||
const credential = new ClientCertificateCredential("tenant", "client", {
|
||||
certificatePath: fullPath,
|
||||
});
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
|
||||
/* eslint-disable @typescript-eslint/no-namespace */
|
||||
|
||||
import { MsalTestCleanup, msalNodeTestSetup } from "../../node/msalNodeTestSetup";
|
||||
import { Recorder, env } from "@azure-tools/test-recorder";
|
||||
import { Context } from "mocha";
|
||||
import {
|
||||
InteractiveBrowserCredential,
|
||||
InteractiveBrowserCredentialNodeOptions,
|
||||
} from "../../../src";
|
||||
import { MsalTestCleanup, msalNodeTestSetup } from "../../node/msalNodeTestSetup";
|
||||
import { Recorder, env } from "@azure-tools/test-recorder";
|
||||
|
||||
import { Context } from "mocha";
|
||||
import Sinon from "sinon";
|
||||
import { assert } from "chai";
|
||||
import http from "http";
|
||||
|
@ -46,9 +46,7 @@ describe("InteractiveBrowserCredential (internal)", function () {
|
|||
|
||||
const scope = "https://vault.azure.net/.default";
|
||||
|
||||
// TODO: re-enable this when we resolve the esm incompatibility issues
|
||||
// https://github.com/Azure/azure-sdk-for-js/issues/28373
|
||||
it.skip("Throws an expected error if no browser is available", async function (this: Context) {
|
||||
it("Throws an expected error if no browser is available", async function (this: Context) {
|
||||
// The SinonStub type does not include this second parameter to throws().
|
||||
const testErrorMessage = "No browsers available on this test.";
|
||||
(sandbox.stub(interactiveBrowserMockable, "open") as any).throws(
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import * as util from "../../src/msal/utils";
|
||||
|
||||
import {
|
||||
AuthenticationResult,
|
||||
ConfidentialClientApplication,
|
||||
|
@ -46,9 +44,6 @@ export async function msalNodeTestSetup(
|
|||
|
||||
const sandbox = createSandbox();
|
||||
|
||||
const stub = sandbox.stub(util, "randomUUID");
|
||||
stub.returns(playbackValues.correlationId);
|
||||
|
||||
if (testContextOrStubbedToken instanceof Test || testContextOrStubbedToken === undefined) {
|
||||
const testContext = testContextOrStubbedToken;
|
||||
|
||||
|
@ -132,6 +127,11 @@ export async function msalNodeTestSetup(
|
|||
target: `x-client-VER=[a-zA-Z0-9.-]+`,
|
||||
value: `x-client-VER=identity-client-version`,
|
||||
},
|
||||
{
|
||||
regex: true,
|
||||
target: `client-request-id=[a-zA-Z0-9-]+`,
|
||||
value: `client-request-id=${playbackValues.correlationId}`,
|
||||
},
|
||||
],
|
||||
bodyKeySanitizers: [
|
||||
{
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
import * as fs from "fs";
|
||||
import * as jwt from "jsonwebtoken";
|
||||
import * as net from "net";
|
||||
import * as tls from "tls";
|
||||
|
||||
import jwt from "jsonwebtoken";
|
||||
import ms from "ms";
|
||||
import { randomUUID } from "@azure/core-util";
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче