Skip to content
Vitest 3
Main Navigation Guida & APIConfigurazioneModalità BrowserAPI avanzata
3.2.0
2.1.9
1.6.1
0.34.6

Italiano

English
简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Polski
Türkçe
čeština
magyar

Italiano

English
简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Polski
Türkçe
čeština
magyar

Aspetto

Sidebar Navigation

Introduzione

Perché Vitest

Per Iniziare

Caratteristiche

Configurazione di Vitest

API

Riferimento API di test

Funzioni Mock

Vi

expect

expectTypeOf

assert

assertType

Guida

Interfaccia a Riga di Comando

Filtro dei Test

Progetti di Test

Reporter

Copertura

Snapshot

Mocking

Parallelismo

Tipi di Test

Vitest UI

Test nel Codice Sorgente

Contesto di Test

Annotazioni dei Test

Ambiente di Test

Estensione dei Matcher

Integrazioni IDE

Debugging

Errori Comuni

Guida alla Migrazione

Migrazione a Vitest 3.0

Migrazione da Jest

Prestazioni

Profilazione delle prestazioni dei test

Ottimizzare le Prestazioni

Modalità Browser

API Avanzate

Confronto con Altri Test Runner

In questa pagina

Annotazioni dei Test ​

Vitest supporta l'annotazione dei tuoi test con messaggi e file personalizzati tramite l'API context.annotate. Queste annotazioni saranno allegate al caso di test e trasmesse ai reporter tramite l'hook onTestAnnotate.

ts
test('hello world', async ({ annotate }) => {
  await annotate('this is my test');

  if (condition) {
    await annotate("this should've errored", 'error');
  }

  const file = createTestSpecificFile();
  await annotate('creates a file', { body: file });
});

WARNING

La funzione annotate restituisce una Promise, quindi deve essere attesa se si desidera gestirne il completamento. Tuttavia, Vitest attenderà automaticamente qualsiasi annotazione non ancora risolta prima che il test termini.

La visualizzazione di queste annotazioni varia a seconda del reporter utilizzato.

Reporter Integrati ​

default ​

Il reporter default stampa le annotazioni solo se il test è fallito:

  ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯

  FAIL  example.test.js > an example of a test with annotation
Error: thrown error
  ❯ example.test.js:11:21
      9 |    await annotate('annotation 1')
      10|    await annotate('annotation 2', 'warning')
      11|    throw new Error('thrown error')
        |          ^
      12|  })

  ❯ example.test.js:9:15 notice
    ↳ annotation 1
  ❯ example.test.js:10:15 warning
    ↳ annotation 2

  ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

verbose ​

In un terminale TTY, il reporter verbose funziona in modo simile al reporter default. Tuttavia, in un ambiente non-TTY, il reporter verbose stamperà le annotazioni anche dopo ogni test.

✓ example.test.js > an example of a test with annotation

  ❯ example.test.js:9:15 notice
    ↳ annotation 1
  ❯ example.test.js:10:15 warning
    ↳ annotation 2

html ​

Il reporter HTML mostra le annotazioni allo stesso modo dell'interfaccia utente. L'annotazione è visibile sulla riga in cui è stata chiamata. Attualmente, se l'annotazione non è stata richiamata all'interno di un file di test, non sarà visibile nell'interfaccia utente. È previsto il supporto per una vista di riepilogo dei test separata in cui sarà visibile.

Vitest UIVitest UI

junit ​

Il reporter junit elenca le annotazioni all'interno del tag properties del caso di test. Il reporter JUnit ignorerà tutti gli allegati e visualizzerà solo il tipo e il messaggio.

xml
<testcase classname="basic/example.test.js" name="an example of a test with annotation" time="0.14315">
    <properties>
        <property name="notice" value="the message of the annotation">
        </property>
    </properties>
</testcase>

github-actions ​

Il reporter github-actions visualizzerà l'annotazione come messaggio di notifica per impostazione predefinita. Puoi configurare il type specificando il secondo argomento come notice, warning o error. Se il tipo non corrisponde a nessuno di questi, Vitest visualizzerà il messaggio come una notifica.

GitHub ActionsGitHub Actions

tap ​

I reporter tap e tap-flat visualizzano le annotazioni come messaggi diagnostici su una nuova riga, preceduti dal simbolo #. Ignoreranno tutti gli allegati e visualizzeranno solo il tipo e il messaggio:

ok 1 - an example of a test with annotation # time=143.15ms
    # notice: the message of the annotation
Pager
Pagina precedenteContesto di Test
Pagina successivaAmbiente di Test

Rilasciato sotto la licenza MIT.

Copyright (c) 2021-Present Vitest Team

https://vitest.dev/guide/test-annotations

Rilasciato sotto la licenza MIT.

Copyright (c) 2021-Present Vitest Team