picostitch
crafting (and) JavaScript

Tidbits tagged with #nodejs (3)

#JavaScript

ECMAScript Module Support in nodejs

While working on pico-tester I realized I am not as knowledgable in nodejs' support for ECMAScript Modules (esm).
I think it's very simple in the browser. There is <script type=module> which understands import and there is <script nomodule> which nicely gradually falls back to before ESM times. But what about nodejs? There is a package.json with properties such as main: <filename>, exports: {} type: module, type: commonjs, and any combination of them. For a long time I am using the package esm to allow me to use ESM on nodejs, but when publishing a package such as pico-tester, I must be compatible with as many ways as possible, in which nodejs can be used. So first there is terminology to get right (esm, cjs, ...) and than provide the right type of package or packaging so it can be used there. I might update this over time with more learnings.
Continue reading →

#javascript

Tests using process.cpuUsage and process.memoryUsage

Learning stuff about nodejs (or v8) while writing tests that ensure runtime behaviour, using process.cpuUsage and process.memoryUsage. Curious how brittle those tests become over time. Glad the app ALWAYS runs in the same docker container (dev and prod).
Continue reading →

#javascript

Mocha's Magic done Parameter

Why a #mocha #test times out, when I write it like this: it('...', _ => {}); but it does NOT time out, when I write: it('...', () => {});? Exactly, because the _ is the magic done, that one needs to call.
Continue reading →