Skip to content

Commit 1be16ec

Browse files
committed
tests: add new test cases
1 parent 5108c29 commit 1be16ec

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

tests/AppPackager.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,38 @@ describe("AppPackager", () => {
360360
// along with the custom ignored file
361361
});
362362

363+
it("should use forward slashes in zip entry paths for nested files", async () => {
364+
// Create files in subdirectories to exercise the path separator fix
365+
await fs.mkdirp(path.join(tempDir, "lib"));
366+
await fs.mkdirp(path.join(tempDir, "assets", "icons"));
367+
await fs.writeFile(
368+
path.join(tempDir, "lib", "helper.json"),
369+
'{"ok":true}',
370+
);
371+
await fs.writeFile(
372+
path.join(tempDir, "assets", "icons", "logo.png"),
373+
"fake png",
374+
);
375+
376+
const outputFile = path.join(tempDir, "output.zip");
377+
const packager = new AppPackager(
378+
compilerDesc,
379+
folderDetails,
380+
compilationResult,
381+
outputFile,
382+
);
383+
384+
await packager.zipItUp();
385+
386+
const zipContents = await getZipFileList(outputFile);
387+
388+
// Regardless of the host OS separator, zip entry paths must use "/"
389+
expect(zipContents).to.include("lib/helper.json");
390+
expect(zipContents).to.include("assets/icons/logo.png");
391+
expect(zipContents).to.not.include("lib\\helper.json");
392+
expect(zipContents).to.not.include("assets\\icons\\logo.png");
393+
});
394+
363395
it("should handle .rcappsconfig without ignoredFiles property", async () => {
364396
// Create .rcappsconfig without ignoredFiles property
365397
const rcAppsConfig = {

tests/TypescriptCompiler.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,30 @@ describe("TypescriptCompiler", () => {
118118
expect(result.implemented).to.deep.equal(["IPostMessageSent"]);
119119
});
120120

121+
it("normalizes backslash separators in sourceFiles keys and classFile (Windows paths)", () => {
122+
// Simulate an IAppSource constructed on Windows where path.join produces
123+
// backslash-separated keys and classFile comes from app.json with backslashes.
124+
const appInfo = { ...baseAppInfo, classFile: "lib\\Foo.ts" };
125+
126+
const sourceFiles: Record<string, ICompilerFile> = {
127+
"lib\\Foo.ts": {
128+
name: "lib\\Foo.ts",
129+
content: "export class Foo {}",
130+
version: 1,
131+
},
132+
};
133+
134+
const result = compiler.transpileSource({ appInfo, sourceFiles });
135+
136+
expect(result.diagnostics).to.be.empty;
137+
// Keys in result.files must use forward slashes regardless of input
138+
expect(Object.keys(result.files)).to.include("lib/Foo.js");
139+
expect(Object.keys(result.files)).to.not.include("lib\\Foo.js");
140+
// mainFile must be resolved correctly via the normalised classFile
141+
expect(result.mainFile).to.exist;
142+
expect(result.mainFile.name).to.equal("lib/Foo.js");
143+
});
144+
121145
it("throws on invalid permission names", () => {
122146
const badAppInfo = {
123147
...baseAppInfo,

0 commit comments

Comments
 (0)