Testy / TestyTs

✔️ Modern TypeScript testing framework.
http://testy.github.io
ISC License
123 stars 8 forks source link

The simplest object comparisons create a stack overflow #77

Closed Pointotech closed 3 years ago

Pointotech commented 3 years ago

For example:

@TestSuite()
export class MyTestSuite {
  @Test()
  onePlusOne() {
    // Act
    const result = {x: 2};

    // Assert
    expect.toBeEqual(result, {x: 2});
  }
}

This will fail, with a stack overflow, because the inputs to toBeEqual are objects and toBeEqual doesn't know how to handle objects.

When I try to follow the implementation of toBeEqual, I end up in some non-TypeScript hell of .d.ts files, instead of actual TypeScript code, which seems weird for a framework that advertises itself as using the "full power of TypeScript". Since there's no implementation code, I'm not sure what's wrong with the implementation or how I could make a pull request to try and fix it.

Aboisier commented 3 years ago

Hi! First of all, thanks for reporting this bug! This quite an embarrassing one, I'm surprised a test haven't caught this. I'll fix and release this as soon as possible. I believe I meant to call JSON.stringify instead of this.stringify.

private stringify(val: unknown) {
  return typeof val === 'object' ? this.stringify(val) : `${val}`;
}

Secondly, you should be able to see the implementation code right next to the expect.d.ts file, in the expect.js file. Reading the node module isn't usually a common or preferred method for investigating bugs. You can find the source code in this repository. I'd like to repatriate the code in this repository at some point, I just haven't taken the time to do it!

You stumbled upon "no-TypeScript hell" because, ultimately, TypeScript must be compiled to JavaScript, except if it's run in a TypeScript interpreter or execution engine such as ts-node. It wouldn't really make sense to give the burden of compiling the library to the user.

TestyTs actually runs tests using such a TypeScript execution engine, ts-node (which actually ultimately compiles the code to JavaScript just-in-time). The library itself, though, is published pre-compiled. I don't think there would be any value in publishing the library as TypeScript, it would just add compilation overhead to each test run. The "the full power of TypeScript" is the static typing, not... libraries published as plain code?

Finally, I'm not sure if this is the vibe you were going for, but your message sound quite passive agressive. Please be careful in the future.

Aboisier commented 3 years ago

I just released v1.4.0, which fixes this issue. Thanks for reporting again! :)