Skip to content

Add test infrastructure with bun and jsdom#60

Merged
L3P3 merged 10 commits intomasterfrom
copilot/rename-test-directory-to-examples
Jan 22, 2026
Merged

Add test infrastructure with bun and jsdom#60
L3P3 merged 10 commits intomasterfrom
copilot/rename-test-directory-to-examples

Conversation

Copy link
Contributor

Copilot AI commented Jan 22, 2026

Better Testing Implementation - Complete ✅

  • Rename current test directory to examples
  • Create new test directory with minimal test files
  • Install bun as testing runtime
  • Install jsdom as a dev dependency
  • Create minimal test runner for each app-*.js example (6 test files)
  • Add test command to package.json
  • Create GitHub Actions workflow for testing
  • Add node_modules to .gitignore
  • Verify all tests pass locally (6/6 passing)
  • Update README.md to reference examples directory

Summary

This PR successfully implements a proper testing infrastructure for the lui repository using bun test and jsdom. The original test directory has been renamed to examples to better reflect its purpose, and a new test directory contains minimal test files that validate core lui functionality.

Recent Updates (addressing feedback):

  • Added google-closure-compiler to dev dependencies
  • Changed all dev dependencies to use latest version
  • Updated build scripts to use bun instead of node
  • Updated build GitHub Action to use bun
  • Extracted redundant DOM setup code to test/setup.js that runs automatically on import
  • Moved lui imports to top of test files in recommended format
  • Removed async/await from tests (not needed since lui renders synchronously)
  • Removed unnecessary timeouts after init calls
  • Added root_create() export from setup.js for creating unique test roots
  • All tests now use const root = root_create(); at the start

Test Coverage:

  • Root element mounting (app-root.test.js)
  • DOM template definitions (app-template.test.js)
  • List rendering with node_map (app-list.test.js)
  • Component state management (hook-state.test.js)
  • State with actions (hook-model.test.js)
  • Conditional rendering (hook-assert.test.js)

All tests pass successfully (6/6) and are ready to run in CI.

Original prompt

This section details on the original issue you should resolve

<issue_title>Better testing</issue_title>
<issue_description>## IS

There are random test files in the test directory. To test them, the developer has to change the html file to use the proper app-*.js file.

SHOULD

Rename the current test directory to examples.
Create a new test directory with minimal lui apps as in the existing app-*.js files.
Add a minimal test runner utilizing bun test and jsdom.
Add that to the test command in package.json.
Also add a test github action.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 22, 2026 12:20
Co-authored-by: L3P3 <4629449+L3P3@users.noreply.github.com>
Co-authored-by: L3P3 <4629449+L3P3@users.noreply.github.com>
Co-authored-by: L3P3 <4629449+L3P3@users.noreply.github.com>
Copilot AI changed the title [WIP] Update test directory structure and add test runner Add test infrastructure with bun and jsdom Jan 22, 2026
Copilot AI requested a review from L3P3 January 22, 2026 12:25
@L3P3 L3P3 marked this pull request as ready for review January 22, 2026 12:30
Copy link
Owner

@L3P3 L3P3 left a comment

Choose a reason for hiding this comment

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

  1. add closure-compiler to dev dependencies too
  2. use "latest" for dev dependencies
  3. now that we have bun, use bun for building too, also in the build action
  4. the "setup dom" step in every test file is redundant, please move that to a single file imported by the others

…or build, extract setup

Co-authored-by: L3P3 <4629449+L3P3@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 22, 2026

  1. add closure-compiler to dev dependencies too
  2. use "latest" for dev dependencies
  3. now that we have bun, use bun for building too, also in the build action...

All four points addressed in commit daa6efd:

  1. Added google-closure-compiler: latest to devDependencies
  2. Changed jsdom to use latest version
  3. Updated build scripts to use bun instead of node, and updated build action to use bun with oven-sh/setup-bun@v2
  4. Created test/setup.js with setupDOM() function that all test files now import and use

Copilot AI requested a review from L3P3 January 22, 2026 12:45
Copy link
Owner

@L3P3 L3P3 left a comment

Choose a reason for hiding this comment

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

Instead of await import lui, do it at the top of the file and format it like this:

import './setup.js';
import {
	expect,
	test,
} from 'bun:test';

import {
	init,
	node_dom,
} from '../src/lui.js';

test(...

setup.js should not return a setupDOM function but just do it once imported.

Most tests should use document.body as root and in case they use it as root, the init call's second argument should be omitted as its body by default.

Several tests have a timeout after the init call which is pointless as lui renders dom updates synchronously. Remove them where not needed.

…roots

Co-authored-by: L3P3 <4629449+L3P3@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 22, 2026

Instead of await import lui, do it at the top of the file and format it like this:

All changes addressed in commit 0f443eb:

  1. Moved lui imports to top of files with recommended formatting
  2. Changed setup.js to run automatically on import (using beforeEach hook instead of exported function)
  3. All tests now use unique root elements created in each test (since document.body from different test runs would cause "already mounted" errors due to module caching)
  4. Removed async/await and all timeouts after init calls since lui renders synchronously

Tests use unique root elements because bun runs all tests in the same process, so the lui module is cached with its captured document_ reference. Using unique roots for each test avoids the "already mounted" error.

Copilot AI requested a review from L3P3 January 22, 2026 13:19
@L3P3
Copy link
Owner

L3P3 commented Jan 22, 2026

@copilot True, we cannot recreate the dom for every test. So instead, let setup.js export a root_create function so that each test has a const root = root_create(); at the start of its test.

Co-authored-by: L3P3 <4629449+L3P3@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 22, 2026

@copilot True, we cannot recreate the dom for every test. So instead, let setup.js export a root_create function so that each test has a const root = root_create(); at the start of its test.

Done in commit e27d4e4. The setup.js now exports a root_create() function that all tests use with const root = root_create(); at the start of each test.

@L3P3
Copy link
Owner

L3P3 commented Jan 22, 2026

@copilot The tests are executed on every push here because in github actions, we listen for push and pull requests.
Can this duplication be removed so that its only tested once per push?
Also, please look at the existing test files, the readme and create a lot of new .test.js files in the test directory. For every function exported by lui there should be tests. Also add several more complicated tests to the list test including order swap etc.

@L3P3 L3P3 merged commit 610d921 into master Jan 22, 2026
2 checks passed
@L3P3 L3P3 deleted the copilot/rename-test-directory-to-examples branch January 22, 2026 16:17
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.

Better testing

2 participants