MithrilJS / ospec

Noiseless testing framework
MIT License
48 stars 13 forks source link

fix: Always explicitly exit() to avoid hangs #51

Closed maranomynet closed 1 year ago

maranomynet commented 1 year ago

Description

Fixes this problem:

import o from 'ospec';

o.spec('This dangling setInterval', () => {
  setInterval(() => undefined, 100);

  o('causes ospec to hang', () => {
    o(true).equals(true);
  });
});

Motivation and Context

Tests that import code from 3rd party libraries can cause ospec to unexpectedly hang, even though your own code and tests are perfectly fine.

How Has This Been Tested?

By pasting the above code into a file called hangtest.mjs and running ospec hangtest.mjs.

Without the fix the process doesn't exit.

With the fix it exits like normal.

Types of changes

Checklist:

BTW: I Can't get the package tests to pass locally (MacOS 12.5) — not even on the untouched main branch:

git clone git@github.com:MithrilJS/ospec.git
cd ospec
git checkout main  # Already on 'main'
yarn install
yarn run test
# 30 out of 4024 assertions failed
yarn run self-test
# 30 out of 4024 assertions failed
maranomynet commented 1 year ago

yarn patch ospec is currently saving my a**. 😅

maranomynet commented 1 year ago

Any comments @pygy ?

pygy commented 1 year ago

That sounds good, could you push a dummy commit to re-launch CI? The logs have expired, and I can't find how to relaunch these jobs (neither can I relaunch old Mithril jobs, so it could be an expiration thing here too).

maranomynet commented 1 year ago

Pushed a trivial fix to the README, for luck.

pygy commented 1 year ago

Merging, I'll publish a new version this evening and investigate where pnpm fails.

pygy commented 1 year ago

Many thanks for raising the issue and providing a patch.

pygy commented 1 year ago

@maranomynet @v4.1.7 is out

maranomynet commented 1 year ago

Thank you.