-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
18 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
import { runE2ETestExpectFailure } from "../../test-util/test-util"; | ||
//import { buildWebOn } from "../../src/build-webon/build-webon"; | ||
//import { runCliTestExpectFailure } from "../test-util/test-util"; | ||
import { getDebugPath } from "../../../src/util/util"; | ||
|
||
test("assetDir not existing", async () => { | ||
const output = await runE2ETestExpectFailure("build some-non-existing-dir"); | ||
expect(output).toBe( | ||
`error: ${getDebugPath("some-non-existing-dir")} does not exist.\n` | ||
`ERROR: ${getDebugPath("some-non-existing-dir")} does not exist.\n` | ||
); | ||
}); | ||
|
||
test("assetDir not a dir", async () => { | ||
const output = await runE2ETestExpectFailure("build README.md"); | ||
expect(output).toBe( | ||
`error: ${getDebugPath("README.md")} is not a directory.\n` | ||
`ERROR: ${getDebugPath("README.md")} is not a directory.\n` | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,9 @@ | ||
import { buildWebOn } from "../../../src/build-webon/build-webon"; | ||
import { enableUnitTest } from "../../../src/util/util"; | ||
import tar from "tar"; | ||
import { join, resolve } from "path"; | ||
import { existsSync, mkdirSync, readdirSync, renameSync } from "fs"; | ||
import { runE2ETestExpectFailure } from "../../test-util/test-util"; | ||
import { getDebugPath } from "../../../src/util/util"; | ||
|
||
enableUnitTest(); | ||
|
||
jest.mock("fs"); | ||
jest.mock("tar"); | ||
|
||
test("Should create a tar.gz WebOn file", async () => { | ||
const mockExistsSync = jest.spyOn(require("fs"), "existsSync"); | ||
const mockMkdirSync = jest.spyOn(require("fs"), "mkdirSync"); | ||
const mockRenameSync = jest.spyOn(require("fs"), "renameSync"); | ||
const mockTarCreate = jest.spyOn(tar, "create"); | ||
|
||
// Set up mock data and expectations | ||
const assetDir = "test/out"; | ||
const outDir = resolve(assetDir); | ||
const outDirPath = resolve(assetDir, "..", "out"); | ||
|
||
mockExistsSync.mockReturnValueOnce(true); // "out" directory doesn't exist | ||
mockRenameSync.mockImplementationOnce((source, destination) => { | ||
expect(source).toBe(assetDir); | ||
expect(destination).toBe(outDirPath); | ||
}); | ||
mockMkdirSync.mockImplementationOnce((path) => { | ||
expect(path).toBe(outDir); | ||
}); | ||
|
||
console.log('Directory exists:', existsSync(assetDir)); | ||
// Run the function | ||
await buildWebOn({ assetDir }); | ||
|
||
expect(mockExistsSync).toHaveBeenCalledWith(assetDir); | ||
// expect(mockRenameSync).toHaveBeenCalled(); | ||
expect(mockMkdirSync).toHaveBeenCalled(); | ||
expect(mockTarCreate).toHaveBeenCalledWith( | ||
{ | ||
file: expect.any(String), | ||
gzip: true, | ||
}, | ||
[outDir] | ||
test("assetDir not a dir", async () => { | ||
const output = await runE2ETestExpectFailure("build README.md"); | ||
expect(output).toBe( | ||
`ERROR: ${getDebugPath("README.md")} is not a directory.\n` | ||
); | ||
|
||
// Clear mocks after the test | ||
jest.clearAllMocks(); | ||
}); | ||
}); |