테스트 어노테이션
Vitest는 context.annotate
API를 통해 사용자 지정 메시지 및 파일을 테스트에 첨부할 수 있도록 지원합니다. 이러한 어노테이션은 테스트 케이스에 연결되어 onTestAnnotate
훅을 통해 리포터로 전달됩니다.
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
annotate
함수는 Promise를 반환하므로, 해당 결과에 의존하는 경우 await
해야 합니다. 그러나 Vitest는 테스트가 완료되기 전에 await
되지 않은 모든 어노테이션을 자동으로 await
합니다.
리포터의 종류에 따라 이러한 어노테이션은 다르게 표시됩니다.
내장 리포터
default
default
리포터는 테스트가 실패한 경우에만 어노테이션을 출력합니다.
⎯⎯⎯⎯⎯⎯⎯ 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
TTY 터미널에서 verbose
리포터는 default
리포터와 유사하게 작동합니다. 그러나 비 TTY 환경에서는 verbose
리포터가 각 테스트가 끝난 후에도 어노테이션을 출력합니다.
✓ 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
HTML 리포터는 UI와 동일한 방식으로 어노테이션을 표시합니다. 어노테이션이 호출된 위치에서 확인할 수 있습니다. 현재로서는 어노테이션이 테스트 파일 내에서 호출되지 않으면 UI에서 볼 수 없습니다. 어노테이션을 확인할 수 있는 별도의 테스트 요약 화면을 지원할 계획입니다.


junit
junit
리포터는 테스트 케이스의 properties
태그 내에 어노테이션을 나열합니다. JUnit 리포터는 모든 첨부 파일은 무시하고 유형과 메시지만 출력합니다.
<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
github-actions
리포터는 기본적으로 어노테이션을 공지 메시지로 출력합니다. 두 번째 인자로 notice
, warning
, error
를 전달하여 유형을 지정할 수 있습니다. 유형이 이 중 어느 것도 아니라면, Vitest는 해당 메시지를 알림으로 표시합니다.


tap
tap
및 tap-flat
리포터는 #
기호로 시작하는 새 줄에 진단 정보로 어노테이션을 출력합니다. 모든 첨부 파일은 무시하고 유형과 메시지만 출력합니다.
ok 1 - an example of a test with annotation # time=143.15ms
# notice: the message of the annotation