Skip to content

Commit 7dd903c

Browse files
authored
Merge pull request #2047 from Shopify/test-improvements
Improvements in the e2e test infrastructure
2 parents 981cdf5 + 0ef7971 commit 7dd903c

File tree

9 files changed

+258
-228
lines changed

9 files changed

+258
-228
lines changed

example/src/Tests/Tests.tsx

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
Canvas,
77
Skia,
88
makeImageFromView,
9-
Paragraph,
109
} from "@shopify/react-native-skia";
1110
import React, { useEffect, useRef, useState } from "react";
1211
import { PixelRatio, Platform, Text, View } from "react-native";
@@ -17,7 +16,8 @@ import { useClient } from "./useClient";
1716
import { Screens } from "./Screens";
1817

1918
export const CI = process.env.CI === "true";
20-
const scale = 3 / PixelRatio.get();
19+
const s = 3;
20+
const scale = s / PixelRatio.get();
2121
const size = 256 * scale;
2222
// Maximum time to draw: 250 on iOS, 500ms on Android, 1000ms on CI
2323
// eslint-disable-next-line no-nested-ternary
@@ -41,28 +41,15 @@ export const Tests = ({ assets }: TestsProps) => {
4141
client.send(
4242
JSON.stringify(
4343
eval(
44-
`(function Main(){return (${tree.code})(this.Skia, this.ctx); })`
44+
`(function Main(){return (${tree.code})(this.Skia, this.ctx, this.size, this.scale); })`
4545
).call({
4646
Skia,
4747
ctx: parseProps(tree.ctx, assets),
48+
size: size * PixelRatio.get(),
49+
scale: s,
4850
})
4951
)
5052
);
51-
} else if (tree.paragraph) {
52-
const paragraph = eval(
53-
`(function Main(){return (${tree.paragraph})(this.Skia, this.ctx); })`
54-
).call({
55-
Skia,
56-
ctx: parseProps(tree.ctx, assets),
57-
});
58-
setDrawing(
59-
<Paragraph
60-
paragraph={paragraph}
61-
width={tree.paragraphWidth}
62-
x={0}
63-
y={0}
64-
/>
65-
);
6653
} else if (typeof tree.screen === "string") {
6754
const Screen = Screens[tree.screen];
6855
if (!Screen) {

fabricexample/src/Tests/Tests.tsx

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
Canvas,
77
Skia,
88
makeImageFromView,
9-
Paragraph,
109
} from "@shopify/react-native-skia";
1110
import React, { useEffect, useRef, useState } from "react";
1211
import { PixelRatio, Platform, Text, View } from "react-native";
@@ -17,7 +16,8 @@ import { useClient } from "./useClient";
1716
import { Screens } from "./Screens";
1817

1918
export const CI = process.env.CI === "true";
20-
const scale = 3 / PixelRatio.get();
19+
const s = 3;
20+
const scale = s / PixelRatio.get();
2121
const size = 256 * scale;
2222
// Maximum time to draw: 250 on iOS, 500ms on Android, 1000ms on CI
2323
// eslint-disable-next-line no-nested-ternary
@@ -41,28 +41,15 @@ export const Tests = ({ assets }: TestsProps) => {
4141
client.send(
4242
JSON.stringify(
4343
eval(
44-
`(function Main(){return (${tree.code})(this.Skia, this.ctx); })`
44+
`(function Main(){return (${tree.code})(this.Skia, this.ctx, this.size, this.scale); })`
4545
).call({
4646
Skia,
4747
ctx: parseProps(tree.ctx, assets),
48+
size: size * PixelRatio.get(),
49+
scale: s,
4850
})
4951
)
5052
);
51-
} else if (tree.paragraph) {
52-
const paragraph = eval(
53-
`(function Main(){return (${tree.paragraph})(this.Skia, this.ctx); })`
54-
).call({
55-
Skia,
56-
ctx: parseProps(tree.ctx, assets),
57-
});
58-
setDrawing(
59-
<Paragraph
60-
paragraph={paragraph}
61-
width={tree.paragraphWidth}
62-
x={0}
63-
y={0}
64-
/>
65-
);
6653
} else if (typeof tree.screen === "string") {
6754
const Screen = Screens[tree.screen];
6855
if (!Screen) {

package/cpp/api/JsiSkCanvas.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#pragma clang diagnostic pop
3838

3939
namespace RNSkia {
40+
4041
namespace jsi = facebook::jsi;
4142

4243
class JsiSkCanvas : public JsiSkHostObject {
@@ -524,7 +525,7 @@ class JsiSkCanvas : public JsiSkHostObject {
524525
if (!_canvas->readPixels(*info, bfrPtr, bytesPerRow, srcX, srcY)) {
525526
return jsi::Value::null();
526527
}
527-
return std::move(dest);
528+
return dest;
528529
}
529530

530531
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkCanvas, drawPaint),

package/src/__tests__/setup.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ export const checkImage = (
6262
width: baseline.width,
6363
height: baseline.height,
6464
});
65+
if (baseline.width !== toTest.width || baseline.height !== toTest.height) {
66+
throw new Error(
67+
`Image sizes don't match: ${baseline.width}x${baseline.height} vs ${toTest.width}x${toTest.height}`
68+
);
69+
}
6570
const diffPixelsCount = pixelmatch(
6671
baseline.data,
6772
toTest.data,
18.3 KB
Loading
3.09 KB
Loading

0 commit comments

Comments
 (0)