Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test #1

Merged
merged 1 commit into from
Jan 17, 2024
Merged
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
38 changes: 38 additions & 0 deletions package/src/renderer/__tests__/e2e/Colors.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { surface } from "../setup";

describe("Colors", () => {
it("should support int, string, array, and Float32Array", async () => {
const result = await surface.eval((Skia) => {
const areEqualFloat32Arrays = (...arrays: Float32Array[]) => {
// Check if all arrays have the same length
const allSameLength = arrays.every(
(array) => array.length === arrays[0].length
);
if (!allSameLength) {
return false;
}

// Compare elements across all arrays for each index
for (let i = 0; i < arrays[0].length; i++) {
if (!arrays.every((array) => array[i] === arrays[0][i])) {
return false;
}
}

return true;
};

const c1 = Skia.Color("cyan");
const c2 = Skia.Color([0, 1, 1, 1]);
const c3 = Skia.Color(0xff00ffff);
const c4 = Skia.Color(Float32Array.of(0, 1, 1, 1));
Comment on lines +25 to +28
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks! I should have added these myself.

I assumed from #2113 that number[] expected 0-255 (and so coded it that way on the C++ side). Should I change it to 0-1 to match Float32Array?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually not sure I need to check 🙈 also a good test to add would be to use the drawOffscreen API to make sure they all generate the same image (cyan).
I tried to write more info at https://github.com/Shopify/react-native-skia/pull/2145/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5


const r = areEqualFloat32Arrays(c1, c2, c3, c4);
if (!r) {
console.log({ c1, c2, c3, c4 });
}
return r;
});
expect(result).toBe(true);
});
});
Loading