Skip to content

Commit ae2b099

Browse files
authored
fix: Treeview v3 ssr tests (#7967)
* try with babel * fix tree ssr tests * remove unneeded change * Update __mocks__/fileMock.js
1 parent a058e48 commit ae2b099

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2025 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import {testSSR} from '@react-spectrum/test-utils-internal';
14+
15+
// TODO: fix the macros to work with SSR tests
16+
describe('TreeView SSR', function () {
17+
it('should render without errors', async function () {
18+
await testSSR(__filename, `
19+
import {Provider} from '@react-spectrum/provider';
20+
import {theme} from '@react-spectrum/theme-default';
21+
import {TreeView, TreeViewItem, TreeViewItemContent} from '../';
22+
import {Text} from '@react-spectrum/text';
23+
<Provider theme={theme}>
24+
<TreeView aria-label="Example tree with static contents" defaultExpandedKeys={['documents', 'photos']} height="size-4600" maxWidth="size-6000">
25+
<TreeViewItem id="documents" textValue="Documents">
26+
<TreeViewItemContent>
27+
<Text>Documents</Text>
28+
</TreeViewItemContent>
29+
<TreeViewItem id="project-a" textValue="Project A">
30+
<TreeViewItemContent>
31+
<Text>Project A</Text>
32+
</TreeViewItemContent>
33+
<TreeViewItem id="weekly-report" textValue="Weekly-Report">
34+
<TreeViewItemContent>
35+
<Text>Weekly Report</Text>
36+
</TreeViewItemContent>
37+
</TreeViewItem>
38+
</TreeViewItem>
39+
<TreeViewItem id="document-1" textValue="Document 1">
40+
<TreeViewItemContent>
41+
<Text>Document 1</Text>
42+
</TreeViewItemContent>
43+
</TreeViewItem>
44+
<TreeViewItem id="document-2" textValue="Document 2">
45+
<TreeViewItemContent>
46+
<Text>Document 2</Text>
47+
</TreeViewItemContent>
48+
</TreeViewItem>
49+
</TreeViewItem>
50+
<TreeViewItem id="photos" textValue="Photos">
51+
<TreeViewItemContent>
52+
<Text>Photos</Text>
53+
</TreeViewItemContent>
54+
<TreeViewItem id="image-1" textValue="Image 1">
55+
<TreeViewItemContent>
56+
<Text>Image 1</Text>
57+
</TreeViewItemContent>
58+
</TreeViewItem>
59+
<TreeViewItem id="image-2" textValue="Image 2">
60+
<TreeViewItemContent>
61+
<Text>Image 2</Text>
62+
</TreeViewItemContent>
63+
</TreeViewItem>
64+
<TreeViewItem id="image-3" textValue="Image 3">
65+
<TreeViewItemContent>
66+
<Text>Image 3</Text>
67+
</TreeViewItemContent>
68+
</TreeViewItem>
69+
</TreeViewItem>
70+
</TreeView>
71+
</Provider>
72+
`);
73+
});
74+
});

packages/dev/test-utils/src/ssrWorker.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ ignoreStyles.default(undefined, (module) => {
2222
});
2323

2424
require('@babel/register')({
25-
extensions: ['.js', '.ts', '.tsx']
25+
extensions: ['.js', '.ts', '.tsx'],
26+
plugins: [
27+
'@babel/plugin-syntax-import-attributes'
28+
]
2629
});
2730

2831
let {evaluate} = require('./ssrUtils');

packages/dev/test-utils/src/testSSR.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ try {
3232

3333
export async function testSSR(filename, source, runAfterServer) {
3434
// Transform the code with babel so JSX becomes JS.
35-
source = babel.transformSync(source, {filename}).code;
35+
source = babel.transformSync(source, {filename, plugins: ['@babel/plugin-syntax-import-attributes']}).code;
3636

3737
// Send the HTML along with the source code to the worker to be hydrated in a DOM environment.
3838
return new Promise((resolve, reject) => {

0 commit comments

Comments
 (0)