fix: make attachmentsDir root only config (#10334) · vitest-dev/vitest@fab1b60 (original) (raw)
1
1
`import type { TestArtifact } from '@vitest/runner'
`
2
2
`import type { TestAnnotation } from 'vitest'
`
``
3
`+
import { readdirSync } from 'node:fs'
`
``
4
`+
import path from 'node:path'
`
3
5
`import { playwright } from '@vitest/browser-playwright'
`
4
6
`import { describe, expect, test } from 'vitest'
`
5
7
`import { runInlineTests } from '../../test-utils'
`
`@@ -665,3 +667,52 @@ describe('reporters', () => {
`
665
667
`})
`
666
668
`})
`
667
669
`})
`
``
670
+
``
671
`+
test('attachmentsDir is root only', async () => {
`
``
672
`+
const result = await runInlineTests(
`
``
673
`+
{
`
``
674
`` +
'packages/client/basic.test.ts': `
``
``
675
`+
import { test } from 'vitest'
`
``
676
`+
test("hello", ({ annotate }) => {
`
``
677
`+
annotate("hello annotation", { path: "./hello.txt" })
`
``
678
`+
})
`
``
679
`` +
`,
``
``
680
`` +
'packages/client/hello.txt': HELLO,
``
``
681
`` +
'packages/server/basic.test.ts': `
``
``
682
`+
import { test } from 'vitest'
`
``
683
`+
test("world", ({ annotate }) => {
`
``
684
`+
annotate("world annotation", { path: "./world.txt" })
`
``
685
`+
})
`
``
686
`` +
`,
``
``
687
`` +
'packages/server/world.txt': WORLD,
``
``
688
`+
},
`
``
689
`+
{
`
``
690
`+
projects: ['./packages/*'],
`
``
691
`+
},
`
``
692
`+
)
`
``
693
`` +
expect(result.stderr).toMatchInlineSnapshot("")
``
``
694
`` +
expect(result.errorTree({ project: true })).toMatchInlineSnapshot(`
``
``
695
`+
{
`
``
696
`+
"client": {
`
``
697
`+
"basic.test.ts": {
`
``
698
`+
"hello": "passed",
`
``
699
`+
},
`
``
700
`+
},
`
``
701
`+
"server": {
`
``
702
`+
"basic.test.ts": {
`
``
703
`+
"world": "passed",
`
``
704
`+
},
`
``
705
`+
},
`
``
706
`+
}
`
``
707
`` +
`)
``
``
708
`+
const files = readdirSync(path.join(result.root, '.vitest/attachments'))
`
``
709
`+
const contents = files.sort().map(file =>
`
``
710
`+
result.fs.readFile(path.join('.vitest/attachments', file)),
`
``
711
`+
)
`
``
712
`` +
expect(contents).toMatchInlineSnapshot(`
``
``
713
`+
[
`
``
714
`+
"HELLO",
`
``
715
`+
"WORLD",
`
``
716
`+
]
`
``
717
`` +
`)
``
``
718
`+
})
`