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

Verbose API results #75

Open
wants to merge 50 commits into
base: main
Choose a base branch
from

Conversation

smartclash
Copy link
Contributor

@smartclash smartclash commented Aug 13, 2020

This PR is dependent on #74

TSD either returns a null array if there is no test failures or an array of Diagnostic objects. This PR aims to make TSD return with ExtendedDiagnostic object no matter if the tests fail or not.

Merging this PR allows custom test runners like Jest to report the number of assertions it evaluated in each file.

It also means that it introduces a breaking change because TSD now returns...

  • An object with numTests and null diagnostics array if all tests passed.
{
    numTests: 1024, // Total number of tests it ran through
    diagnostics: [] // No failed test cases
}
  • An object with numTests and an diagnostics array populated with test fail reports if a test is failed.
{
    numTests: 1024, // Total number of tests it ran through
    diagnostics: [
        {
            fileName: 'add.test-d.ts',
            message: 'A message here',
            severity: 'error',
            line: 10,
            column: 34,
        },
        ...
    ]
}


This PR is Co-Authored By:

Copy link
Contributor

@Ethan-Arrowood Ethan-Arrowood left a comment

Choose a reason for hiding this comment

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

this looks really good! nice work!

@sindresorhus sindresorhus changed the title Verbose reporting in TSD. Verbose API results Oct 3, 2020
@SimenB
Copy link

SimenB commented Dec 16, 2020

rebase this now that #74 has landed?

@SimenB
Copy link

SimenB commented Oct 5, 2021

Still very interested in seeing this land 😀

@tommy-mitchell tommy-mitchell mentioned this pull request Mar 6, 2023
@tommy-mitchell
Copy link
Contributor

tommy-mitchell commented Mar 13, 2023

Instead of making a breaking change, maybe tsd can just have verbose: boolean option?

const diagnostics = await tsd();
//=> Diagnostic[]

console.log(diagnostics.length);
//=> '0'
const verboseResults = await tsd({verbose: true});
//=> {testCount: number, diagnostics: Diagnostic[]}

console.log(verboseResults.testCount);
//=> '1024'

console.log(verboseResults.diagnostics.length);
//=> '0'

@sindresorhus
Copy link
Collaborator

I'm fine with this change. Having an object also gives us the opportunity to add additional properties in the future.

@sindresorhus
Copy link
Collaborator

Instead of making a breaking change, maybe tsd can just have verbose: boolean option?

I don't like options that change the return value type.

I think a breaking change is ok here. Programmatic use is not that common.

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.

6 participants