question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve Programmatic Usage

See original GitHub issue

What I did

I’ve got a bunch of tests that I want to run in a specific order, e.g. “create the user” -> “log in as user” -> “log out as user” (where each of those has a bunch of tests).

Each of those tests is in its own file, then I created a test runner so I can manage state easier.

The test files all export a default function that takes test (the suite) and assert (for convenience):

// tests/*.js
export default (test, assert) => {
	test('example test', () => {
		assert.is(true, true);
	});
}

The custom test runner sets up state, and manually controls the suite ordering:

// runner.js
import { exec, suite } from 'uvu'
import * as assert from 'uvu/assert'

const scenarios = [
	'tests/aaa.js',
	'tests/ccc.js',
	'tests/bbb.js'
]

const run = async () => {
	for (const scenario of scenarios) {
		const test = suite(scenario)
		const run = await import(scenario)
		run.default(test, assert)
		test.run()
	}
	return exec()
}

run()
	.then(() => { console.log('done') })
	.catch(error => { console.error('error', error) })

Then I execute the runner simply node ./runner.js

What I expect

When I execute the runner, normal uvu output should list each suite:

$ node ./runner.js

 tests/aaa.js  •   (1 / 1)
 tests/ccc.js  •   (1 / 1)
 tests/bbb.js  •   (1 / 1)

  Total:     3
  Passed:    3
  Skipped:   0
  Duration:  0.29ms

What actually happens

If I try reordering the tests, they are all run in order, except always the first one is skipped and prints this instead:

$ node ./runner.js

function () { [native code] }
 tests/ccc.js  •   (1 / 1)
 tests/bbb.js  •   (1 / 1)

  Total:     2
  Passed:    2
  Skipped:   0
  Duration:  0.29ms

Other information

$  node -v
v16.0.0

$  npm -v
7.12.1

$  hostinfo 
Mach kernel version:
	 Darwin Kernel Version 20.4.0: Fri Mar  5 01:14:02 PST 2021; root:xnu-7195.101.1~3/RELEASE_ARM64_T8101

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

29reactions
lukeedcommented, Aug 12, 2021

Just an update:

I’m working on this now, which is effectively a rewrite of uvu. It will allow you to call a new run() export which will provide a JSON report of the results. I don’t have anything concrete yet (I started on this last night) but it will touch on multiple open issues: #14, #38, #52, #60, #80, #130

3reactions
saibotsivadcommented, May 14, 2021

Just a note to myself / whoever else stumbles across this: if you don’t bail (i.e. uvu.exec(true)) then the way to get the exit status code is using process.exitCode afterward, e.g.:

const run = async () => {
  // ... any of the forms @lukeed wrote
  return uvu.exec()
}
// ... where you call `run`
await run()
// after the promise resolves
if (process.exitCode) {
  // one or more tests failed
} else {
  // all tests passed
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How a Programmatic Ad Campaign is Optimized - Strategus
The flexibility of programmatic ads creates customized goals and establishes waypoints to understand how the campaign works — measuring visits to a landing...
Read more >
Top 5 Programmatic Advertising Best Practices for Better ...
#1: Use audience targeting to reach high-value audiences and exclude non-performing audiences to buy media smarter. Strong audience targeting is one of the...
Read more >
5 Tips to Drive Programmatic Success - Quantcast
1. Set goals and measurements. Think about KPIs and metrics that make sense for what you're trying to achieve with programmatic advertising. ·...
Read more >
5 ways to improve your programmatic media buying
1. Have the hygiene factors in place before and during the campaign · 2. Use log-level data and cloud services for the right...
Read more >
How to Get the Most Out of Programmatic Display Campaigns
Here's a dirty little secret of programmatic advertising: ad impressions don't always equal ad views. Since programmatic campaigns typically use a cost per ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found