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

feat(api): startVitest() to accept stdout and stdin #5493

Merged
merged 4 commits into from
Apr 23, 2024

Conversation

AriPerkkio
Copy link
Member

@AriPerkkio AriPerkkio commented Apr 5, 2024

Description

Adds new options to startVitest() so that stdout and stdin can be handled without overriding globals.

import { ReadStream } from "node:tty";
import { Writable } from "node:stream";
import { Console } from "node:console";
import { startVitest } from "vitest/node";

const stdin = new ReadStream(0);
const stdout = new Writable({
  write(chunk, _encoding, callback) {
    console.log("Captured", chunk.toString())
    callback();
  },
});

await startVitest(
  "test",
  [],
  { watch: true },
  undefined,
  { stdin, stdout }
);


// Re-run all tests
stdin.emit("data", "a");

// ... wait for tests to finish etc.

// Quit watch mode
stdin.emit("data", "q");

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Apr 5, 2024

Deploy Preview for fastidious-cascaron-4ded94 ready!

Name Link
🔨 Latest commit 093f0bd
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/661be1a9ab73870008852d26
😎 Deploy Preview https://deploy-preview-5493--fastidious-cascaron-4ded94.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@AriPerkkio AriPerkkio force-pushed the feat/logger-option branch 6 times, most recently from 20839b2 to 754dc39 Compare April 7, 2024 13:27
Comment on lines +67 to +68
// TODO: Why should this be picked as well?
// expect(stderr).toContain('FAIL only.test-d.ts') // .only
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this started to fail now. The only.test-d.ts is not defined in the custom TS config.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember 🤔

@AriPerkkio AriPerkkio force-pushed the feat/logger-option branch from 6d65e44 to 7fd7a95 Compare April 9, 2024 15:49
@AriPerkkio AriPerkkio marked this pull request as ready for review April 14, 2024 14:21
@sheremet-va sheremet-va changed the title feat: startVitest() to accept stdout and stdin feat(api): startVitest() to accept stdout and stdin Apr 22, 2024
@sheremet-va
Copy link
Member

sheremet-va commented Apr 23, 2024

Let's merge this as a patch since it modifies the public API which is not affected by the semver.

@sheremet-va sheremet-va merged commit 780b187 into vitest-dev:main Apr 23, 2024
18 of 19 checks passed
@AriPerkkio AriPerkkio deleted the feat/logger-option branch April 23, 2024 14:04
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

Successfully merging this pull request may close these issues.

2 participants