typescript-runtime-type-benchmarks icon indicating copy to clipboard operation
typescript-runtime-type-benchmarks copied to clipboard

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

Open jeengbe opened this issue 2 years ago • 5 comments

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)

jeengbe avatar Nov 14 '22 17:11 jeengbe

@hoeck Do you have any input on this?

moltar avatar Nov 15 '22 14:11 moltar

@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.

hoeck avatar Nov 15 '22 15:11 hoeck

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

jeengbe avatar Nov 15 '22 15:11 jeengbe

:+1: 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 avatar Nov 15 '22 15:11 hoeck

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.

hoeck avatar Nov 15 '22 15:11 hoeck