↖️ Show all posts

NoBuild Javascript for a Deno on Roda experiment

Deno has my interest. 🦕🛼

I fiddled with bun, too, but the feel was a bit different.

$ deno compile - what’s not to love?

Since the release of Deno v2, I can’t help but think: Can’t I use Deno’s tools in some helpful ways?

Following my GitHub you could see, that I enjoy working with Roda. My current undercover side project became one of the biggest codebases, I’ve ever written for myself. And JS is lacking tests. 🤙 #yolo #e2elifeguard

What parts of Deno could be useful in this context?
The pieces that somehow spoke to me were:

Could Deno remove the need for setting up and keeping up to date with eslint and prettier?
Maybe I wouldn’t have to setup and maintain jest or mocha even.

Path to NoBuild

Linting and formatting is straightforward. I’ve added a deno fmt and deno lint to my justfile.

test-js:
  deno test spec_js

test-js-watch:
	deno test --watch spec_js

lint-js:
	deno lint public/js
	deno lint --rules-exclude=no-window,no-window-prefix,no-global-assign assets/js

test-js:
	deno test spec_js/**/*test.*{js,ts,jsx,tsx}

This rules-excude will prevent Deno from complaining about global variables like window and document. This needs to be good enough for now.

Roda already ships with an asset bundling plugin. It’s a simple plugin that takes all your assets and bundles them into a single file. Yet some parts of the Javascript parts are becoming more business logic heavy and will benefit from unit testing. Here’s how Deno steps in.

I’ve created a spec_js folder in the root of my project. This is where I’ll put all my JS tests.

import { assertEquals } from "jsr:@std/assert";
import { Elvis } from "../public/js/rock-and-roll-superstar.js";

Deno.test("assert Elvis is in the house", () => {
  const elvis = new Elvis();
  assertEquals(elvis.pelvis() , "Elvis is in the house!");
});

I know this is a bit unusual.
But so is using Roda.
Deno v2 won’t change its APIs for quite some time (🤞). And if it will … I mean it’ll break just the tests… right?

Rewriting the js test suite is easy.
It’s a system rewrite that fails.
And why haven’t you used Rust in the first place?

- Charles Ponzi


⬅️ Read previous Read next ➡️