Would you consider recommending Deno as an alternative for running tests in the Typescript track?

Hi Everyone,

Yesterday I posted this thread:

And promptly received some valuable assistance which helped me reduce the download and wait times for running yarn install prior to running tests on an exercise from:

229.42 seconds and 180 MB per exercise (node_modules folder)
to
~100 seconds and 45.5 MB per exercise (.yarn folder)

Now I don’t claim to have set up my development environment properly, and I’m not sure it’s typical to be encountering this much repetitive downloads when running yarn install, but I did find a way to run the provided tests which doesn’t require any per exercise installations.

I’ve summarized the method below. Based on the results, would Exercism be interested in suggesting Deno as an alternative to or replacement to Yarn / Node for the Typescript track?

Summary

The method uses a quick and dirty Python script to convert the provided tests intended for the jest test runner to be run with deno test.

The script is included below. I’ve only tested it on 14 out of the 95 Typescript exercises. I doubt it’s perfect, but it seems to work.

import sys

bddImports = 'describe, it'
beforeEach = False
afterEach = False

with open(sys.argv[1]) as file:
	data = file.readlines()

data[0] = data[0][:-2] + ".ts" + data[0][-2:]
data.insert(2,"import { expect } from 'https://deno.land/x/expect@v0.3.0/mod.ts'\n\n")
for i, line in enumerate(data):
    if line.startswith('  xit('):
        data[i] = line.replace('xit(','it(')
        continue
    if line.startswith('  it.skip('):
        data[i] = line.replace('it.skip(','it.ignore(')
        continue
    if line.startswith('  beforeEach('):
        beforeEach = True
        continue
    if line.startswith('  afterEach('):
        afterEach = True

if beforeEach:
    bddImports += ', beforeEach'

if afterEach:
    bddImports += ', afterEach'

data.insert(1,"import { " + bddImports + " } from 'https://deno.land/std@0.177.0/testing/bdd.ts'")

with open(sys.argv[1], 'w') as file:
    file.writelines(data) 

Here are the steps for your consideration:

  1. Install the Deno runtime (Installation | Deno Docs)
  2. Download an exercise from the Typescript track
  3. Run the above python script with the exercise’s test file as an argument
    e.g. lets say I saved the above python file as denoifyTest.py, and I downloaded the Matrix exercise. I could then run: py denoifyTest.py ./matrix/matrix.test.ts
  4. You are now ready to use Deno test to run the tests in that directory without running yarn install

For anyone curious, It’s important to note Deno is a different runtime to Node, and you should be both mindful about what separates the two and intentional about moving forward with an alternative. its approach to external dependencies is why the above results in no subsequent per exercise dependency downloads.

Bonus suggestion: Those using VS Code and following the above advice should strongly consider installing and enabling the Deno extension if they’re going to install and use the Deno runtime. You’ll get some red underlining and mentions in your Problem section if you use the above advice but skip this step.

2 Likes

deno installs the packages, it just does it automatically. The technique is very similar to PnP but it’s not not downloading them. It just defaults to use the cache without checking.

Whilst I really like deno myself, it’s 250k monthly users against > 3 million for node, and its relatively youn age also make it not a good fit to teach “TypeScript” in, because the vast majority of online content to learn TypeScript will be targeting node. This may not seem significant, but a lot of frameworks don’t run on deno. On top of that, the standard library isn’t stable (yet) and thus I don’t really want to support it officially.

I am therefore not keen to recommend running the TypeScript track on deno, but I am happy to include some information about it in the installation doc, should you provide a PR.