Skip to content

Commit 0dc393e

Browse files
authored
Merge pull request #3 from Visual-Regression-Tracker/8-diff-size
8 diff size
2 parents 7a6e69f + 59aca9b commit 0dc393e

File tree

12 files changed

+713
-125
lines changed

12 files changed

+713
-125
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ APP_FRONTEND_URL=http://localhost:8080
1212
POSTGRES_PORT=5432
1313
POSTGRES_USER=postgres
1414
POSTGRES_PASSWORD=postgres
15-
POSTGRES_DB=vrt_db
15+
POSTGRES_DB=vrt_db_dev

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"printWidth": 120,
4+
"trailingComma": "es5"
5+
}

prisma/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/vrt_db"
1+
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/vrt_db_dev"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Migration `20200526195312-approved-test-status-added`
2+
3+
This migration has been generated by Pavel Strunkin at 5/26/2020, 7:53:12 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 TYPE "TestStatus" ADD VALUE 'approved'
10+
```
11+
12+
## Changes
13+
14+
```diff
15+
diff --git schema.prisma schema.prisma
16+
migration 20200524162125-baseline-history..20200526195312-approved-test-status-added
17+
--- datamodel.dml
18+
+++ datamodel.dml
19+
@@ -3,9 +3,9 @@
20+
}
21+
datasource db {
22+
provider = "postgresql"
23+
- url = "***"
24+
+ url = env("DATABASE_URL")
25+
}
26+
model Build {
27+
id String @default(uuid()) @id
28+
@@ -101,5 +101,6 @@
29+
failed
30+
new
31+
ok
32+
unresolved
33+
+ approved
34+
}
35+
```
36+
37+
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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 @default(uuid()) @id
12+
number Int?
13+
branchName String?
14+
status String?
15+
testRuns TestRun[]
16+
projectId String
17+
project Project @relation(fields: [projectId], references: [id])
18+
updatedAt DateTime @updatedAt
19+
createdAt DateTime @default(now())
20+
user User? @relation(fields: [userId], references: [id])
21+
userId String?
22+
}
23+
24+
model Project {
25+
id String @default(uuid()) @id
26+
name String
27+
builds Build[]
28+
testVariations TestVariation[]
29+
updatedAt DateTime @updatedAt
30+
createdAt DateTime @default(now())
31+
}
32+
33+
model TestRun {
34+
id String @default(uuid()) @id
35+
imageName String
36+
diffName String?
37+
diffPercent Float?
38+
diffTollerancePercent Float @default(1.0)
39+
pixelMisMatchCount Int?
40+
status TestStatus
41+
buildId String
42+
build Build @relation(fields: [buildId], references: [id])
43+
testVariationId String
44+
testVariation TestVariation @relation(fields: [testVariationId], references: [id])
45+
updatedAt DateTime @updatedAt
46+
createdAt DateTime @default(now())
47+
// Test variation data
48+
name String @default("")
49+
browser String?
50+
device String?
51+
os String?
52+
viewport String?
53+
baselineName String?
54+
ignoreAreas String @default("[]")
55+
// Baseline
56+
baseline Baseline?
57+
}
58+
59+
model TestVariation {
60+
id String @default(uuid()) @id
61+
name String
62+
browser String?
63+
device String?
64+
os String?
65+
viewport String?
66+
baselineName String?
67+
ignoreAreas String @default("[]")
68+
projectId String
69+
project Project @relation(fields: [projectId], references: [id])
70+
testRuns TestRun[]
71+
baselines Baseline[]
72+
updatedAt DateTime @updatedAt
73+
createdAt DateTime @default(now())
74+
}
75+
76+
model Baseline {
77+
id String @default(uuid()) @id
78+
baselineName String
79+
testVariationId String
80+
testVariation TestVariation @relation(fields: [testVariationId], references: [id])
81+
testRunId String?
82+
testRun TestRun? @relation(fields: [testRunId], references: [id])
83+
updatedAt DateTime @updatedAt
84+
createdAt DateTime @default(now())
85+
}
86+
87+
model User {
88+
id String @default(uuid()) @id
89+
email String @unique
90+
password String
91+
firstName String?
92+
lastName String?
93+
apiKey String @unique
94+
isActive Boolean @default(true)
95+
builds Build[]
96+
updatedAt DateTime @updatedAt
97+
createdAt DateTime @default(now())
98+
}
99+
100+
enum TestStatus {
101+
failed
102+
new
103+
ok
104+
unresolved
105+
approved
106+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "0.3.14-fixed",
3+
"steps": [
4+
{
5+
"tag": "UpdateEnum",
6+
"enum": "TestStatus",
7+
"createdValues": [
8+
"approved"
9+
]
10+
}
11+
]
12+
}

prisma/migrations/migrate.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
# Read more about conflict resolution here: TODO
55

66
20200503001556-init
7-
20200524162125-baseline-history
7+
20200524162125-baseline-history
8+
20200526195312-approved-test-status-added

prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,5 @@ enum TestStatus {
102102
new
103103
ok
104104
unresolved
105+
approved
105106
}

src/shared/static/static.service.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@ export class StaticService {
99
constructor(private configService: ConfigService) {
1010
}
1111

12-
saveImage(imageName: string, imageBuffer: Buffer) {
12+
saveImage(type: 'screenshot' | 'diff' | 'baseline', imageBuffer: Buffer): string {
13+
const imageName = `${Date.now()}.${type}.png`
1314
writeFileSync(this.getImagePath(imageName), imageBuffer);
15+
return imageName
1416
}
1517

1618
getImage(imageName: string): PNGWithMetadata {
17-
return PNG.sync.read(readFileSync(this.getImagePath(imageName)));
19+
let image: PNGWithMetadata
20+
try {
21+
image = PNG.sync.read(readFileSync(this.getImagePath(imageName)))
22+
} catch (ex) {
23+
console.log(`Cannot image: ${imageName}. ${ex}`)
24+
}
25+
return image;
1826
}
1927

2028
async deleteImage(imageName: string): Promise<boolean> {

src/test-runs/diffResult.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { TestStatus } from '@prisma/client';
2+
3+
export interface DiffResult {
4+
status: TestStatus;
5+
imageName: string;
6+
pixelMisMatchCount: number;
7+
diffPercent: number;
8+
isSameDimension: boolean;
9+
}

0 commit comments

Comments
 (0)