@@ -244,7 +244,11 @@ function start(filters?: string[]): Promise<TestRunResult>
244244function standalone(): Promise<void>
245245` ` `
246246
247+ <<<<<< < HEAD
247248- ** 别名:** : ` init ` < Deprecated / >
249+ ====== =
250+ - ** Alias :** ` init ` < Deprecated / >
251+ >>>>>> > ec964f36ce7596a023a32b8265f6019c51b32926
248252
249253初始化报告器和覆盖率提供者。此方法不运行任何测试。如果提供了 ` --watch ` 标志,Vitest 仍将运行更改的测试,即使未调用此方法。
250254
@@ -696,3 +700,122 @@ export interface SourceModuleDiagnostic {
696700::: warning
697701[浏览器模式](/ guide / browser / ) 暂不支持。
698702:::
703+
704+ ## createReport < Version > 5.0 .0 < / Version > {#createreport }
705+
706+ ` ` ` ts
707+ function createReport(scope: string): Report
708+ ` ` `
709+
710+ Creates a report that is limited to the given scope . ` Report ` follows Vitest ' s rules around [Storing artifacts on file system](/guide/advanced/reporters.html#storing-artifacts-on-file-system).
711+
712+ ` Report ` provides collection of utilities for writing test results , temporary files and other artifacts on the file system . It ' s especially intended for third party integrations like custom reporters.
713+
714+ All operations of ` Report ` are limited to given ` scope ` . A single report cannot interfere with other reports . Internally Vitest creates ` .vitest ` directory where each ` scope ` creates their own directory . This convention of ` .vitest ` directory reduces the amount of entries end - users need to specify in their ` .gitignore ` .
715+
716+ ` ` ` ts
717+ import type { Report } from 'vitest/node'
718+
719+ const scope = 'example-yaml-reporter'
720+
721+ // Automatically creates ` < project - root > / .vitest / example - yaml - reporter / `
722+ // directory if it does not exist already
723+ const report: Report = vitest.createReport(scope)
724+ ` ` `
725+
726+ ### Report .root
727+
728+ ` ` ` ts
729+ const root: string
730+ ` ` `
731+
732+ The root directory for this scope .
733+
734+ ` ` ` ts
735+ const report = vitest.createReport('my-json-reporter')
736+
737+ // Is <project-root>/.vitest/my-json-reporter
738+ const root = report.root
739+ ` ` `
740+
741+
742+ ### Report .clean
743+
744+ ` ` ` ts
745+ function clean(): Promise<void>
746+ ` ` `
747+
748+ Clean up the report directory for this scope .
749+
750+ ` ` ` ts
751+ const report = vitest.createReport('my-json-reporter')
752+
753+ // Removes everything inside <project-root>/.vitest/my-json-reporter/
754+ await report.clean()
755+ ` ` `
756+
757+ ### Report .writeFile
758+
759+ ` ` ` ts
760+ function writeFile(
761+ filename: string,
762+ content: string | Uint8Array,
763+ encoding?: BufferEncoding
764+ ): Promise<void>
765+ ` ` `
766+
767+ Write a file to the report directory for this scope . By default the file will be written with UTF - 8 encoding . The filename is relative to the scope directory .
768+
769+ ` ` ` ts
770+ const report = vitest.createReport('my-json-reporter')
771+
772+ // Writes file to .vitest/my-json-reporter/test-report.json
773+ await report.writeFile('test-report.json', JSON.stringify(results))
774+ ` ` `
775+
776+ ### Report .readFile
777+
778+ ` ` ` ts
779+ function readFile(filename: string, encoding?: BufferEncoding): Promise<string>
780+ ` ` `
781+
782+ Read a file from the report directory for this scope .
783+
784+ ` ` ` ts
785+ const report = vitest.createReport('my-json-reporter')
786+
787+ // Reads file from .vitest/my-json-reporter/test-report.json
788+ const content: string = await report.readFile('test-report.json')
789+ ` ` `
790+
791+ ### Report .readdir
792+
793+ ` ` ` ts
794+ function readdir(): Promise<string[]>
795+ ` ` `
796+
797+ Read contents of the report directory for this scope .
798+
799+ ` ` ` ts
800+ const report = vitest.createReport('my-json-reporter')
801+
802+ // Reads contents from .vitest/my-json-reporter
803+ const filenames: string[] = await report.readdir()
804+ ` ` `
805+
806+ ### Report .delete
807+
808+ < ! -- eslint - skip -- >
809+ ` ` ` ts
810+ function delete(filename: string): Promise<void>
811+ ` ` `
812+
813+ Delete a file from the report directory for this scope .
814+
815+ ` ` ` ts
816+ const report = vitest.createReport('my-json-reporter')
817+
818+ // Deletes file from .vitest/my-json-reporter/test-report.json
819+ await report.delete('test-report.json')
820+ ` ` `
821+
0 commit comments