Skip to content

Commit

Permalink
Integration Test - minomax() added #18, test workflow enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
darsan-in committed Jan 15, 2025
1 parent 4824d20 commit d6ef667
Show file tree
Hide file tree
Showing 20 changed files with 626 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Node.js
uses: actions/[email protected]
with:
node-version: '16'
node-version: '20'
cache: yarn

- name: Install dependencies
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ node_modules
.pixteroid
outputs
minomax.err.log
test/temp-artifacts
*log*
9 changes: 5 additions & 4 deletions lib/core/imageset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ export default class ImageSetGenerator {
variableImgFormat: ImageWorkerOutputTypes | false;
destinationBase: string;
}): Promise<{ linkedImages: string[]; transformedHtmlFiles: string[] }> {
const pupeeterBatchSize: number = getFreeMemBatchSize({
memPerProc: 2000,
cPerBatchSize: this.#batchSizes.cPer,
});
const pupeeterBatchSize: number =
getFreeMemBatchSize({
memPerProc: 2000,
cPerBatchSize: this.#batchSizes.cPer,
}) || 1;

console.log(
`\n[${currentTime()}] +++> ⏰ Imageset generation started.`,
Expand Down
9 changes: 5 additions & 4 deletions lib/core/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,11 @@ export default class VideoWorker {
) {
videoPaths = Array.from(new Set(videoPaths)); //keep unique videos path

const videoEncodeBatchSize: number = getFreeMemBatchSize({
memPerProc: 1500,
cPerBatchSize: this.#batchSizes.cPer,
});
const videoEncodeBatchSize: number =
getFreeMemBatchSize({
memPerProc: 1500,
cPerBatchSize: this.#batchSizes.cPer,
}) || 1;

/* dumpRunTimeData({
data: videoPaths,
Expand Down
31 changes: 24 additions & 7 deletions minomax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ export class Minomax {
webDocLookUpPatterns?: string[];
destinationBasePath?: string;
removeOld?: boolean;
}): Promise<void> {
}): Promise<{
availableImages: string[];
availableVideos: string[];
thumnailCount: number;
}> {
this.#beforeAll();

ignorePatterns = [...ignorePatterns, `${destinationBasePath}/**`];
Expand Down Expand Up @@ -135,6 +139,7 @@ export class Minomax {
htmlFiles: transformedHtmlFiles,
variableImgFormat: targetFormat,
videoCodec: videoWorkerParams.codecType,
basePath: destinationBasePath,
});
const availableVideos = Object.keys(videoMetas);
const thumbnails = Object.values(videoMetas);
Expand Down Expand Up @@ -199,6 +204,12 @@ export class Minomax {
});

this.#afterAll();

return {
availableImages: imagePaths,
thumnailCount: thumbnails.length,
availableVideos: availableVideos,
};
}

async compressImages({
Expand Down Expand Up @@ -281,15 +292,15 @@ export class Minomax {
variableImgFormat = false,
videoCodec = false,
ignorePatterns = this.configurations.ignorePatterns,
}: /* destinationBase = this.configurations.destPath, */
{
basePath = "",
}: {
htmlFiles?: string[];
htmlLookupPattern?: string[];
seekPercentage?: number;
variableImgFormat?: ImageWorkerOutputTypes | false;
videoCodec?: CodecType | false;
ignorePatterns?: string[] | string;
/* destinationBase?: string; */
basePath?: string;
}): Promise<Record<string, string>> {
if (!htmlFiles && !htmlLookupPattern) {
terminate({
Expand All @@ -308,6 +319,10 @@ export class Minomax {
});
}

if (!htmlFiles?.length) {
return {};
}

console.log(
`\n[${currentTime()}] +++> ⏰ Thumbnail worker started.\n`,
);
Expand Down Expand Up @@ -335,8 +350,10 @@ export class Minomax {
//only hold existing videoPaths
Object.entries(metas).forEach(
([videoPath, thumbnailPath]) => {
if (existsSync(videoPath)) {
result[videoPath] = relative(
const realVidPath = relative(basePath, videoPath);

if (existsSync(realVidPath)) {
result[realVidPath] = relative(
process.cwd(),
thumbnailPath,
);
Expand Down Expand Up @@ -382,7 +399,7 @@ export class Minomax {
.thumbnailGenerator({
videoPath: videoPath,
seekPercentage: seekPercentage,
basepath: process.cwd(),
basepath: basePath,
})
.then(() => {
progressBar.increment();
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"scripts": {
"dev": "cls && rimraf dist && tsc -p tscdev.json && ncp ./bin/user-config-template.js ./dist/bin/user-config-template.js",
"build": "cls && rimraf dist && tsc -p tsconfig.json && ncp ./bin/user-config-template.js ./dist/bin/user-config-template.js",
"test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js",
"test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathIgnorePatterns=main.test.ts && node --experimental-vm-modules ./node_modules/jest/bin/jest.js main.test.ts",
"clean": "cls && rimraf dist",
"deploy": "yarn test && yarn build && yarn publish --access public && git push"
},
Expand Down Expand Up @@ -69,9 +69,9 @@
"glob": "11.0.0",
"handstop": "^1.0.3",
"html-minifier": "4.0.0",
"lightningcss": "^1.28.2",
"lightningcss": "^1.29.1",
"pixteroid": "^1.0.3",
"puppeteer": "23.11.1",
"puppeteer": "^23.11.1",
"remige": "^0.1.2",
"sharp": "^0.33.5",
"svgo": "3.3.2",
Expand All @@ -95,6 +95,6 @@
"ncp": "latest",
"rimraf": "latest",
"ts-node": "latest",
"typescript": "5.7.2"
"typescript": "5.7.3"
}
}
}
171 changes: 171 additions & 0 deletions test/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/* Integration Test */

import { globSync } from "glob";
import { rm } from "node:fs/promises";
import { extname, relative, sep } from "node:path";
import {
ImageWorkerParamsMain,
VideoWorkerParamsMain,
} from "../lib/types";
import { Minomax } from "../minomax";
import { imageWorkerTestConditions } from "./unit-test/util.compress-images";
import { videoWorkerTestConditions } from "./unit-test/util.compress-videos";
import { imageSetTestConditions } from "./unit-test/util.imageset";
import { videoThumnailGenTestConditions } from "./unit-test/util.video-thumbnail";
import { webdocTestConditions } from "./unit-test/util.webdoc";

const minomax = new Minomax();

async function _integrationTest({
imageWorkerParams,
videoWorkerParams,
ignorePatterns,
webDocLookUpPatterns,
destinationBasePath,
}: {
imageWorkerParams: ImageWorkerParamsMain;
videoWorkerParams: VideoWorkerParamsMain;
ignorePatterns: string[];
webDocLookUpPatterns: string[];
destinationBasePath: string;
}): Promise<boolean> {
const testTriggeredOn = Date.now(); // for file mod filter - cond (1) - thumbnailgenerator

const { availableImages, availableVideos, thumnailCount } =
await minomax.minomax({
imageWorkerParams: imageWorkerParams,
videoWorkerParams: videoWorkerParams,
ignorePatterns: ignorePatterns,
webDocLookUpPatterns: webDocLookUpPatterns,
destinationBasePath: destinationBasePath,
});

//1) copy test
const availableFilesInDest = globSync(webDocLookUpPatterns, {
cwd: destinationBasePath,
absolute: true,
nodir: true,
});

const expectedFileCount = 8; //manual definition as per available test samples

const copyTest_PASSED =
availableFilesInDest.length === expectedFileCount;

console.log(
"main - copyTest:",
copyTest_PASSED ? "✅ PASSED" : "❌ Failed",
);

const sourceHtmlFiles = availableFilesInDest
.filter((path) => extname(path) === ".html")
.map((path) =>
relative(destinationBasePath, path).replaceAll(sep, "/"),
);

const imageSet_PASSED = await imageSetTestConditions({
lookUpPatterns: sourceHtmlFiles,
destinationBasePath: destinationBasePath,
ignorePatterns: ignorePatterns,
vidThumbnailCount: thumnailCount,
});

console.log(
"main - imageSet:",
imageSet_PASSED ? "✅ PASSED" : "❌ Failed",
);

const imageWorker_PASSED = await imageWorkerTestConditions({
targetFormat: imageWorkerParams.targetFormat,
expectedFileCount: availableImages.length,
ignorePatterns: ignorePatterns,
destinationBasePath: destinationBasePath,
});

console.log(
"main - imageWorker:",
imageWorker_PASSED ? "✅ PASSED" : "❌ Failed",
);

const videoWorker_PASSED = await videoWorkerTestConditions({
codecType: videoWorkerParams.codecType,
lookUpPatterns: availableVideos.map((path) =>
path.replaceAll(sep, "/"),
),
expectedVideoFileCount: availableVideos.length,
ignorePatterns: ignorePatterns,
destinationBasePath: destinationBasePath,
});

console.log(
"main - videoWorker:",
videoWorker_PASSED ? "✅ PASSED" : "❌ Failed",
);

const videoThumbnailGen_PASSED = await videoThumnailGenTestConditions({
htmlLookupPattern: webDocLookUpPatterns
.filter((path) => path.endsWith("html"))
.map((path) => `${destinationBasePath}/${path}`),
ignorePatterns: ignorePatterns,
variableImgFormat: imageWorkerParams.targetFormat,
videoCodec: videoWorkerParams.codecType,
testTriggeredOn: testTriggeredOn,
});

console.log(
"main - videoThumnailGen:",
videoThumbnailGen_PASSED ? "✅ PASSED" : "❌ Failed",
);

const webdocWorker_PASSED = await webdocTestConditions({
lookUpPatterns: webDocLookUpPatterns,
lookUpBasePath: process.cwd(),
ignorePatterns: ignorePatterns,
destinationBasePath: destinationBasePath,
transformedHtml: true,
});

console.log(
"main - webdocWorker:",
webdocWorker_PASSED ? "✅ PASSED" : "❌ Failed",
);

const PASSED =
copyTest_PASSED &&
imageSet_PASSED &&
imageWorker_PASSED &&
videoWorker_PASSED &&
videoThumbnailGen_PASSED &&
webdocWorker_PASSED;

return PASSED;
}

const imageWorkerParams: ImageWorkerParamsMain = { targetFormat: "webp" };
const videoWorkerParams: VideoWorkerParamsMain = {
codecType: "mx265",
encodeLevel: 1,
};
const ignorePatterns = ["samples/webdocs/mangler-testset/HTML.html"];
const webDocLookUpPatterns = ["**/*.css", "**/*.js", "**/*.html"];
const destinationBasePath = "./temp-artifacts/main";

beforeAll(() => {
process.chdir(__dirname);
});

test("Integration Test", async () => {
expect(
await _integrationTest({
imageWorkerParams: imageWorkerParams,
videoWorkerParams: videoWorkerParams,
ignorePatterns: ignorePatterns,
webDocLookUpPatterns: webDocLookUpPatterns,
destinationBasePath: destinationBasePath,
}),
).toBe(true);
}, 180000);

afterAll(() => {
rm(destinationBasePath, { force: true, recursive: true });
});
2 changes: 1 addition & 1 deletion test/samples/webdocs/webroot-sim/css/one.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Base styles for images */
img {
display: block;
width: 1px;
width: 50px;
height: auto;
}

Expand Down
4 changes: 2 additions & 2 deletions test/unit-test/compress-images.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { rm } from "node:fs/promises";
import { testCompressImages } from "./util.compress-images";

const destinationBasePath = "test/.temp-artifacts/images";
const destinationBasePath = "test/temp-artifacts/images";
const targetFormat = "webp";
const lookUpPatterns = ["test/samples/images/**"];
const ignorePatterns = [
Expand All @@ -18,7 +18,7 @@ test("Unit Test - compressImages()", async () => {
ignorePatterns: ignorePatterns,
}),
).toBe(true);
}, 60000);
}, 100000);

afterAll(() => {
rm(destinationBasePath, { force: true, recursive: true });
Expand Down
4 changes: 2 additions & 2 deletions test/unit-test/compress-videos.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { rm } from "node:fs/promises";
import { testCompressVideos } from "./util.compress-videos";

const destinationBasePath = "test/.temp-artifacts/videos";
const destinationBasePath = "test/temp-artifacts/videos";
const lookUpPatterns = ["test/samples/videos/*.mp4"];
const ignorePatterns = ["test/samples/videos/*C.mp4"];
const codecType = "mx265";
Expand All @@ -17,7 +17,7 @@ test("Unit Test - compressVideos()", async () => {
encodeLevel: encodeLevel,
}),
).toBe(true);
}, 60000);
}, 100000);

afterAll(() => {
rm(destinationBasePath, { force: true, recursive: true });
Expand Down
4 changes: 2 additions & 2 deletions test/unit-test/imageset.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { rm } from "node:fs/promises";
import { testImageSet } from "./util.imageset";

const destinationBasePath = "test/.temp-artifacts/images-set";
const destinationBasePath = "test/temp-artifacts/images-set";
const lookUpPatterns = ["test/samples/webdocs/webroot-sim/**"];
const ignorePatterns = ["test/samples/webdocs/webroot-sim/page2.html"];

Expand All @@ -13,7 +13,7 @@ test("Unit Test - generateImageSets()", async () => {
ignorePatterns: ignorePatterns,
}),
).toBe(true);
}, 60000);
}, 100000);

afterAll(() => {
rm(destinationBasePath, { force: true, recursive: true });
Expand Down
Loading

0 comments on commit d6ef667

Please sign in to comment.