Skip to content

Commit

Permalink
Fixed TAR packaging errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dev2-nomo committed Dec 19, 2023
1 parent 8e2a09b commit 5f4f372
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
Empty file removed cache/.gitkeep
Empty file.
11 changes: 7 additions & 4 deletions src/build-webon/build-webon.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export async function deleteExistingTarFile(
tarFilePath: string
): Promise<void> {
if (existsSync(tarFilePath)) {
console.log("Deleting existing tar file: " + getDebugPath(tarFilePath));
unlinkSync(tarFilePath);
}
}
Expand Down Expand Up @@ -63,8 +64,7 @@ export async function buildWebOn(assetDir: string): Promise<void> {
return;
}

const tarFileName = "nomo.tar.gz";
const tarFilePath = path.join(outDirPath, tarFileName);
const tarFilePath = "./nomo.tar.gz";

await deleteExistingTarFile(tarFilePath);

Expand All @@ -80,11 +80,14 @@ export async function buildWebOn(assetDir: string): Promise<void> {
}
}

async function createTarFile(
export async function createTarFile(
outDirPath: string,
tarFilePath: string
): Promise<void> {
console.log(`Creating WebOn: ${tarFilePath}`);
if (!existsSync(outDirPath)) {
logFatal("Output directory does not exist: " + outDirPath);
}

try {
await tar.create(
{
Expand Down
2 changes: 1 addition & 1 deletion src/util/util.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function isDirectory(path: string): boolean {
}
}
export function readCliConfig(): NomoCliConfigs {
const cliPath = resolve("nomo_cli.config.cjs");
const cliPath = resolve("nomo_cli.config.js");
try {
// @ts-ignore
const nomoCliConfig = require(cliPath);
Expand Down
7 changes: 2 additions & 5 deletions test/e2e/build-webon-test/packaging-completed.test.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ import {
test("nextjs_sample tar.gz build", async () => {
const output = await runE2ETest("build test_assets/nextjs_sample/out/");
expect(output).toContain("WebOn build completed: ");
const existsFile = fs.existsSync("test_assets/nextjs_sample/out/nomo.tar.gz");
const existsFile = fs.existsSync("nomo.tar.gz");
expect(existsFile).toBe(true);
await new Promise((resolve) => setTimeout(resolve, 5000));
fs.unlinkSync("test_assets/nextjs_sample/out/nomo.tar.gz");
});

test("cra_sample tar.gz build", async () => {
const output = await runE2ETest("build test_assets/cra_sample/out/");
expect(output).toContain("WebOn build completed: ");
const existsFile = fs.existsSync("test_assets/cra_sample/out/nomo.tar.gz");
const existsFile = fs.existsSync("nomo.tar.gz");
expect(existsFile).toBe(true);
fs.unlinkSync("test_assets/cra_sample/out/nomo.tar.gz");
});

test("missing required file", async () => {
Expand Down
42 changes: 41 additions & 1 deletion test/unitTest/build-tar-gz/build-tar.test.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { runUnitTestExpectFailure } from "../../test-util/test-util";
import {
runUnitTestExpectFailure,
runE2ETest,
} from "../../test-util/test-util";
import { createTarFile } from "../../../src/build-webon/build-webon";
import * as fs from "fs";
import * as path from "path";
import * as tar from "tar";

test("missing required file", async () => {
const output = await runUnitTestExpectFailure(
Expand All @@ -8,3 +15,36 @@ test("missing required file", async () => {
/Error: The 'out' directory is missing the following required files: .* Use nomo-webon-cli init if you do not have a nomo_manifest.json yet.\n/
);
});

jest.mock("fs");
jest.mock("tar");

describe("createTarFile", () => {
afterEach(() => {
jest.restoreAllMocks();
});

it("should create a tar file with the correct options", async () => {
const outDirPath = "/test_assets/my_sample/out";
const tarFilePath = "/test_assets/my_sample/out/nomo.tar.gz";

const existsSyncMock = jest.spyOn(fs, "existsSync");
existsSyncMock.mockReturnValue(true);

const createMock = tar.create as jest.Mock;
createMock.mockResolvedValue(undefined);

await createTarFile(outDirPath, tarFilePath);

expect(existsSyncMock).toHaveBeenCalledWith(outDirPath);
expect(createMock).toHaveBeenCalledWith(
{
file: tarFilePath,
gzip: true,
cwd: path.dirname(outDirPath),
},
[path.basename(outDirPath)]
);
expect(fs.existsSync(tarFilePath)).toBe(true);
});
});

0 comments on commit 5f4f372

Please sign in to comment.