nodejs / nodejs/node

The assertion module should signals failures through messages to the test runner

Aperta
#52,033 12 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

assert feature request test_runner
Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

What is the problem this feature will solve?

The assertion module signals failures via exceptions. This may causes some subtle issues during program testing, since the "exception channel" is also used by the program under test which may catch the exceptions generated by failing assertions resulting in weird test behavior.

import {test} from "node:test";
import assert from "node:assert";

function function_under_test(callback, value) {
    let r = 0;
    try {
        r = callback(value);
    } catch (error) {
       //log error...
    }
    //continue executing operations...
}

test("weird test supposed to fail, but it doesn't", function () {
    function_under_test(function (v) {
        assert.fail("BOOM!");
    }, 4);
});

test passes...

What is the feature you are proposing to solve the problem?

When in a test runner context provide the assertion module via the testContext object:

import {test} from "node:test";
import assert from "node:assert";

function function_under_test(callback, value) {
    let r = 0;
    try {
        r = callback(value);
    } catch (error) {
       //log error...
    }
    //continue executing operations...
}

test("weird test", function (testContext) {
    function_under_test(function (v) {
        testContext.assert.fail("BOOM!");
    }, 4);
});

and signal the failures via messages between testContext and assert methods.

What alternatives have you considered?

No response

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia leggendo l'API testContext di node:test e il modulo node:assert, quindi esamina come gli errori delle asserzioni raggiungono il test runner. Definisci l'interfaccia delle asserzioni del contesto di test e verifica che gli errori non possano essere intercettati dal codice sottoposto a test, mentre il runner continua a segnalarli.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript
Ambito
testing
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
32/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.