lorenzofox3 / zora

Lightest, yet Fastest Javascript test runner for nodejs and browsers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to use zora with Deno?

andreswebs opened this issue · comments

Doing an

import { test } from "https://raw.githubusercontent.com/lorenzofox3/zora/master/src/index.ts"

gives this error:

Download https://raw.githubusercontent.com/lorenzofox3/zora/master/src/reporter
Download https://raw.githubusercontent.com/lorenzofox3/zora/master/src/interfaces
Download https://raw.githubusercontent.com/lorenzofox3/zora/master/src/harness
Download https://raw.githubusercontent.com/lorenzofox3/zora/master/src/assertion
error: Import 'https://raw.githubusercontent.com/lorenzofox3/zora/master/src/reporter' failed: 404 Not Found
    at https://raw.githubusercontent.com/lorenzofox3/zora/master/src/index.ts:2:0

Hello.

To be honest I don't know: https://raw.githubusercontent.com/lorenzofox3/zora/master/src/reporter.ts exists, so it might be a bug in Deno's loader.

Maybe you can try by using this bundle file URL.

Perhaps @bdchauvette can help you. He is the only Deno's user I am aware of

You have to use the bundle URL and you won't be able to use any TS interfaces because the declarations use node-style path imports. Here's a minimal example.

The reason you have to use the bundle is that it's pretty much impossible to write TS sources that are compatible with both Deno and tsc. The issue is that Deno requires you to include .ts in the import path but the tsc itself does not allow you to import files ending with .ts (see e.g. microsoft/TypeScript#37582). As a result, you can either write TS sources that work with Deno or TS sources that work with tsc, but not both.

The reason the declarations don't work is again related to Deno's requirement that imports need to match the exact file name. The Zora typings are not bundled and they use Node-style extensionless paths. So even if you add a // @deno-types annotation (see below), it will fail when trying to import the other type files:

// @deno-types="https://unpkg.com/zora@4.0.1/dist/declarations/index.d.ts"
import { test } from 'https://unpkg.com/zora@4.0.1/dist/bundle/module.js';

In my case, I'm writing a cross-runtime lib, so I'm writing the tests with Node-style imports, then bundling everything together (with some changes based on target runtime) into tmp files, then running Node, Deno, QuickJS, etc. against the temp files. The only runtime support that I was missing from Zora was the ability to read env vars from the Deno object like it does with process in Node (#73).

If you're only supporting Deno, you should probably use Deno's builtin test framework or something like Rhum that targets Deno exclusively.


@lorenzofox3 -- Sorry for adding some maintenance overhead here 😓

I'm actually probably going to end up writing my own testing framework (no issue with Zora, I just prefer Mocha/Jest bdd-style structure for tests), so it might be simpler to revert #73 to avoid any confusion about Deno support 😬

Thanks for your thorough feedback @bdchauvette 👍 I'll close this one for now