Skip to content

Conversation

nadr0
Copy link
Contributor

@nadr0 nadr0 commented Oct 6, 2025

closes #8377

Issue

I made a massive integration.spec.ts because the engine connection code and WASM loaders were not stable with multiple files spamming initPromise()

Implementation

  • Properly split each file
  • Each file will initialize all its dependencies locally
  • Limit or totally remove the global dependencies
  • unitTestUtils.ts implements buildTheWorldAndConnectToEngine and buildTheWorldAndNoEngineConnection
  • Load WASM instance off disk with read file instead of localhost:3000
  const WASM_PATH = join(process.cwd(), 'public/kcl_wasm_lib_bg.wasm')
  const instance = await loadAndInitialiseWasmInstance(WASM_PATH)
  • Every single it( test can build the world and do engineCommandManager.tearDown()
  • Every single initPromise() spam will have a Promise.resolve() but say it failed so all of the tests will brick unless you build the world
  • Maybe functions, code paths, classes now accept optional arguments for different amounts of the "world".

Even though an entire .spec.ts file can have each it( test build the world with engine connection and destroy it that is super resource intensive so a single file will do this at the start and destroy at the end. This is not the same as using global singletons imports. Everything is still created locally within that file and passed to all the it( tests.

  • Tests that do not use the engine connection will build the world each it( since it is all based on memory usage not the remote engine connection.

  • Each test that needs only a WASM instance will build it again since you read off disk and then store an instance of it in memory.

  • All *.spec.ts(x) files are migrated

  • npx vitest run --mode development --no-file-parallelism --project integration will run all the tests with 1 file at a time.

  • Massive wasmInstance?: ModuleType spammed in every helper function

  • huge update to the modelingMachine to use the context and the provided ones over the global ones

Copy link

vercel bot commented Oct 6, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
modeling-app Ready Ready Preview Comment Oct 21, 2025 4:40pm

💡 Enable Vercel Agent with $100 free credit for automated AI reviews

@nadr0 nadr0 requested a review from a team as a code owner October 20, 2025 21:49

- name: Install Chromium Browser
if: ${{ github.event_name != 'release' && github.event_name != 'schedule' }}
run: npm run playwright install chromium --with-deps
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking, do the integration tests still need a real web browser?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not think so? https://vitest.dev/guide/browser/

I am trying to see if it is possible to configure a browser with vitest. I honestly do not think we have this integration enabled. I checked the vitest.config.ts

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, seems like we don't need the browser. For review to merge into this branch: #8622

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I changed my mind and marked that as a draft based on this conversation. Ideally, the npm-test-unit job doesn't need Wasm at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. The proper way to solve this would be dependency injection and not directly importing WASM functions from that binding.

Our application today does not do dependency injection so the dependency must exist for the unit test to import even if my unit test is not directly using it. The import/export builder step will crash.

Copy link
Contributor

@jacebrowning jacebrowning left a comment

Choose a reason for hiding this comment

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

Great work on this!

…hub.com:KittyCAD/modeling-app into nadro/gh-8377/wasm-instance-in-integration-test
@nadr0 nadr0 merged commit 6d90865 into main Oct 21, 2025
57 checks passed
@nadr0 nadr0 deleted the nadro/gh-8377/wasm-instance-in-integration-test branch October 21, 2025 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: Move all of the unit tests that require a file to be served to a different workflow.

2 participants