Skip to content

Commit

Permalink
Build tar.gz tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dev2-nomo committed Dec 1, 2023
1 parent 6546b35 commit 26f1b14
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
11 changes: 3 additions & 8 deletions src/build-webon/build-webon.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { logFatal, checkDir } from "../util/util";
import { checkDir } from "../util/util";
import { existsSync, mkdirSync, unlinkSync, renameSync } from "fs";
import * as path from "path";
import tar from "tar";
import * as fs from "fs";

export function renameAssetDir(assetDir: string): void {
try {
renameSync(assetDir, path.join(path.dirname(assetDir), "out"));
} catch (error) {
console.error(`Error renaming directory: ${error}`);
throw error;
}
}

export function createOutDir(outDirPath: string): void {
if (!existsSync(outDirPath)) {
console.log("Creating 'out' directory...");
mkdirSync(outDirPath);
}
}
Expand All @@ -32,13 +29,11 @@ export function checkRequiredFiles(outDirPath: string): string[] {

export function deleteExistingTarFile(tarFilePath: string): void {
if (existsSync(tarFilePath)) {
console.log(`Deleting existing nomo.tar.gz...`);
unlinkSync(tarFilePath);
}
}

export async function buildWebOn(args: { assetDir: string }): Promise<void> {
const assetDir = args.assetDir;
export async function buildWebOn(assetDir: string): Promise<void> {
const isOutDir = assetDir.endsWith("/out");
const outDirPath = isOutDir ? assetDir : path.resolve(assetDir, "..", "out");

Expand Down Expand Up @@ -79,7 +74,7 @@ async function createTarFile(
outDirPath: string,
tarFilePath: string
): Promise<void> {
console.log(`Creating new ${path.basename(tarFilePath)}: ${tarFilePath}`);
// console.log( `Creating new webon ${path.basename(tarFilePath)}: ${tarFilePath}`);

await tar.create(
{
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function commanderBuildWebOn() {
.description("Build a WebOn archive")
.action((assetDir) => {
runAsyncCommand(async () => {
await buildWebOn({ assetDir });
await buildWebOn(assetDir);
});
});
}
Expand Down
6 changes: 4 additions & 2 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { join, resolve } from "path";
import semver from "semver";
import { NomoCliConfigs } from "../init/interface";
import { exec } from "child_process";
import * as fs from "fs";

let _isUnitTest: boolean = false;

Expand All @@ -13,9 +14,10 @@ export function joinDirWithFileName(dir: string, fileName: string): string {

function isDirectory(path: string): boolean {
try {
const stat = lstatSync(path);
return stat.isDirectory();
const stat = fs.lstatSync(path).isDirectory();
return stat;
} catch (e) {
console.log(e);
return false;
}
}
Expand Down
22 changes: 22 additions & 0 deletions test/e2e/build-webon-test/packaging-completed.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as fs from "fs";
import {
runUnitTestExpectFailure,
runE2ETest,
} from "../../test-util/test-util";

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

test("missing required file", async () => {
const output = await runUnitTestExpectFailure(
"build test_assets/out_incomplete/out"
);
expect(output).toMatch(
/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/
);
});
11 changes: 8 additions & 3 deletions test/unitTest/build-tar-gz/build-tar.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { runUnitTestExpectFailure } from "../../test-util/test-util";
import {
runUnitTestExpectFailure,
runE2ETest,
} from "../../test-util/test-util";
import { enableUnitTest } from "../../../src/util/util";

enableUnitTest();
import * as fs from "fs";
import { buildWebOn } from "../../../src/build-webon/build-webon"; // Replace with the actual path to your module
import tar from "tar";
import * as path from "path";

test("missing required file", async () => {
const output = await runUnitTestExpectFailure(
Expand Down

0 comments on commit 26f1b14

Please sign in to comment.