Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/core/utils/user-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("userConfig", () => {
{
[convertToNativePaths(currentDir)]: {},
},
currentDir
currentDir,
);
const entry = await asyncGeneratorToArray(traverseFolder("/"));
expect(entry).toEqual([]);
Expand Down Expand Up @@ -129,7 +129,7 @@ describe("userConfig", () => {
{
[convertToNativePaths(currentDir)]: {},
},
currentDir
currentDir,
);
const file = await findSWAConfigFile("/");
expect(file).toBe(null);
Expand Down Expand Up @@ -159,7 +159,7 @@ describe("userConfig", () => {
expect(config).toBeNull();
expect(logger.warn).toHaveBeenLastCalledWith(
` WARNING: Functionality defined in the routes.json file is now deprecated. File will be ignored!\n` +
` Read more: https://docs.microsoft.com/azure/static-web-apps/configuration#routes`
` Read more: https://docs.microsoft.com/azure/static-web-apps/configuration#routes`,
);
});

Expand All @@ -178,10 +178,29 @@ describe("userConfig", () => {
expect(config).toBeNull();
expect(logger.warn).toHaveBeenLastCalledWith(
` WARNING: Functionality defined in the routes.json file is now deprecated. File will be ignored!\n` +
` Read more: https://docs.microsoft.com/azure/static-web-apps/configuration#routes`
` Read more: https://docs.microsoft.com/azure/static-web-apps/configuration#routes`,
);
});

it("should warn with KB unit when config file exceeds max size", async () => {
// Create a valid config file larger than 20KB (SWA_RUNTIME_CONFIG_MAX_SIZE_IN_KB)
// Use many routes to inflate file size while keeping schema valid
const routes = [];
for (let i = 0; i < 500; i++) {
routes.push({ route: `/route-${i}-${"a".repeat(30)}`, rewrite: `/index-${i}.html` });
}
const largeContent = JSON.stringify({ routes });
vol.fromJSON({
"staticwebapp.config.json": largeContent,
});

vi.spyOn(logger, "log").mockImplementation(() => {});

await findSWAConfigFile("/");
expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining("KB"));
expect(logger.warn).not.toHaveBeenCalledWith(expect.stringContaining("bytes"));
});

it("should ignore routes.json if a staticwebapp.config.json exists", async () => {
vol.fromNestedJSON({
s: {
Expand Down
4 changes: 2 additions & 2 deletions src/core/utils/user-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function findSWAConfigFile(folder: string): Promise<{ filepath: str
const fileSize = (await fs.stat(file.filepath)).size;
const fileSizeInKb = Math.round(fileSize / 1024);
if (fileSizeInKb > SWA_RUNTIME_CONFIG_MAX_SIZE_IN_KB) {
logger.warn(`WARNING: ${SWA_CONFIG_FILENAME} is ${fileSizeInKb} bytes. The maximum size is ${SWA_RUNTIME_CONFIG_MAX_SIZE_IN_KB} bytes.`);
logger.warn(`WARNING: ${SWA_CONFIG_FILENAME} is ${fileSizeInKb} KB. The maximum size is ${SWA_RUNTIME_CONFIG_MAX_SIZE_IN_KB} KB.`);
}

logger.silly(`Content parsed successfully`);
Expand All @@ -85,7 +85,7 @@ export async function findSWAConfigFile(folder: string): Promise<{ filepath: str
logger.warn(`Found legacy configuration file: ${file?.filepath}.`);
logger.warn(
` WARNING: Functionality defined in the routes.json file is now deprecated. File will be ignored!\n` +
` Read more: https://docs.microsoft.com/azure/static-web-apps/configuration#routes`
` Read more: https://docs.microsoft.com/azure/static-web-apps/configuration#routes`,
);
return null;
}
Expand Down
Loading