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:
- Install the Deno runtime (Installation | Deno Docs)
- Download an exercise from the Typescript track
- 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
- You are now ready to use
Deno test
to run the tests in that directory without runningyarn 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.