Skip to content

Commit 2ab7abe

Browse files
authored
Merge pull request #17 from thavelick/remove-jsdom-add-playwright-tests
Remove jsdom dependencies and add Playwright integration tests
2 parents c7ca8a4 + 5ac22dc commit 2ab7abe

File tree

10 files changed

+119
-565
lines changed

10 files changed

+119
-565
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.claude/
2-
node_modules/
2+
node_modules/
3+
test-results/

CLAUDE.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Just Bangs Lite is a client-side search tool with bang shortcuts (e.g., `python
1313
- **`public_html/main.js`**: Simple entry point that ONLY calls `initialize()` - no additional code or functions
1414
- **`public_html/index.html`**: Loads both scripts sequentially (search.js then main.js)
1515

16-
**IMPORTANT**: main.js exists solely to separate the function library (search.js) from execution for Jest compatibility. Adding any additional code or functions to main.js will break this separation and cause testing issues.
16+
**IMPORTANT**: main.js exists solely to separate the function library (search.js) from execution for test compatibility. Adding any additional code or functions to main.js will break this separation and cause testing issues.
1717

1818
### Dependency Injection Pattern
1919
Functions that use browser objects (like `window`) accept them as parameters for testability. Most commonly this is a `windowObj = window` parameter:
@@ -23,11 +23,13 @@ function someFunction(param, windowObj = window) { ... }
2323

2424
The `= window` default parameter makes the real browser object the default, allowing seamless browser usage while enabling tests to pass mock objects.
2525

26-
### Testing Without package.json
27-
- Uses Jest via `bunx jest` with custom configuration
26+
### Testing Without Dependencies
27+
- **Unit tests**: Uses Bun test runner via `bun test` - no package.json required
28+
- **Integration tests**: Uses Playwright via `bunx playwright test` for browser automation
2829
- CommonJS exports in search.js for Node.js compatibility: `module.exports = { ... }`
29-
- Test files in `tests/` directory with `.spec.js` extension
30-
- All functions tested with mock browser objects as needed
30+
- Unit test files in `tests/unit/` directory with `.spec.js` extension
31+
- Integration test files in `tests/integration/` directory with `.spec.js` extension
32+
- All unit tests use mock browser objects for isolation
3133

3234
## Development Commands
3335

@@ -42,8 +44,17 @@ make check # Run both formatting and linting checks
4244

4345
### Running Specific Tests
4446
```bash
47+
# Run unit tests only
48+
make test-unit
49+
50+
# Run integration tests only (requires dev server on port 8000)
51+
make test-integration
52+
53+
# Run all tests
54+
make test-all
55+
4556
# Run single test file
46-
bun test tests/search.spec.js
57+
bun test tests/unit/search.spec.js
4758

4859
# Run specific test pattern
4960
bun test -t "processBang"
@@ -59,7 +70,7 @@ bun test -t "processBang"
5970
### Module System
6071
- **Browser**: Regular script tags (no ES6 modules for broader compatibility)
6172
- **Tests**: CommonJS require/module.exports (Bun supports both)
62-
- **Minimal package.json**: Basic metadata only, no external dependencies
73+
- **No package.json**: Pure dependency-free JavaScript with external test runner
6374

6475
## Bang System
6576

@@ -83,7 +94,7 @@ Modify the `bangs` array in `search.js`:
8394
Always pass mock browser objects to test functions that interact with DOM, location, or other browser APIs:
8495
```javascript
8596
const mockWindow = {
86-
document: { getElementById: jest.fn() },
97+
document: { getElementById: () => {} },
8798
location: { search: "?q=test", href: "", hash: "" }
8899
};
89100
```

Makefile

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,38 @@ dev: # Start development server
1313

1414
format: # Format code with Biome
1515
@echo "Formatting code.."
16-
npx --yes @biomejs/biome format --write .
16+
bunx --bun @biomejs/biome format --write .
1717

1818
lint: # Lint code with Biome
1919
@echo "Linting code.."
20-
npx --yes @biomejs/biome lint .
20+
bunx --bun @biomejs/biome lint .
2121

2222
check: # Check formatting and linting with Biome
2323
@echo "Checking formatting and linting.."
24-
npx --yes @biomejs/biome check .
24+
bunx --bun @biomejs/biome check .
2525

2626
test: # Run unit tests with Bun
27-
@echo "Running tests.."
28-
bun test
27+
@echo "Running unit tests.."
28+
bun test tests/unit
29+
30+
test-unit: # Run unit tests only
31+
@echo "Running unit tests.."
32+
bun test tests/unit
33+
34+
test-coverage: # Run unit tests with coverage
35+
@echo "Running unit tests with coverage.."
36+
bun test tests/unit --coverage
37+
38+
test-integration: # Run integration tests with Playwright
39+
@echo "Running integration tests.."
40+
bunx playwright test tests/integration
41+
42+
test-all: # Run both unit and integration tests
43+
@echo "Running all tests.."
44+
@echo "Running unit tests.."
45+
bun test tests/unit
46+
@echo "Running integration tests.."
47+
bunx playwright test tests/integration
2948

3049
# -----------------------------------------------------------
3150
# CAUTION: If you have a file with the same name as make

bun.lock

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)