Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,187 changes: 370 additions & 817 deletions package-lock.json

Large diffs are not rendered by default.

31 changes: 15 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"license": "Apache-2.0",
"scripts": {
"prebuild": "rimraf dist",
"postinstall": "prisma generate",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"prisma/**/*.ts\"",
"format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\" \"prisma/**/*.ts\"",
Expand All @@ -30,22 +29,22 @@
"dependencies": {
"@aws-sdk/client-s3": "^3.922.0",
"@aws-sdk/s3-request-presigner": "^3.922.0",
"@nestjs/cache-manager": "^3.0.1",
"@nestjs/common": "^11.1.8",
"@nestjs/config": "^4.0.2",
"@nestjs/core": "^11.1.8",
"@nestjs/jwt": "^11.0.1",
"@nestjs/passport": "^11.0.5",
"@nestjs/platform-express": "^11.1.8",
"@nestjs/platform-socket.io": "^11.1.8",
"@nestjs/schedule": "^6.0.1",
"@nestjs/swagger": "^11.2.1",
"@nestjs/terminus": "^11.0.0",
"@nestjs/websockets": "^11.1.8",
"@nestjs/cache-manager": "^2.1.0",
"@nestjs/common": "^10.2.5",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.2.5",
"@nestjs/jwt": "^10.1.1",
"@nestjs/passport": "^10.0.2",
"@nestjs/platform-express": "^10.3.9",
"@nestjs/platform-socket.io": "^10.3.9",
"@nestjs/schedule": "^3.0.3",
"@nestjs/swagger": "^7.1.11",
"@nestjs/terminus": "^10.1.1",
"@nestjs/websockets": "^10.4.4",
"@prisma/client": "^6.18.0",
"ajv": "^8.17.1",
"bcryptjs": "^2.4.3",
"cache-manager": "^7.2.4",
"cache-manager": "^3.6.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"fs-extra": "^11.3.2",
Expand All @@ -68,8 +67,8 @@
"devDependencies": {
"@darraghor/eslint-plugin-nestjs-typed": "^6.9.3",
"@nestjs/cli": "^11.0.10",
"@nestjs/schematics": "^11.0.9",
"@nestjs/testing": "^11.1.8",
"@nestjs/schematics": "^10.1.2",
"@nestjs/testing": "^10.2.5",
"@types/bcryptjs": "^2.4.4",
"@types/cache-manager": "^3.4.3",
"@types/express": "^4.17.17",
Expand Down
77 changes: 45 additions & 32 deletions prisma/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
},
"dependencies": {
"@prisma/client": "^6.18.0",
"bcryptjs": "^2.4.3"
"bcryptjs": "^3.0.3"
},
"devDependencies": {
"@types/bcryptjs": "^2.4.2",
"@types/bcryptjs": "^3.0.0",
"@types/jest": "^29.5.12",
"jest": "^29.7.0",
"jest-mock-extended": "^3.0.7",
"jest-mock-extended": "^4.0.0",
"prisma": "^6.18.0",
"ts-jest": "^29.4.5",
"ts-node": "^10.9.2",
Expand Down
53 changes: 53 additions & 0 deletions src/__mocks__/looks-same.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Mock for looks-same to avoid ESM @jsquash/png issues in Jest
// Provides a simple comparison implementation for tests
async function looksSame(
img1: Buffer | { source: Buffer },
img2: Buffer | { source: Buffer },
options?: any
): Promise<{ equal: boolean }> {
const buf1 = Buffer.isBuffer(img1) ? img1 : img1.source;
const buf2 = Buffer.isBuffer(img2) ? img2 : img2.source;

// Simple buffer comparison
if (buf1.length !== buf2.length) {
return { equal: false };
}

const tolerance = options?.tolerance ?? 2.5;
let diffPixels = 0;
const totalPixels = buf1.length / 4;

for (let i = 0; i < buf1.length; i += 4) {
const r1 = buf1[i];
const g1 = buf1[i + 1];
const b1 = buf1[i + 2];

const r2 = buf2[i];
const g2 = buf2[i + 1];
const b2 = buf2[i + 2];

const delta = Math.sqrt(
Math.pow(r1 - r2, 2) +
Math.pow(g1 - g2, 2) +
Math.pow(b1 - b2, 2)
) / 255 * 100;

if (delta > tolerance) {
diffPixels++;
}
}

const diffPercent = (diffPixels / totalPixels) * 100;
const equal = diffPercent === 0;

return { equal };
}

looksSame.createDiff = async function createDiff(options: any): Promise<void> {
// Simple diff creation - just copy reference to current
// For testing purposes, this is a no-op
return Promise.resolve();
};

export default looksSame;

56 changes: 56 additions & 0 deletions src/__mocks__/pixelmatch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Mock for pixelmatch to avoid ESM issues in Jest
// Provides a simple pixel-by-pixel comparison for tests
function pixelmatch(
img1: Buffer | Uint8Array | Uint8ClampedArray,
img2: Buffer | Uint8Array | Uint8ClampedArray,
output: Buffer | Uint8Array | Uint8ClampedArray | null,
width: number,
height: number,
options?: any
): number {
const threshold = options?.threshold ?? 0.1;
let diff = 0;

// Simple pixel comparison
for (let i = 0; i < img1.length; i += 4) {
const r1 = img1[i];
const g1 = img1[i + 1];
const b1 = img1[i + 2];
const a1 = img1[i + 3];

const r2 = img2[i];
const g2 = img2[i + 1];
const b2 = img2[i + 2];
const a2 = img2[i + 3];

// Calculate color difference
const delta = Math.sqrt(
Math.pow(r1 - r2, 2) +
Math.pow(g1 - g2, 2) +
Math.pow(b1 - b2, 2) +
Math.pow(a1 - a2, 2)
) / 255;

if (delta > threshold) {
diff++;
// Mark different pixels in output if provided
if (output) {
output[i] = 255; // R
output[i + 1] = 0; // G
output[i + 2] = 0; // B
output[i + 3] = 255; // A
}
} else if (output) {
// Copy original pixel to output
output[i] = img1[i];
output[i + 1] = img1[i + 1];
output[i + 2] = img1[i + 2];
output[i + 3] = img1[i + 3];
}
}

return diff;
}

export default pixelmatch;

12 changes: 11 additions & 1 deletion src/compare/libs/looks-same/looks-same.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { applyIgnoreAreas, parseConfig } from '../../utils';
import { ImageComparator } from '../image-comparator.interface';
import { ImageCompareInput } from '../ImageCompareInput';
import { LookSameResult, LooksSameConfig } from './looks-same.types';
import looksSame from 'looks-same';
import { DIFF_DIMENSION_RESULT, EQUAL_RESULT, NO_BASELINE_RESULT } from '../consts';

export const DEFAULT_CONFIG: LooksSameConfig = {
Expand All @@ -20,14 +19,23 @@ export const DEFAULT_CONFIG: LooksSameConfig = {
@Injectable()
export class LookSameService implements ImageComparator {
private readonly logger: Logger = new Logger(LookSameService.name);
private looksSame: any;

constructor(private readonly staticService: StaticService) {}

private async getLooksSame() {
if (!this.looksSame) {
this.looksSame = (await import('looks-same')).default;
}
return this.looksSame;
}

parseConfig(configJson: string): LooksSameConfig {
return parseConfig(configJson, DEFAULT_CONFIG, this.logger);
}

async getDiff(data: ImageCompareInput, config: LooksSameConfig): Promise<DiffResult> {
const looksSame = await this.getLooksSame();
const result: DiffResult = {
...NO_BASELINE_RESULT,
};
Expand Down Expand Up @@ -67,6 +75,7 @@ export class LookSameService implements ImageComparator {
}

async compare(baseline: PNG, image: PNG, config: LooksSameConfig): Promise<LookSameResult | undefined> {
const looksSame = await this.getLooksSame();
const diffResult = await looksSame(PNG.sync.write(baseline), PNG.sync.write(image), config).catch((error) => {
this.logger.error(error.message);
});
Expand All @@ -77,6 +86,7 @@ export class LookSameService implements ImageComparator {
}

async createDiff(baseline: PNG, image: PNG, config: LooksSameConfig): Promise<string | undefined> {
const looksSame = await this.getLooksSame();
const buffer = await looksSame
.createDiff({
reference: PNG.sync.write(baseline),
Expand Down
Loading
Loading