зеркало из https://github.com/microsoft/rnx-kit.git
fix(lazy-index): update error messages (#2638)
This commit is contained in:
Родитель
950fcf0a3d
Коммит
a669c0210f
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@rnx-kit/react-native-lazy-index": patch
|
||||
---
|
||||
|
||||
Update error messages to reflect the latest changes
|
|
@ -34,12 +34,8 @@ function getFlightedModule(moduleId) {
|
|||
* @returns {Record<string, Component>}
|
||||
*/
|
||||
function parseExperiences(experiences) {
|
||||
if (!experiences) {
|
||||
throw new Error("Missing `experiences` section in `package.json`");
|
||||
}
|
||||
|
||||
if (typeof experiences !== "object") {
|
||||
throw new Error("Invalid `experiences` section in `package.json`");
|
||||
if (!experiences || typeof experiences !== "object") {
|
||||
throw new Error(`Invalid experiences map; got '${typeof experiences}'`);
|
||||
}
|
||||
|
||||
const flights = process.env["RN_LAZY_INDEX_FLIGHTS"]?.split(",");
|
||||
|
|
|
@ -64,6 +64,14 @@ function readExperiencesFromManifest() {
|
|||
const manifest = fs.readFileSync(manifestPath, { encoding: "utf-8" });
|
||||
const { experiences } = JSON.parse(manifest);
|
||||
|
||||
if (!experiences) {
|
||||
throw new Error("Missing `experiences` section in `package.json`");
|
||||
}
|
||||
|
||||
if (typeof experiences !== "object") {
|
||||
throw new Error("Invalid `experiences` section in `package.json`");
|
||||
}
|
||||
|
||||
return experiences;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
import fs from "fs";
|
||||
import { getFlightedModule, parseExperiences } from "../src/experiences";
|
||||
import { resolveModule } from "../src/module";
|
||||
|
||||
describe("parseExperiences()", () => {
|
||||
afterEach(() => {
|
||||
|
@ -8,24 +6,15 @@ describe("parseExperiences()", () => {
|
|||
});
|
||||
|
||||
test("missing experiences section", () => {
|
||||
const packageManifest = resolveModule("./package.json");
|
||||
const { experiences } = JSON.parse(
|
||||
fs.readFileSync(packageManifest, "utf-8")
|
||||
);
|
||||
const result = () => {
|
||||
parseExperiences(experiences);
|
||||
};
|
||||
const result = () => parseExperiences(undefined);
|
||||
expect(result).toThrow(Error);
|
||||
expect(result).toThrow("Missing `experiences` section in `package.json`");
|
||||
expect(result).toThrow("Invalid experiences map; got 'undefined'");
|
||||
});
|
||||
|
||||
test("invalid experiences section", () => {
|
||||
const experiences = "MyAwesomeApp";
|
||||
const result = () => {
|
||||
parseExperiences(experiences);
|
||||
};
|
||||
const result = () => parseExperiences("MyAwesomeApp");
|
||||
expect(result).toThrow(Error);
|
||||
expect(result).toThrow("Invalid `experiences` section in `package.json`");
|
||||
expect(result).toThrow("Invalid experiences map; got 'string'");
|
||||
});
|
||||
|
||||
test("object experiences section", () => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче