Programmatic interface for the runner
moltar opened this issue · 6 comments
Is there a programmatic interface for the runner?
Use case is to bundle the test file using esbuild for a self-sufficient remote execution (lambda).
Thank you.
Hey @moltar! Thanks for the issue.
Could you tell us more about the use case? earljs
doesn't ship its own test runner.
-
You can use Mocha with
new Mocha({})
to create a test runner. -
You can even use
earljs
without a test runner. It might be the approach you choose if code size matters (like with lambdas).
Here's the article describing the exact use case I am after: https://thebenforce.com/post/cdk-integration-testing
In essence, the tests run remotely, within the infrastructure (inside a bundled Lambda function).
Lambda code is bundled by esbuild into a single file and is executed like a normal Lambda function via a handler method.
Example:
const testRunner = async () => {
// earljs tests would run here
// what does this implementation look like?
}
// Lambda handler (implementation detail)
const handler = async (event, context) => {
await testRunner()
}
Thanks!
Hey @moltar, I've made a tiny repo for you here: https://github.com/hasparus/earl-example-programmatic-uvu-usage
This is TLDR version:
import { test } from "uvu";
async function runTests(): Promise<void> {
// esbuild-plugin-import-glob doesn't seem to work for me, so you basically
// list all test files here manually.
await import("./addition.test");
await import("./subtraction.test");
// with webpack, you could use require.context() for this
test.run();
}
Ah, thank you so much. I get it now.
For some reason, I was confused about the role of earl
. It is only an assertion library and does not come with a runner. This is clearly stated in the docs, but of course, who reads those? 🙈
And then you said:
earljs doesn't ship its own test runner.
And I still missed it haha.
Anyhow. I get it now. Thank you for your time and the example. I will try it out.
Have you tested earl
with different runners? Any specific ones you like or don't like? Any ones that it integrates well with?
Cheers!
Have you tested earl with different runners? Any specific ones you like or don't like? Any ones that it integrates well with?
We’re using Mocha in deth projects, but uvu
looks really neat too (I learned about it from your link. Thanks!)
Vitest also looks quite interesting. I’m considering using it instead of Mocha + esbuild-register
setup in my next Vite project.
And I still missed it haha.
Anyhow. I get it now. Thank you for your time and the example. I will try it out.
No worries, mate. Happens to all of us. Merry Christmas 🎄