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

How do I add a testcase (Request: Documentation on that) #1012

Open
jeengbe opened this issue Nov 14, 2022 · 5 comments
Open

How do I add a testcase (Request: Documentation on that) #1012

jeengbe opened this issue Nov 14, 2022 · 5 comments

Comments

@jeengbe
Copy link
Contributor

jeengbe commented Nov 14, 2022

addCase('vality', 'parseSafe', data => {
  const res = validate(dataType, data, { strict: true, bail: true });
  if(res.valid) return res.data;
  throw new Error("Invalid");
});

throws an exception on invalid which crashes the process.

Executing "vality"
Loading "vality"
/home/coder/data/typescript-runtime-type-benchmarks/cases/vality.ts:24
  throw new Error('Invalid!');
        ^
Error: Invalid!
    at ParseSafe.fn (/home/coder/data/typescript-runtime-type-benchmarks/cases/vality.ts:24:9)
    at ParseSafe.run (/home/coder/data/typescript-runtime-type-benchmarks/benchmarks/parseSafe.ts:29:10)
@moltar
Copy link
Owner

moltar commented Nov 15, 2022

@hoeck Do you have any input on this?

@hoeck
Copy link
Collaborator

hoeck commented Nov 15, 2022

@jeengbe have you tried running the tests with npm run test - what do they say?

If a benchmarked library does not implement the benchmark correctly (e.g. raises an exception if the data is valid) the benchmark will crash. The tests are meant to ensure that the benchmarked libraries do indeed conform to the benchmark spec.

@jeengbe
Copy link
Contributor Author

jeengbe commented Nov 15, 2022

Ah yes, I could debug it with jest.
That is something that should somewhat be documented 🙈

Along the lines of

parseSafe:

  • Allows unknown properties
  • Throws if invalid
  • Returns data if valid

assertStrict

  • Doesn't unknown properties
  • Throws if invalid
  • Returns true if valid

@hoeck
Copy link
Collaborator

hoeck commented Nov 15, 2022

👍 also at the bottom of the benchmark graph there is a short description what every benchmark is supposed to test: https://moltar.github.io/typescript-runtime-type-benchmarks/

@hoeck
Copy link
Collaborator

hoeck commented Nov 15, 2022

That is something that should somewhat be documented see_no_evil

I didn't expect so much feedback and new libraries so you're right, documentation is missing a bit.

If you could add a few hints / bullets to the readme on how to add a new library, that would be great.

Feel free to ask when something is not working or if you need some help.

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

3 participants