Skip to content

Commit cad5a03

Browse files
authored
Merge branch 'main' into main
2 parents efc970f + f5d32ab commit cad5a03

File tree

5 files changed

+50
-11
lines changed

5 files changed

+50
-11
lines changed

.github/workflows/android-ubuntu.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Android Ubuntu
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
48

59
jobs:
610
build:

.github/workflows/android.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Android
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
48

59
jobs:
610
build:

.github/workflows/cpplint.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: cpplint
2-
on: [push]
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
37
jobs:
48
cpplint:
59
runs-on: ubuntu-latest

.github/workflows/tests.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: Tests
2-
on: [push]
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
37
jobs:
48
build:
59
runs-on: ubuntu-latest

README.md

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,17 @@ Publish the NPM package manually. The output is found in the `dist` folder.
6868

6969
- Install Cocoapods in the example/ios folder `cd example/ios && pod install && cd ..`
7070

71-
### Contributing
71+
## Contributing
7272

73+
When making contributions to the project, an important part is testing.
7374
In the `package` folder, we have several scripts set up to help you maintain the quality of the codebase and test your changes:
7475

7576
- `yarn lint` — Lints the code for potential errors and to ensure consistency with our coding standards.
7677
- `yarn tsc` — Runs the TypeScript compiler to check for typing issues.
7778
- `yarn test` — Executes the unit tests to ensure existing features work as expected after changes.
7879
- `yarn e2e` — Runs end-to-end tests. For these tests to run properly, you need to have the example app running. Use `yarn ios` or `yarn android` in the `example` folder and navigate to the Tests screen within the app.
7980

80-
#### Running End-to-End Tests
81+
## Running End-to-End Tests
8182

8283
To ensure the best reliability, we encourage running end-to-end tests before submitting your changes:
8384

@@ -86,17 +87,23 @@ To ensure the best reliability, we encourage running end-to-end tests before sub
8687
cd example
8788
yarn ios # or yarn android for Android testing
8889
```
90+
91+
Once the app is open in your simulator or device, press the "Tests" item at the bottom of the list.
8992

9093
2. With the example app running and the Tests screen open, run the following command in the `package` folder:
9194
```sh
9295
yarn e2e
9396
```
9497

9598
This will run through the automated tests and verify that your changes have not introduced any regressions.
99+
You can also run a particular using the following command:
100+
```sh
101+
E2E=true yarn test -i e2e/Colors
102+
```
96103

97-
#### Writing End-to-End Tests
104+
### Writing End-to-End Tests
98105

99-
Contributing end-to-end tests to React Native Skia is invaluable. Below you'll find guidelines for writing tests using the `eval` and `draw` commands.
106+
Contributing end-to-end tests to React Native Skia is extremely useful. Below you'll find guidelines for writing tests using the `eval`, `draw`, and `drawOffscreen` commands.
100107

101108
e2e tests are located in the `package/__tests__/e2e/` directory. You can create a file there or add a new test to an existing file depending on what is most sensible.
102109
When looking to contribute a new test, you can refer to existing tests to see how these can be built.
@@ -117,15 +124,18 @@ Both the `eval` and `draw` commands require a function that will be executed in
117124

118125
```tsx
119126
it("should generate commands properly", async () => {
127+
// Referencing the SVG variable directly in the tests would fail
128+
// as the function wouldn't be able to run in an isolated context
129+
const svg = "M 0 0, L 30 30";
120130
const result = await surface.eval((Skia, ctx) => {
121131
const path = Skia.Path.MakeFromSVGString(ctx.svg);
122132
return path.toCmds();
123-
}, { svg: "M 0 0, L 30 30" });
133+
}, { svg });
124134
expect(result).toEqual([[0, 0, 0], [1, 30, 30]]);
125135
});
126136
```
127137

128-
Another option is to use the `draw` command:
138+
A second option is to use the `draw` command where you can test the Skia components and get the resulting image:
129139
```tsx
130140
it("Path with default fillType", async () => {
131141
const { Skia } = importSkia();
@@ -141,4 +151,17 @@ it("Path with default fillType", async () => {
141151
});
142152
```
143153

144-
Again, since `eval` and `draw` serialize the function's content, avoid any external dependencies that can't be serialized.
154+
Finally, you can use `drawOffscreen` to receive a canvas object as parameter. You will also get the resulting image:
155+
156+
```tsx
157+
it("Should draw cyan", async () => {
158+
const image = await surface.drawOffscreen(
159+
(Skia, canvas, { size }) => {
160+
canvas.drawColor(Skia.Color("cyan"));
161+
}
162+
);
163+
checkImage(image, "snapshots/cyan.png");
164+
});
165+
```
166+
167+
Again, since `eval`, `draw`, and `drawOffscreen` serialize the function's content, avoid any external dependencies that can't be serialized.

0 commit comments

Comments
 (0)