Code Monkey home page Code Monkey logo

oletus's People

Contributors

avaq avatar bearror avatar conaclos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

rodjjo avaq conaclos

oletus's Issues

Tests that never settle are treated as non-existent

Hi @bearror !

I'm still a very active and happy user of the project, and as such have recently run into a subtle yet problematic issue.

How to reproduce

Run oletus as normal with a test/whatever.mjs file:

import test from 'oletus'
test ('test', () => new Promise (() => {}));

Expected result

Some error about the test timing out, or even just a hanging process.

Actual result

 0 passed  0 failed  in 0.046s

Background

This problem has bitten me in a sense that I thought I had all my use-cases covered and my code had no bugs. However, some tests were simply being ignored because I did have an issue in my code that made it so the Promise never settled.

Custom error presentation logic messes with the behaviour of my code

I'm opening this issue to discuss a matter that doesn't have a straight-forward enough solution for a PR.

My code uses the .stack property in Error instances. Overriding Error.prepareStackTrace before running a test, as done in the snippet below, means that while I'm testing this functionality, my code behaves differently from how it should.

Error.prepareStackTrace = (e, stack) => stack

I have attempted to fix this issue without success, by moving the location where prepareStackTrace is overridden closer to where .stack is accessed by Oletus:

https://github.com/Avaq/oletus/blob/309e79c0e19b2a949aedc4d26aeb89fc8f19744d/oletus.mjs#L18-L21

Yet I realize that even if I were successful, there is another issue with Oletus' approach to formatting errors, and that is that it assumes that all assertions are made directly at the testing location, and thus that only the first stack trace entry is relevant to the user.

For me, this is not the case. I have abstracted over assertions, and therefore Oletus shows me the same location for every failing assertion. It might therefore be worth considering the removal of the custom error formatting logic altogether, and just presenting the user with the default e.stack as a message.

If you do just present e.stack, then a user can always modify the output from that by overriding Error.prepareStackTrace themselves.

Incorrect reported location

Reported paths of failing tests are Incorrect: they start with '/'. This prevents IDE to jump to the file from an embedded terminal.

Improve stacktrace

Hi!

I have often difficulties to locate which assertion fails in my unit tests. Let's just take an example to illustrate this.

Usually my unit tests have several assertions, such as:

import test from "oletus"
test("example", t => {
    t.ok(true)
    t.ok(false)
})

The reported location is a bit evasive:

$ oletus test.js
x error
test.js:2

We don't know whether it is the first or the second assertion that failed. It could be nice to get the line where the assertion failed:

$ oletus test.js
x error
test.js:4

However I don't see how to get this location in a reliable way. Indeed: we do not know which assertion library is used and which test pattern are used. The current approach (reporting the test location) seems more reliable.

A possible approach could be to report a reliable location (the location currently reported) and an unreliable location:

$ oletus test.js
x example
test.js:2
test.js:4

However, I am not convinced by this. Have you some thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.