Skip to content

Commit 7a33d12

Browse files
committed
Merge branch 'master' into s3-integration
2 parents 080c07c + f1be51f commit 7a33d12

35 files changed

+299
-442
lines changed

.env

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ POSTGRES_USER=postgres
1212
POSTGRES_PASSWORD=postgres
1313
POSTGRES_DB=vrt_db_dev
1414

15-
#If you store your images in AWS S3 bucket, then you can give this config and it will take that config. A small amout of data is needed to temporarily keep the downloaded images. You can configure the size of that below.
16-
USE_AWS_S3_BUCKET=false
17-
AWS_ACCESS_KEY_ID=
18-
AWS_SECRET_ACCESS_KEY=
19-
AWS_REGION=
20-
AWS_S3_BUCKET_NAME=
21-
# Below is the maximum allowed usage of local space to optimize/prevent multiple download from S3 bucket. Give the value in MB. E.g. enter 1024 for 1GB
22-
MAX_TEMP_STORAGE_FOR_S3_DOWNLOAD=
15+
# static
16+
STATIC_SERVICE=hdd # hdd | s3 - hdd as default if not provided
17+
18+
# AWS_ACCESS_KEY_ID=
19+
# AWS_SECRET_ACCESS_KEY=
20+
# AWS_REGION=
21+
# AWS_S3_BUCKET_NAME=
2322

2423
# optional
2524
#HTTPS_KEY_PATH='./secrets/ssl.key'

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"**/.git/objects/**": true,
44
"**/.git/subtree-cache/**": true,
55
"**/.hg/store/**": true
6-
}
6+
},
7+
"jest.runMode":"on-demand"
78
}

package-lock.json

Lines changed: 0 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
"@nestjs/testing": "^10.2.5",
6969
"@types/bcryptjs": "^2.4.4",
7070
"@types/cache-manager": "^3.4.3",
71-
"@types/cron": "^2.4.0",
7271
"@types/express": "^4.17.17",
7372
"@types/jest": "^29.5.5",
7473
"@types/lodash": "^4.14.198",

src/compare/compare.module.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,11 @@ import { CompareService } from './compare.service';
33
import { LookSameService } from './libs/looks-same/looks-same.service';
44
import { OdiffService } from './libs/odiff/odiff.service';
55
import { PixelmatchService } from './libs/pixelmatch/pixelmatch.service';
6-
import { AWSS3Service } from '../shared/static/aws-s3.servce.';
7-
import { HardDiskService } from '../shared/static/hard-disk.service';
8-
import { STATIC_SERVICE, StaticService } from '../shared/static/static-service.interface';
6+
import { StaticModule } from '../static/static.module';
97

108
@Module({
11-
providers: [
12-
{
13-
provide: STATIC_SERVICE,
14-
useFactory: (): StaticService => {
15-
const isAWSDefined = process.env.USE_AWS_S3_BUCKET?.trim().toLowerCase() === 'true';
16-
return isAWSDefined ? new AWSS3Service() : new HardDiskService();
17-
},
18-
},
19-
CompareService,
20-
PixelmatchService,
21-
LookSameService,
22-
OdiffService,
23-
],
9+
providers: [CompareService, PixelmatchService, LookSameService, OdiffService],
10+
imports: [StaticModule],
2411
exports: [CompareService],
2512
})
2613
export class CompareModule {}

src/compare/compare.service.spec.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,15 @@ import { CompareService } from './compare.service';
44
import { LookSameService } from './libs/looks-same/looks-same.service';
55
import { OdiffService } from './libs/odiff/odiff.service';
66
import { PixelmatchService } from './libs/pixelmatch/pixelmatch.service';
7-
import { HardDiskService } from '../shared/static/hard-disk.service';
8-
import { STATIC_SERVICE } from '../shared/static/static-service.interface';
7+
import { StaticModule } from '../static/static.module';
98

109
describe('CompareService', () => {
1110
let service: CompareService;
1211

1312
beforeEach(async () => {
1413
const module: TestingModule = await Test.createTestingModule({
15-
providers: [
16-
{
17-
provide: STATIC_SERVICE,
18-
useClass: HardDiskService,
19-
},
20-
CompareService,
21-
OdiffService,
22-
PixelmatchService,
23-
LookSameService,
24-
PrismaService,
25-
],
14+
providers: [CompareService, OdiffService, PixelmatchService, LookSameService, PrismaService],
15+
imports: [StaticModule],
2616
}).compile();
2717

2818
service = module.get<CompareService>(CompareService);

src/compare/libs/looks-same/looks-same.service.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import { TestingModule, Test } from '@nestjs/testing';
22
import { TestStatus } from '@prisma/client';
33
import { PNG } from 'pngjs';
4+
import { StaticService } from '../../../static/static.service';
45
import { DIFF_DIMENSION_RESULT, EQUAL_RESULT, NO_BASELINE_RESULT } from '../consts';
56
import { DEFAULT_CONFIG, LookSameService } from './looks-same.service';
67
import { LooksSameConfig } from './looks-same.types';
7-
import { HardDiskService } from '../../../shared/static/hard-disk.service';
8-
import { STATIC_SERVICE } from '../../../shared/static/static-service.interface';
98

109
const initService = async ({ getImageMock = jest.fn(), saveImageMock = jest.fn(), deleteImageMock = jest.fn() }) => {
1110
const module: TestingModule = await Test.createTestingModule({
1211
providers: [
1312
LookSameService,
1413
{
15-
provide: STATIC_SERVICE,
16-
useClass: HardDiskService,
14+
provide: StaticService,
1715
useValue: {
1816
getImage: getImageMock,
1917
saveImage: saveImageMock,

src/compare/libs/looks-same/looks-same.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Inject, Injectable, Logger } from '@nestjs/common';
1+
import { Injectable, Logger } from '@nestjs/common';
22
import { TestStatus } from '@prisma/client';
33
import { PNG } from 'pngjs';
4-
import { STATIC_SERVICE, StaticService } from '../../../shared/static/static-service.interface';
4+
import { StaticService } from '../../../static/static.service';
55
import { DiffResult } from '../../../test-runs/diffResult';
66
import { applyIgnoreAreas, parseConfig } from '../../utils';
77
import { ImageComparator } from '../image-comparator.interface';
@@ -21,7 +21,7 @@ export const DEFAULT_CONFIG: LooksSameConfig = {
2121
export class LookSameService implements ImageComparator {
2222
private readonly logger: Logger = new Logger(LookSameService.name);
2323

24-
constructor(@Inject(STATIC_SERVICE) private staticService: StaticService) {}
24+
constructor(private staticService: StaticService) {}
2525

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

src/compare/libs/odiff/odiff.service.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { TestingModule, Test } from '@nestjs/testing';
22
import { TestStatus } from '@prisma/client';
33
import { IgnoreAreaDto } from 'src/test-runs/dto/ignore-area.dto';
4+
import { StaticService } from '../../../static/static.service';
45
import { DIFF_DIMENSION_RESULT, NO_BASELINE_RESULT } from '../consts';
56
import { OdiffService, DEFAULT_CONFIG, ignoreAreaToRegionMapper } from './odiff.service';
67
import { OdiffConfig, OdiffIgnoreRegions } from './odiff.types';
78
import { compare } from 'odiff-bin';
8-
import { HardDiskService } from '../../../shared/static/hard-disk.service';
9-
import { STATIC_SERVICE } from '../../../shared/static/static-service.interface';
109

1110
jest.mock('odiff-bin', () => ({
1211
compare: jest.fn(),
@@ -23,8 +22,7 @@ const initService = async ({
2322
providers: [
2423
OdiffService,
2524
{
26-
provide: STATIC_SERVICE,
27-
useClass: HardDiskService,
25+
provide: StaticService,
2826
useValue: {
2927
deleteImage: deleteImageMock,
3028
generateNewImage: generateNewImageMock,

src/compare/libs/odiff/odiff.service.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Inject, Injectable, Logger } from '@nestjs/common';
1+
import { Injectable, Logger } from '@nestjs/common';
22
import { TestStatus } from '@prisma/client';
3-
import { STATIC_SERVICE, StaticService } from '../../../shared/static/static-service.interface';
3+
import { StaticService } from '../../../static/static.service';
44
import { DiffResult } from '../../../test-runs/diffResult';
55
import { parseConfig } from '../../utils';
66
import { ImageComparator } from '../image-comparator.interface';
@@ -9,6 +9,8 @@ import { DIFF_DIMENSION_RESULT, NO_BASELINE_RESULT } from '../consts';
99
import { compare } from 'odiff-bin';
1010
import { IgnoreAreaDto } from 'src/test-runs/dto/ignore-area.dto';
1111
import { OdiffConfig, OdiffIgnoreRegions, OdiffResult } from './odiff.types';
12+
import { HddService } from 'src/static/hdd/hdd.service';
13+
import { isHddStaticServiceConfigured } from '../../../static/utils';
1214

1315
export const DEFAULT_CONFIG: OdiffConfig = {
1416
outputDiffMask: true,
@@ -20,8 +22,14 @@ export const DEFAULT_CONFIG: OdiffConfig = {
2022
@Injectable()
2123
export class OdiffService implements ImageComparator {
2224
private readonly logger: Logger = new Logger(OdiffService.name);
25+
private readonly hddService: HddService;
2326

24-
constructor(@Inject(STATIC_SERVICE) private staticService: StaticService) {}
27+
constructor(private staticService: StaticService) {
28+
if (!isHddStaticServiceConfigured()) {
29+
throw new Error('OdiffService can only be used with HddService');
30+
}
31+
this.hddService = this.staticService as unknown as HddService;
32+
}
2533

2634
parseConfig(configJson: string): OdiffConfig {
2735
return parseConfig(configJson, DEFAULT_CONFIG, this.logger);
@@ -37,10 +45,10 @@ export class OdiffService implements ImageComparator {
3745
}
3846

3947
// compare
40-
const diff = this.staticService.generateNewImage('diff');
48+
const diff = this.hddService.generateNewImage('diff');
4149
const compareResult = (await compare(
42-
this.staticService.getImagePath(data.baseline),
43-
this.staticService.getImagePath(data.image),
50+
this.hddService.getImagePath(data.baseline),
51+
this.hddService.getImagePath(data.image),
4452
diff.imagePath,
4553
{
4654
...config,

0 commit comments

Comments
 (0)