fix(container-loader): Return codeDetails.name (#21849)
This PR fixes a minor bug found in this PR: https://github.com/microsoft/FluidFramework/pull/21542/files#r1648285464
This commit is contained in:
Родитель
7049c9401e
Коммит
059c25a752
|
@ -214,15 +214,9 @@ export const getPackageName = (
|
|||
codeDetails: IFluidCodeDetails | undefined,
|
||||
): IContainerPackageInfo => {
|
||||
// TODO: use a real type
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let containerPackageName: any;
|
||||
if (codeDetails && "name" in codeDetails) {
|
||||
containerPackageName = codeDetails;
|
||||
} else if (isFluidPackage(codeDetails?.package)) {
|
||||
containerPackageName = codeDetails?.package.name;
|
||||
} else {
|
||||
containerPackageName = codeDetails?.package;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
return { name: containerPackageName };
|
||||
// This is the normal path that any modern customer would hit
|
||||
const containerPackageName: string | undefined = isFluidPackage(codeDetails?.package)
|
||||
? codeDetails?.package.name
|
||||
: codeDetails?.package;
|
||||
return { name: containerPackageName as string };
|
||||
};
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*!
|
||||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import { strict as assert } from "node:assert";
|
||||
|
||||
import type { IFluidCodeDetails } from "@fluidframework/container-definitions/internal";
|
||||
|
||||
import { getPackageName } from "../contracts.js";
|
||||
|
||||
const sampleCodeDetailsWithFluidPackage: IFluidCodeDetails = {
|
||||
package: {
|
||||
name: "fluid-package",
|
||||
fluid: {},
|
||||
},
|
||||
};
|
||||
|
||||
const sampleCodeDetailsWithPackageWithoutName: IFluidCodeDetails = {
|
||||
package: "simple-package",
|
||||
};
|
||||
|
||||
describe("Contract", () => {
|
||||
describe("getPackageName", () => {
|
||||
it("should return the package name if isFluidPackage returns true", () => {
|
||||
const result = getPackageName(sampleCodeDetailsWithFluidPackage);
|
||||
assert.deepEqual(result, { name: "fluid-package" });
|
||||
});
|
||||
|
||||
it("should return the package as it is if it does not have a name property", () => {
|
||||
const result = getPackageName(sampleCodeDetailsWithPackageWithoutName);
|
||||
assert.deepEqual(result, { name: "simple-package" });
|
||||
});
|
||||
|
||||
it("should return undefined", () => {
|
||||
const result = getPackageName(undefined);
|
||||
assert.deepEqual(result, { name: undefined });
|
||||
});
|
||||
});
|
||||
});
|
Загрузка…
Ссылка в новой задаче