coderaiser / supertape Goto Github PK
View Code? Open in Web Editor NEW๐ผ Simplest high speed testing
License: MIT License
๐ผ Simplest high speed testing
License: MIT License
In #3, you mentioned that the --require
flag could be used for JIT transpilation:
How does the --require flag work? Tape says that it can be used for JIT compilation - does this mean that the supertape CLI could support TypeScript through a required module?
Yes [this could work]
A quick Google search brought me to this article about using tape
with TypeScript by requiring ts-node/register/transpile-only
(effectively, a module that transpiles TS without type checking). However, trying
$ supertape -r ts-node/register/transpile-only test.ts
Fails with an error message about the .ts
extension:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for test.ts
Looking into tape
's implementation for --require
, it has an import-or-require.js
script:
function importOrRequire(file) {
const ext = extnamePath(file);
if (ext === '.mjs' || (ext === '.js' && getPackageType.sync(file) === 'module'))
return import(pathToFileURL(file).href);
require(file);
};
Compared to Supertape
's simple-import.js
, which simply uses a dynamic import:
I've tested out a simple copy and paste implementation and can successfully run a TypeScript test:
// lib/cli.js
// in function 'cli'
for (const file of files) {
const resolved = resolvePath(cwd, file);
promises.push(importOrRequire(resolved));
}
// test.ts
import test from "supertape";
test("test: from ts-node", async t => {
t.pass("using 'supertape' binary");
t.end();
});
$ supertape -r ts-node/register/transpile-only test.ts
TAP version 13
1..1
# tests 1
# pass 1
# โ
ok
What do you think about implementing something like this?
The problem seems to only happen with --format tap
or --format short
.
supertape version 9.5.0:
$ supertape --no-check-assertions-count --format tap test/test.js
TAP version 13
# migrate: migration works
ok 1 it did not throw an error
# migrate: migration works the second time
ok 2 it did not throw an error
# orm: select: get works
ok 3 should equal
supertape version 10.0.0 and 10.2.0:
$ supertape --no-check-assertions-count --format tap test/test.js
# migrate: migration works
# migrate: migration works the second time
# orm: select: get works
I expected the output to have lines starting with ok
.
I'm not very familiar with testing in the JS ecosystem, and while setting up a new project I found that I could use Tape to test with:
ts-node node_modules/tape/bin/tape tests/**/*.ts
I like the features of Supertape, but I can't seem to get it to run my tests. I've tried both ts-node
and esno
/esmo
, but I only get a "Done in 0.XXs" output without showing the testing results. Is there something I'm doing wrong, or is this use case not viable?
(Thank you very much for making supertape, it's the only testing library that matches how my brain works!)
I'm having a problem where supertape is stopping execution before my tests start running. In my test file, I want to do some slow setup (download some files to use in the tests) before the tests execute. But supertape stops it early before it can finish the setup.
From digging into the code, it seems this is because supertape expects one test()
to be called in the test file straight away, and then loops every 5 ms until new test()
s stop being added. Then it runs all of those tests.
So my test file basically looks like this:
const {test} = require("supertape")
const fetch = require("node-fetch")
const file = await fetch("some url").then(res => res.buffer()) // supertape stops trying to detect tests and stops the tests while this is downloading
test("process: I can process the file", () => {
t.equal(processFile(file), "expected result")
})
I'd love it if supertape would let me do some setup before I do the tests. I can think of three ways to do this:
test()
rather than ending it earlysetup(async () => { ... })
function that I can put my setup code in, and supertape will wait for setup
before detecting testsgo()
function that I call once I've finished my setupDo you have any advice on what I can do to make my use case work, or would I have to figure out a different way of doing it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.