Skip to content

Commit 43a467e

Browse files
authored
feat: look-same image compare library added (#141)
1 parent bda4709 commit 43a467e

24 files changed

+961
-313
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@
2727
"@nestjs/jwt": "^7.1.0",
2828
"@nestjs/passport": "^7.1.0",
2929
"@nestjs/platform-express": "^7.4.2",
30-
"@nestjs/platform-socket.io": "^7.4.2",
31-
"@nestjs/swagger": "^4.5.12",
30+
"@nestjs/platform-socket.io": "^7.6.17",
31+
"@nestjs/swagger": "^4.8.0",
3232
"@nestjs/websockets": "^7.4.2",
3333
"@prisma/client": "2.12.1",
3434
"bcryptjs": "^2.4.3",
3535
"cache-manager": "^3.4.0",
3636
"class-transformer": "^0.3.1",
3737
"class-validator": "^0.12.2",
3838
"fs-extra": "^9.0.1",
39+
"looks-same": "^7.3.0",
3940
"passport": "^0.4.1",
4041
"passport-jwt": "^4.0.0",
4142
"passport-local": "^1.0.0",
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Migration `20210605124856-image-compare-config-as-json`
2+
3+
This migration has been generated by Pavel Strunkin at 6/5/2021, 3:48:56 PM.
4+
You can check out the [state of the schema](./schema.prisma) after the migration.
5+
6+
## Database Steps
7+
8+
```sql
9+
ALTER TABLE "Project" DROP COLUMN "diffDimensionsFeature",
10+
DROP COLUMN "ignoreAntialiasing",
11+
DROP COLUMN "threshold",
12+
ADD COLUMN "imageComparisonConfig" TEXT NOT NULL DEFAULT E'{ "threshold": 0.1, "ignoreAntialiasing": true, "allowDiffDimensions": false }'
13+
```
14+
15+
## Changes
16+
17+
```diff
18+
diff --git schema.prisma schema.prisma
19+
migration 20210517203552-add-custom-tags..20210605124856-image-compare-config-as-json
20+
--- datamodel.dml
21+
+++ datamodel.dml
22+
@@ -3,9 +3,9 @@
23+
}
24+
datasource db {
25+
provider = "postgresql"
26+
- url = "***"
27+
+ url = "***"
28+
}
29+
model Build {
30+
id String @id @default(uuid())
31+
@@ -35,12 +35,10 @@
32+
updatedAt DateTime @updatedAt
33+
createdAt DateTime @default(now())
34+
// config
35+
autoApproveFeature Boolean @default(false)
36+
- diffDimensionsFeature Boolean @default(false)
37+
- ignoreAntialiasing Boolean @default(true)
38+
- threshold Float @default(0.1)
39+
imageComparison ImageComparison @default(pixelmatch)
40+
+ imageComparisonConfig String @default("{ \"threshold\": 0.1, \"ignoreAntialiasing\": true, \"allowDiffDimensions\": false }")
41+
@@unique([name])
42+
}
43+
```
44+
45+
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
generator client {
2+
provider = "prisma-client-js"
3+
}
4+
5+
datasource db {
6+
provider = "postgresql"
7+
url = "***"
8+
}
9+
10+
model Build {
11+
id String @id @default(uuid())
12+
ciBuildId String?
13+
number Int?
14+
branchName String?
15+
status String?
16+
testRuns TestRun[]
17+
projectId String
18+
project Project @relation(fields: [projectId], references: [id])
19+
updatedAt DateTime @updatedAt
20+
createdAt DateTime @default(now())
21+
user User? @relation(fields: [userId], references: [id])
22+
userId String?
23+
isRunning Boolean?
24+
25+
@@unique([projectId, ciBuildId])
26+
}
27+
28+
model Project {
29+
id String @id @default(uuid())
30+
name String
31+
mainBranchName String @default("master")
32+
builds Build[]
33+
buildsCounter Int @default(0)
34+
testVariations TestVariation[]
35+
updatedAt DateTime @updatedAt
36+
createdAt DateTime @default(now())
37+
// config
38+
autoApproveFeature Boolean @default(false)
39+
imageComparison ImageComparison @default(pixelmatch)
40+
imageComparisonConfig String @default("{ \"threshold\": 0.1, \"ignoreAntialiasing\": true, \"allowDiffDimensions\": false }")
41+
42+
@@unique([name])
43+
}
44+
45+
model TestRun {
46+
id String @id @default(uuid())
47+
imageName String
48+
diffName String?
49+
diffPercent Float?
50+
diffTollerancePercent Float @default(0)
51+
pixelMisMatchCount Int?
52+
status TestStatus
53+
buildId String
54+
build Build @relation(fields: [buildId], references: [id])
55+
testVariationId String?
56+
testVariation TestVariation? @relation(fields: [testVariationId], references: [id])
57+
merge Boolean @default(false)
58+
updatedAt DateTime @updatedAt
59+
createdAt DateTime @default(now())
60+
// Test variation data
61+
name String @default("")
62+
browser String?
63+
device String?
64+
os String?
65+
viewport String?
66+
customTags String? @default("")
67+
baselineName String?
68+
comment String?
69+
baseline Baseline?
70+
branchName String @default("master")
71+
baselineBranchName String?
72+
ignoreAreas String @default("[]")
73+
tempIgnoreAreas String @default("[]")
74+
}
75+
76+
model TestVariation {
77+
id String @id @default(uuid())
78+
name String
79+
branchName String @default("master")
80+
browser String @default("")
81+
device String @default("")
82+
os String @default("")
83+
viewport String @default("")
84+
customTags String @default("")
85+
baselineName String?
86+
ignoreAreas String @default("[]")
87+
projectId String
88+
project Project @relation(fields: [projectId], references: [id])
89+
testRuns TestRun[]
90+
baselines Baseline[]
91+
comment String?
92+
updatedAt DateTime @updatedAt
93+
createdAt DateTime @default(now())
94+
95+
@@unique([projectId, name, browser, device, os, viewport, customTags, branchName])
96+
}
97+
98+
model Baseline {
99+
id String @id @default(uuid())
100+
baselineName String
101+
testVariationId String
102+
testVariation TestVariation @relation(fields: [testVariationId], references: [id])
103+
testRunId String?
104+
testRun TestRun? @relation(fields: [testRunId], references: [id])
105+
updatedAt DateTime @updatedAt
106+
createdAt DateTime @default(now())
107+
}
108+
109+
model User {
110+
id String @id @default(uuid())
111+
email String @unique
112+
password String
113+
firstName String?
114+
lastName String?
115+
apiKey String @unique
116+
isActive Boolean @default(true)
117+
builds Build[]
118+
updatedAt DateTime @updatedAt
119+
createdAt DateTime @default(now())
120+
}
121+
122+
enum TestStatus {
123+
failed
124+
new
125+
ok
126+
unresolved
127+
approved
128+
autoApproved
129+
}
130+
131+
enum ImageComparison {
132+
pixelmatch
133+
lookSame
134+
odiff
135+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"version": "0.3.14-fixed",
3+
"steps": [
4+
{
5+
"tag": "CreateField",
6+
"model": "Project",
7+
"field": "imageComparisonConfig",
8+
"type": "String",
9+
"arity": "Required"
10+
},
11+
{
12+
"tag": "CreateDirective",
13+
"location": {
14+
"path": {
15+
"tag": "Field",
16+
"model": "Project",
17+
"field": "imageComparisonConfig"
18+
},
19+
"directive": "default"
20+
}
21+
},
22+
{
23+
"tag": "CreateArgument",
24+
"location": {
25+
"tag": "Directive",
26+
"path": {
27+
"tag": "Field",
28+
"model": "Project",
29+
"field": "imageComparisonConfig"
30+
},
31+
"directive": "default"
32+
},
33+
"argument": "",
34+
"value": "\"{ \\\"threshold\\\": 0.1, \\\"ignoreAntialiasing\\\": true, \\\"allowDiffDimensions\\\": false }\""
35+
},
36+
{
37+
"tag": "DeleteField",
38+
"model": "Project",
39+
"field": "diffDimensionsFeature"
40+
},
41+
{
42+
"tag": "DeleteField",
43+
"model": "Project",
44+
"field": "ignoreAntialiasing"
45+
},
46+
{
47+
"tag": "DeleteField",
48+
"model": "Project",
49+
"field": "threshold"
50+
}
51+
]
52+
}

prisma/migrations/migrate.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
20210228121726-test-run--nullable-test-variation-id
1818
20210405171118-github_243-set-empty-test-variation-tags-instead-of-null
1919
20210425191116-github_215_project_config
20-
20210517203552-add-custom-tags
20+
20210517203552-add-custom-tags
21+
20210605124856-image-compare-config-as-json

prisma/schema.prisma

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ model Project {
3636
createdAt DateTime @default(now())
3737
// config
3838
autoApproveFeature Boolean @default(false)
39-
diffDimensionsFeature Boolean @default(false)
40-
ignoreAntialiasing Boolean @default(true)
41-
threshold Float @default(0.1)
4239
imageComparison ImageComparison @default(pixelmatch)
40+
imageComparisonConfig String @default("{ \"threshold\": 0.1, \"ignoreAntialiasing\": true, \"allowDiffDimensions\": false }")
4341
4442
@@unique([name])
4543
}

src/_data_/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ export const TEST_PROJECT: Project = {
88
createdAt: new Date(),
99
updatedAt: new Date(),
1010
autoApproveFeature: true,
11-
diffDimensionsFeature: true,
12-
ignoreAntialiasing: true,
13-
threshold: 0.1,
11+
imageComparisonConfig: '{ "threshold": 0.1, "ignoreAntialiasing": true, "allowDiffDimensions": false }',
1412
imageComparison: ImageComparison.pixelmatch,
1513
};
1614

src/compare/compare.module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Module } from '@nestjs/common';
22
import { CompareService } from './compare.service';
3-
import { PixelmatchService } from './libs/pixelmatch.service';
3+
import { LookSameService } from './libs/looks-same/looks-same.service';
4+
import { PixelmatchService } from './libs/pixelmatch/pixelmatch.service';
45

56
@Module({
6-
providers: [CompareService, PixelmatchService],
7+
providers: [CompareService, PixelmatchService, LookSameService],
78
exports: [CompareService],
89
})
910
export class CompareModule {}

src/compare/compare.service.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { Test, TestingModule } from '@nestjs/testing';
22
import { PrismaService } from '../prisma/prisma.service';
33
import { StaticService } from '../shared/static/static.service';
44
import { CompareService } from './compare.service';
5-
import { PixelmatchService } from './libs/pixelmatch.service';
5+
import { LookSameService } from './libs/looks-same/looks-same.service';
6+
import { PixelmatchService } from './libs/pixelmatch/pixelmatch.service';
67

78
describe('CompareService', () => {
89
let service: CompareService;
910

1011
beforeEach(async () => {
1112
const module: TestingModule = await Test.createTestingModule({
12-
providers: [CompareService, PixelmatchService, StaticService, PrismaService],
13+
providers: [CompareService, PixelmatchService, LookSameService, StaticService, PrismaService],
1314
}).compile();
1415

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

0 commit comments

Comments
 (0)