fix(lazy-index): update error messages (#2638)

This commit is contained in:
Tommy Nguyen 2023-08-29 13:32:03 +00:00 коммит произвёл GitHub
Родитель 950fcf0a3d
Коммит a669c0210f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 19 добавлений и 21 удалений

Просмотреть файл

@ -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>} * @returns {Record<string, Component>}
*/ */
function parseExperiences(experiences) { function parseExperiences(experiences) {
if (!experiences) { if (!experiences || typeof experiences !== "object") {
throw new Error("Missing `experiences` section in `package.json`"); throw new Error(`Invalid experiences map; got '${typeof experiences}'`);
}
if (typeof experiences !== "object") {
throw new Error("Invalid `experiences` section in `package.json`");
} }
const flights = process.env["RN_LAZY_INDEX_FLIGHTS"]?.split(","); const flights = process.env["RN_LAZY_INDEX_FLIGHTS"]?.split(",");

Просмотреть файл

@ -64,6 +64,14 @@ function readExperiencesFromManifest() {
const manifest = fs.readFileSync(manifestPath, { encoding: "utf-8" }); const manifest = fs.readFileSync(manifestPath, { encoding: "utf-8" });
const { experiences } = JSON.parse(manifest); 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; return experiences;
} }

Просмотреть файл

@ -1,6 +1,4 @@
import fs from "fs";
import { getFlightedModule, parseExperiences } from "../src/experiences"; import { getFlightedModule, parseExperiences } from "../src/experiences";
import { resolveModule } from "../src/module";
describe("parseExperiences()", () => { describe("parseExperiences()", () => {
afterEach(() => { afterEach(() => {
@ -8,24 +6,15 @@ describe("parseExperiences()", () => {
}); });
test("missing experiences section", () => { test("missing experiences section", () => {
const packageManifest = resolveModule("./package.json"); const result = () => parseExperiences(undefined);
const { experiences } = JSON.parse(
fs.readFileSync(packageManifest, "utf-8")
);
const result = () => {
parseExperiences(experiences);
};
expect(result).toThrow(Error); 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", () => { test("invalid experiences section", () => {
const experiences = "MyAwesomeApp"; const result = () => parseExperiences("MyAwesomeApp");
const result = () => {
parseExperiences(experiences);
};
expect(result).toThrow(Error); 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", () => { test("object experiences section", () => {