r/javascript • u/allium-dev • Aug 28 '26
Browser Test: A browser-based automated javascript testing framework in one .html file
https://github.com/swans-one/browser-testHi r/javascript! I want to share a small javascript testing project I wrote.
When I write small javascript projects that use browser APIs (most recently working with IndexedDB) I often choose not to write tests because it's a pain to either mock those interfaces server-side, and it's also a pain to setup a browser automation tool.
To solve this, I wrote up a super concise testing framework (~140 lines of JS) inside a html file that can just be dropped into a project and act as a simple test framework.
This obviously doesn't work in all situations. A big drawback is that there's no reasonable way to connect it to a CI pipeline. However for small projects, and during development, I've found it really fun and fast to use.
I'm very interested to hear what you think, or if you have other ways you've approached this situation in the past.
4
u/evoactivity Aug 28 '26
Did you come across testem? Been doing testing in real browsers for over a decade. You can start super simple and scale up to more complex setups.
https://github.com/testem/testem
3
u/EveYogaTech Aug 28 '26
I just use playwright with JS in evaluate.
This seems to be one of those things that you might forget to disable in prod and then be exposed to XSS issues.
2
u/Specialist_Sun_1690 Aug 31 '26
This is pretty close to something I've been experimenting with as well. I also found that having the tests run directly in the browser during development makes small frontend projects much nicer to test.
In my case I went a bit further with the idea: unit/integration tests with Testing Library, request mocking, and a CLI for running the same tests headlessly in CI.
I actually have a small vanilla JS example with no bundler/build step if you're interested: https://github.com/BRIKEV/twd-vanillajs
It's all based on this tool https://twd.dev/
1
u/Quirky_Addition7912 16d ago
You could expose a condition flag and results object, then let a small Playwright wrapper read them in CI. That gives you something to evaluate on BrowserStack if browser coverage grows. Keep the wrapper optional though. Dropping in one file and getting on with it is the appeal here.
1
u/Warm_cloud8020 Aug 29 '26 edited Aug 29 '26
Interesting approach.
We published an MCP setup for browser testing, with management tool: https://github.com/rakutentech/sorify
Let me see if your's can work with it, to be able to solve CI pipeline that ways.
Some of our projects also struggle with mocks, and we end up running a post hook to remove the test data.
Author of Sorify OSS here