Skip to content

Commit f8a33a6

Browse files
authored
Make 'npm run test:rust' work out-of-the-box (#6721)
* Make 'npm run test:rust' work out-of-the-box * Simplify instructions and remove stale * Update to use correct value from the documentation See https://doc.rust-lang.org/std/backtrace/index.html
1 parent af50422 commit f8a33a6

File tree

4 files changed

+15
-122
lines changed

4 files changed

+15
-122
lines changed

.env.development

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# DO NOT commit secrets, overrides go in the ignored `.env.development.local`
2+
13
NODE_ENV=development
24
DEV=true
35

@@ -7,7 +9,10 @@ VITE_KC_SITE_BASE_URL=https://dev.zoo.dev
79
VITE_KC_SITE_APP_URL=https://app.dev.zoo.dev
810
VITE_KC_SKIP_AUTH=false
911
VITE_KC_CONNECTION_TIMEOUT_MS=5000
10-
# ONLY add your token in .env.development.local if you want to skip auth, otherwise this token takes precedence!
11-
#VITE_KC_DEV_TOKEN="your token from dev.zoo.dev should go in .env.development.local"
12+
#VITE_KC_DEV_TOKEN="optional token from dev.zoo.dev to skip auth in the app"
13+
14+
RUST_BACKTRACE=1
15+
PYO3_PYTHON=/usr/local/bin/python3
16+
#KITTYCAD_API_TOKEN="required token from dev.zoo.dev for engine testing"
1217

1318
FAIL_ON_CONSOLE_ERRORS=true

CONTRIBUTING.md

Lines changed: 5 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -300,130 +300,16 @@ Which will run our suite of [Vitest unit](https://vitest.dev/) and [React Testin
300300

301301
### Rust tests
302302

303-
**Dependencies**
303+
Prepare these system dependencies:
304304

305-
- `KITTYCAD_API_TOKEN`
306-
- `cargo-nextest`
307-
- `just`
305+
- Set `$KITTYCAD_API_TOKEN` from https://dev.zoo.dev/account/api-tokens
306+
- Install `just` following [these instructions](https://just.systems/man/en/packages.html)
308307

309-
#### Setting KITTYCAD_API_TOKEN
310-
311-
Use the production zoo.dev token, set this environment variable before running the tests
312-
313-
#### Installing cargonextest
308+
then run tests that target the KCL language:
314309

315310
```
316-
cd rust
317-
cargo search cargo-nextest
318-
cargo install cargo-nextest
319-
```
320-
321-
#### just
322-
323-
install [`just`](https://github.com/casey/just?tab=readme-ov-file#pre-built-binaries)
324-
325-
#### Running the tests
326-
327-
```bash
328-
# With just
329-
# Make sure KITTYCAD_API_TOKEN=<prod zoo.dev token> is set
330-
# Make sure you installed cargo-nextest
331-
# Make sure you installed just
332-
cd rust
333-
just test
334-
```
335-
336-
```bash
337-
# Without just
338-
# Make sure KITTYCAD_API_TOKEN=<prod zoo.dev token> is set
339-
# Make sure you installed cargo-nextest
340-
cd rust
341-
export RUST_BRACKTRACE="full" && cargo nextest run --workspace --test-threads=1
342-
```
343-
344-
Where `XXX` is an API token from the production engine (NOT the dev environment).
345-
346-
We recommend using [nextest](https://nexte.st/) to run the Rust tests (its faster and is used in CI). Once installed, run the tests using
347-
348-
```
349-
cd rust
350-
KITTYCAD_API_TOKEN=XXX cargo run nextest
351-
```
352-
353-
### Mapping CI CD jobs to local commands
354-
355-
When you see the CI CD fail on jobs you may wonder three things
356-
357-
- Do I have a bug in my code?
358-
- Is the test flaky?
359-
- Is there a bug in `main`?
360-
361-
To answer these questions the following commands will give you confidence to locate the issue.
362-
363-
#### Static Analysis
364-
365-
Part of the CI CD pipeline performs static analysis on the code. Use the following commands to mimic the CI CD jobs.
366-
367-
The following set of commands should get us closer to one and done commands to instantly retest issues.
368-
369-
```
370-
npm run test-setup
371-
```
372-
373-
> Gotcha, are packages up to date and is the wasm built?
374-
311+
npm run test:rust
375312
```
376-
npm run tsc
377-
npm run fmt:check
378-
npm run lint
379-
npm run test:unit:local
380-
```
381-
382-
> Gotcha: Our unit tests have integration tests in them. You need to run a localhost server to run the unit tests.
383-
384-
#### E2E Tests
385-
386-
**Playwright Electron**
387-
388-
These E2E tests run in electron. There are tests that are skipped if they are ran in a windows, linux, or macos environment. We can use playwright tags to implement test skipping.
389-
390-
```
391-
npm run test:playwright:electron:local
392-
npm run test:playwright:electron:windows:local
393-
npm run test:playwright:electron:macos:local
394-
npm run test:playwright:electron:ubuntu:local
395-
```
396-
397-
> Why does it say local? The CI CD commands that run in the pipeline cannot be ran locally. A single command will not properly setup the testing environment locally.
398-
399-
#### Some notes on CI
400-
401-
The tests are broken into snapshot tests and non-snapshot tests, and they run in that order, they automatically commit new snap shots, so if you see an image commit check it was an intended change. If we have non-determinism in the snapshots such that they are always committing new images, hopefully this annoyance makes us fix them asap, if you notice this happening let Kurt know. But for the odd occasion `git reset --hard HEAD~ && git push -f` is your friend.
402-
403-
How to interpret failing playwright tests?
404-
If your tests fail, click through to the action and see that the tests failed on a line that includes `await page.getByTestId('loading').waitFor({ state: 'detached' })`, this means the test fail because the stream never started. It's you choice if you want to re-run the test, or ignore the failure.
405-
406-
We run on ubuntu and macos, because safari doesn't work on linux because of the dreaded "no RTCPeerConnection variable" error. But linux runs first and then macos for the same reason that we limit the number of parallel tests to 1 because we limit stream connections per user, so tests would start failing we if let them run together.
407-
408-
If something fails on CI you can download the artifact, unzip it and then open `playwright-report/data/<UUID>.zip` with https://trace.playwright.dev/ to see what happened.
409-
410-
#### Getting started writing a playwright test in our app
411-
412-
Besides following the instructions above and using the playwright docs, our app is weird because of the whole stream thing, which means our testing is weird. Because we've just figured out this stuff and therefore docs might go stale quick here's a 15min vid/tutorial
413-
414-
https://github.com/KittyCAD/modeling-app/assets/29681384/6f5e8e85-1003-4fd9-be7f-f36ce833942d
415-
416-
<details>
417-
418-
<summary>
419-
PS: for the debug panel, the following JSON is useful for snapping the camera
420-
</summary>
421-
422-
```JSON
423-
{"type":"modeling_cmd_req","cmd_id":"054e5472-e5e9-4071-92d7-1ce3bac61956","cmd":{"type":"default_camera_look_at","center":{"x":15,"y":0,"z":0},"up":{"x":0,"y":0,"z":1},"vantage":{"x":30,"y":30,"z":30}}}
424-
```
425-
426-
</details>
427313

428314
### Logging
429315

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ test: test-unit test-e2e
106106

107107
.PHONY: test-unit
108108
test-unit: install ## Run the unit tests
109+
npm run test:rust
109110
@ curl -fs localhost:3000 >/dev/null || ( echo "Error: localhost:3000 not available, 'make run-web' first" && exit 1 )
110111
npm run test:unit
111112

rust/justfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ redo-sim-tests:
5252
EXPECTORATE=overwrite TWENTY_TWENTY=overwrite {{cita}} {{kcl_lib_flags}} --no-quiet -- simulation_tests
5353

5454
test:
55-
export RUST_BRACKTRACE="full" && {{cnr}} --workspace --features artifact-graph --no-fail-fast
55+
cargo install cargo-nextest
56+
{{cnr}} --workspace --features artifact-graph --no-fail-fast
5657

5758
bump-kcl-crate-versions bump='patch':
5859
# First build the kcl-bumper tool.

0 commit comments

Comments
 (0)