Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird behavior when running watch mode via yarn with async global teardown hooks #4582

Closed
4 tasks done
jedwards1211 opened this issue Feb 24, 2021 · 1 comment
Closed
4 tasks done

Comments

@jedwards1211
Copy link

jedwards1211 commented Feb 24, 2021

Prerequisites

  • Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

Watch mode with async global teardown hooks doesn't work properly when run via yarn. It could very well be yarn's fault, but I haven't seen weird behavior like this with any other scripts that do tricky child process spawning...

Steps to Reproduce

Repo: https://github.com/jedwards1211/yarn-mocha-watch

package.json

{
  "name": "yarn-mocha-watch",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "test:watch": "mocha -r teardown.js test.js --watch"
  },
  "devDependencies": {
    "mocha": "^8.3.0"
  }
}

teardown.js

exports.mochaGlobalTeardown = async () => {
  await new Promise((resolve) => setTimeout(resolve, 1000))
}

test.js

describe('test setup', () => {
  it('works', () => {})
})

Expected behavior: [What you expect to happen]

When I run npm run test:watch, and then Ctrl-C, I see the following:

^C⚠ [mocha] cleaning up, please wait...
⚠ [mocha] cleaning up, please wait...
((( 1 second pause )))
npm ERR! code ELIFECYCLE
npm ERR! errno 130
...

I would expect at least a 1 second pause before exit with yarn as well, but for some reason it doesn't.

Actual behavior: [What actually happens]

When I run yarn test:watch, it exits almost immediately after I Ctrl-C, sometimes even printing ⚠ [mocha] cleaning up, please wait... after the next command prompt.

Additionally, if I press the up key after I Ctrl-C:

  • If less than one second has elapsed, I get this strange error:
    node_modules/mocha/lib/runner.js:962
        throw err;
        ^
    
    Error: read EIO
        at TTY.onStreamRead (internal/stream_base_commons.js:205:27)
    Emitted 'error' event on ReadStream instance at:
        at emitErrorNT (internal/streams/destroy.js:92:8)
        at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
        at processTicksAndRejections (internal/process/task_queues.js:84:21) {
      errno: 'EIO',
      code: 'EIO',
      syscall: 'read'
    }
    
  • If more than one second has elapsed, it prints ^[[A instead of the previous command (even though pressing enter will still run the previous command)

Reproduces how often: [What percentage of the time does it reproduce?]

Consistently

Versions

  • The output of mocha --version and node node_modules/.bin/mocha --version: 8.3.0
  • The output of node --version: 14.11.0, doesn't seem to matter
  • Your operating system
    • name and version: macOS 11.2.1
    • architecture (32 or 64-bit): 64-bit
  • Your shell (e.g., bash, zsh, PowerShell, cmd): bash
@jedwards1211
Copy link
Author

Okay nevermind, this is definitely a yarn issue: yarnpkg/yarn#4667

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant