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

Context clonning error when creating custom reporter #614

Closed
vovsemenv opened this issue Jan 23, 2022 · 0 comments · Fixed by #630
Closed

Context clonning error when creating custom reporter #614

vovsemenv opened this issue Jan 23, 2022 · 0 comments · Fixed by #630

Comments

@vovsemenv
Copy link
Contributor

vovsemenv commented Jan 23, 2022

Describe the bug

I trying to create custom reporter.
I copy reporter template from basic JSON reporter. https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/node/reporters/json.ts

When i start tests with this simtle reporter i get error

(node:38) UnhandledPromiseRejectionWarning: TypeError: configureServer(_server) {
            server = _server;
        } could not be cloned.

in all DefaultReporter reporters this works just fine, but cause error in custom ones

onInit(ctx) {
   this.ctx = ctx;
}

My code

import { Reporter } from 'vitest';
import { Vitest } from 'vitest/node';

export class TestReporter implements Reporter {
  ctx!: Vitest;

  onInit(ctx) {
    this.ctx = ctx;
  }

  onFinished(files = this.ctx.state.getFiles()) {
    console.log(files);
  }
}

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-nej1kt?file=test-reporter.ts

System Info

System:
    OS: macOS 11.6.1
    CPU: (8) arm64 Apple M1
    Memory: 180.38 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.0/bin/yarn
    npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
  Browsers:
    Chrome: 97.0.4692.71
    Firefox: 96.0.2
    Safari: 15.2
  npmPackages:
    @vitejs/plugin-vue: ^2.0.1 => 2.1.0 
    @vitejs/plugin-vue-jsx: ^1.3.3 => 1.3.3 
    vite: ^2.7.13 => 2.7.13 
    vitest: ^0.2.0 => 0.2.0


### Used Package Manager

npm

### Validations

- [X] Follow our [Code of Conduct](https://github.com/vitest-dev/vitest/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guidelines](https://github.com/vitest-dev/vitest/blob/main/CONTRIBUTING.md).
- [X] Read the [docs](https://vitest.dev/guide).
- [X] Check that there isn't [already an issue](https://github.com/vitest-dev/vitest/issues) that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitest-dev/vitest/discussions) or join our [Discord Chat Server](https://chat.vitest.dev).
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant