Skip to content

Commit 6422f69

Browse files
authored
Add theme support to tests tab (codesandbox#1793)
* add themes to the tests tab * clea clors * clean more colors * fix arrows * fix other arrow * Use jsdom instead of window in jest test (codesandbox#1812) * Hacky implementation of jsdom inside jest tests * Update path to jsdom * Properly set globals according to jest defaults * Properly set global to jsdom window * Make globals dynamic * Improve scrolling of tests view * Proper fix for the styling of tests * Convert jest-lite to typescript * Fix scrolling for the full test details * Deduplicate Tests container * Properly mark errors as jest errors, clear them on new start * Move clear error to less spammy place * Fix error loading later on in the editor * add bg
1 parent d9bd3ba commit 6422f69

File tree

12 files changed

+131
-105
lines changed

12 files changed

+131
-105
lines changed

packages/app/src/app/components/Preview/DevTools/Tests/TestDetails/ErrorDetails/index.tsx

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ const Container = styled.div`
1212
font-size: 0.875rem;
1313
line-height: 1.6;
1414
15-
color: rgba(255, 255, 255, 0.8);
16-
17-
background-color: rgba(0, 0, 0, 0.5);
18-
15+
color: ${props =>
16+
props.theme.light ? 'rgba(0, 0, 0, 0.8)' : 'rgba(255, 255, 255, 0.8)'};
17+
background-color: ${props => props.theme['sideBar.background']};
1918
white-space: pre-wrap;
2019
21-
border-bottom: 1px solid rgba(0, 0, 0, 0.5);
22-
2320
&:last-child {
2421
border-bottom: none;
2522
}
@@ -34,24 +31,20 @@ function escapeHtml(unsafe) {
3431
.replace(/'/g, ''');
3532
}
3633

37-
const white = 'rgba(255, 255, 255, 0.8)';
38-
3934
const formatDiffMessage = (error: TestError, path: string) => {
4035
let finalMessage: string = '';
4136
if (error.matcherResult) {
42-
finalMessage = `<span style="color:rgba(255, 255, 255, 0.5);">${escapeHtml(
43-
error.message
44-
)
37+
finalMessage = `<span>${escapeHtml(error.message)
4538
.replace(/(expected)/m, `<span style="color:${theme.green()}">$1</span>`)
4639
.replace(/(received)/m, `<span style="color:${theme.red()}">$1</span>`)
47-
.replace(/(Difference:)/m, `<span style="color:${white}">$1</span>`)
40+
.replace(/(Difference:)/m, `<span>$1</span>`)
4841
.replace(
4942
/(Expected.*\n)(.*)/m,
50-
`<span style="color:${white}">$1</span><span style="color:${theme.green()}">$2</span>`
43+
`<span>$1</span><span style="color:${theme.green()}">$2</span>`
5144
)
5245
.replace(
5346
/(Received.*\n)(.*)/m,
54-
`<span style="color:${white}">$1</span><span style="color:${theme.red()}">$2</span>`
47+
`<span>$1</span><span style="color:${theme.red()}">$2</span>`
5548
)
5649
.replace(/^(-.*)/gm, `<span style="color:${theme.red()}">$1</span>`)
5750
.replace(
@@ -94,11 +87,7 @@ const formatDiffMessage = (error: TestError, path: string) => {
9487
}
9588

9689
finalMessage +=
97-
`<div ${
98-
code.highlight
99-
? `style="font-weight:900;color:rgba(255, 255, 255, 0.5)"`
100-
: ``
101-
}>` +
90+
`<div ${code.highlight ? `style="font-weight:900;"` : ``}>` +
10291
(code.highlight
10392
? `<span style="color:${theme.red()};">></span> `
10493
: '') +
Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,39 @@
11
import styled from 'styled-components';
22

33
export const Block = styled.div<{ last: boolean }>`
4-
transition: 0.3s ease color;
54
display: flex;
65
padding: 0.5rem 0.4rem;
76
padding-left: 0.5rem;
87
position: relative;
98
margin-right: ${props => (props.last ? 0 : 12)}px;
10-
color: rgba(255, 255, 255, 0.5);
9+
color: ${props =>
10+
props.theme.light ? 'rgba(0, 0, 0, 0.5)' : 'rgba(255, 255, 255, 0.5)'};
1111
1212
white-space: nowrap;
1313
1414
&::after {
1515
content: '';
1616
position: absolute;
1717
margin: auto;
18-
top: 5px;
18+
top: 13px;
1919
right: -10px;
20-
width: 24px;
21-
height: 24px;
20+
width: 8px;
21+
height: 8px;
2222
transform: rotate(45deg);
23-
-webkit-transform: rotate(45deg);
24-
-moz-transform: rotate(45deg);
25-
-o-transform: rotate(45deg);
26-
-ms-transform: rotate(45deg);
27-
border-right: 1px solid rgba(0, 0, 0, ${props => (props.last ? 0.3 : 0.4)});
28-
border-top: 1px solid rgba(0, 0, 0, ${props => (props.last ? 0.3 : 0.4)});
29-
background-color: #181b1d;
23+
border-right: 1px solid ${props =>
24+
props.theme.light ? `rgba(0, 0, 0, ${(props.last ? 0.3 : 0.4)})` : `rgba(255, 255, 255, ${(props.last ? 0.3 : 0.4)})`};
25+
border-top: 1px solid ${props =>
26+
props.theme.light ? `rgba(0, 0, 0, ${(props.last ? 0.3 : 0.4)})` : `rgba(255, 255, 255, ${(props.last ? 0.3 : 0.4)})`};
27+
background-color: rgba(0, 0, 0, 0.01);
3028
z-index: 1;
3129
}
3230
`;
3331

3432
export const TestName = styled.div`
35-
transition: 0.3s ease background-color;
3633
padding: 0.4rem;
3734
padding-left: 20px;
38-
background-color: ${props => props.theme.background2};
39-
color: rgba(255, 255, 255, 0.8);
35+
color: ${props =>
36+
props.theme.light ? 'rgba(0, 0, 0, 0.8)' : 'rgba(255, 255, 255, 0.8)'};
4037
flex: auto;
4138
white-space: nowrap;
4239
`;
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import styled from 'styled-components';
2+
import Color from 'color'
23

34
export const BlockHeader = styled.div`
45
display: flex;
56
align-items: center;
67
width: 100%;
78
box-sizing: border-box;
8-
padding: 0 0.5rem;
9-
padding-right: 2px;
10-
background-color: #191c1d;
9+
padding: 0rem 1rem;
10+
1111
overflow: hidden;
12+
background-color: ${props => Color(props.theme['sideBar.background'])
13+
.darken(props.theme.light ? 0.1 : 0.3)
14+
.rgbString()};
1215
`;
1316

17+
1418
export const Container = styled.div`
15-
margin-bottom: 1rem;
19+
margin-bottom: 0.75rem;
1620
overflow: hidden;
1721
1822
border-radius: 2px;
@@ -22,19 +26,22 @@ export const Actions = styled.div`
2226
display: flex;
2327
align-items: center;
2428
padding: 7px;
25-
background-color: ${props => props.theme.background2};
29+
padding-right: 0;
2630
2731
font-size: 0.875rem;
28-
color: rgba(255, 255, 255, 0.5);
32+
color: ${props =>
33+
props.theme.light ? 'rgba(0, 0, 0, 0.5)' : 'rgba(255, 255, 255, 0.5)'};
34+
2935
3036
svg {
31-
transition: 0.3s ease color;
37+
transition: 0.3s ease opacity;
3238
margin-right: 1rem;
3339
font-size: 1.125rem;
3440
cursor: pointer;
35-
41+
color: ${props => props.theme['button.hoverBackground']};
42+
opacity: 0.8;
3643
&:hover {
37-
color: white;
44+
opacity: 1;
3845
}
3946
}
4047
`;

packages/app/src/app/components/Preview/DevTools/Tests/TestDetails/elements.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export const Action = styled.div`
1818
opacity: 0.7;
1919
cursor: pointer;
2020
21+
svg {
22+
color: ${props => props.theme['button.hoverBackground']};
23+
}
24+
2125
&:hover {
2226
opacity: 1;
2327
}
@@ -28,14 +32,15 @@ export const Action = styled.div`
2832
`;
2933

3034
export const ErrorNotice = styled.div`
31-
color: rgba(255, 255, 255, 0.5);
35+
opacity: 0.5;
36+
color:${props => props.theme['sideBar.foreground']};
3237
font-weight: 500;
3338
`;
3439

3540
export const TestName = styled.span`
3641
font-weight: 400;
3742
font-size: 1rem;
38-
color: white;
43+
color:${props => props.theme['sideBar.foreground']};
3944
margin: 0;
4045
margin-top: 0;
4146
margin-bottom: 0;
@@ -44,5 +49,6 @@ export const TestName = styled.span`
4449
export const Blocks = styled.span`
4550
font-size: 1rem;
4651
font-weight: 300;
47-
color: rgba(255, 255, 255, 0.7);
52+
opacity: 0.7;
53+
color:${props => props.theme['sideBar.foreground']}
4854
`;

packages/app/src/app/components/Preview/DevTools/Tests/TestElement/elements.ts

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,27 @@ export const Actions = styled.div`
66
opacity: 0;
77
font-size: 1.125rem;
88
9-
color: white;
9+
color: ${props =>
10+
props.theme.light ? 'rgb(0, 0, 0)' : 'rgb(255, 255, 255)'};
1011
1112
svg {
1213
margin-left: 0.5rem;
13-
transition: 0.3s ease color;
14-
15-
color: rgba(255, 255, 255, 0.6);
14+
transition: 0.3s ease opacity;
15+
opacity: 0.6;
16+
color: ${props => props.theme['button.hoverBackground']};
1617
1718
&:hover {
18-
color: rgba(255, 255, 255, 1);
19+
opacity: 1;
1920
}
2021
}
2122
`;
2223

2324
export const TestName = styled.div`
24-
transition: 0.3s ease background-color;
2525
padding: 0.25rem;
2626
padding-left: 20px;
27-
background-color: ${props => props.theme.background2};
28-
color: rgba(255, 255, 255, 0.8);
27+
background-color: ${props => props.theme['sideBar.background']};
28+
color: ${props =>
29+
props.theme.light ? 'rgba(0, 0, 0, 0.8)' : 'rgba(255, 255, 255, 0.8)'};
2930
flex: auto;
3031
white-space: nowrap;
3132
`;
@@ -36,43 +37,37 @@ export const Test = styled.div<{ status: Status }>`
3637
padding-left: 1rem;
3738
cursor: pointer;
3839
39-
background-color: #181b1d;
40-
4140
${props =>
4241
props.status === 'idle' &&
4342
css`
44-
color: rgba(255, 255, 255, 0.4);
43+
color: ${props =>
44+
props.theme.light ? 'rgba(0, 0, 0, 0.4)' : 'rgba(255, 255, 255, 0.4)'};
4545
`};
4646
`;
4747

4848
export const Block = styled.div<{ last: boolean }>`
49-
transition: 0.3s ease color;
5049
display: flex;
5150
padding: 0.25rem 0.4rem;
5251
padding-left: 0.5rem;
5352
position: relative;
5453
margin-right: ${props => (props.last ? 0 : 12)}px;
55-
color: rgba(255, 255, 255, 0.5);
54+
color: ${props =>
55+
props.theme.light ? 'rgba(0, 0, 0, 0.5)' : 'rgba(255, 255, 255, 0.5)'};
5656
5757
white-space: nowrap;
5858
5959
&::after {
6060
content: '';
6161
position: absolute;
62-
margin: auto;
63-
top: 3px;
62+
top: 8px;
6463
right: -10px;
65-
width: 17px;
66-
height: 17px;
64+
width: 10px;
65+
height: 10px;
6766
transform: rotate(45deg);
68-
-webkit-transform: rotate(45deg);
69-
-moz-transform: rotate(45deg);
70-
-o-transform: rotate(45deg);
71-
-ms-transform: rotate(45deg);
72-
border-right: 2px solid rgba(0, 0, 0, 0.2);
73-
border-top: 2px solid rgba(0, 0, 0, 0.2);
74-
background-color: #181b1d;
75-
z-index: 1;
67+
border-right: 1px solid ${props =>
68+
props.theme.light ? `rgba(0, 0, 0, ${(props.last ? 0.3 : 0.4)})` : `rgba(255, 255, 255, ${(props.last ? 0.3 : 0.4)})`};
69+
border-top: 1px solid ${props =>
70+
props.theme.light ? `rgba(0, 0, 0, ${(props.last ? 0.3 : 0.4)})` : `rgba(255, 255, 255, ${(props.last ? 0.3 : 0.4)})`};
7671
}
7772
`;
7873

@@ -86,18 +81,21 @@ export const FileData = styled.div`
8681
`;
8782

8883
export const Path = styled.span`
89-
color: rgba(255, 255, 255, 0.6);
84+
color: ${props =>
85+
props.theme.light ? 'rgba(0, 0, 0, 0.6)' : 'rgba(255, 255, 255, 0.6)'};
9086
`;
9187

9288
export const FileName = styled.span`
93-
color: rgba(255, 255, 255, 0.8);
89+
color: ${props =>
90+
props.theme.light ? 'rgba(0, 0, 0, 0.8)' : 'rgba(255, 255, 255, 0.8)'};
9491
9592
flex: 1;
9693
`;
9794

9895
export const Tests = styled.div`
9996
font-weight: 400;
100-
color: rgba(255, 255, 255, 0.7);
97+
color: ${props =>
98+
props.theme.light ? 'rgba(0, 0, 0, 0.7)' : 'rgba(255, 255, 255, 0.7)'};
10199
overflow-x: auto;
102100
103101
&::-webkit-scrollbar {
@@ -113,7 +111,10 @@ export const Container = styled.div<{ selected: boolean }>`
113111
border-left: 2px solid transparent;
114112
115113
&:hover {
116-
background-color: rgba(0, 0, 0, 0.2);
114+
background-color: ${props =>
115+
!props.theme.light ? 'rgba(0, 0, 0, 0.2)' : 'rgba(255, 255, 255, 0.2)'};
116+
color: ${props =>
117+
props.theme.light ? 'rgba(0, 0, 0, 1)' : 'rgba(255, 255, 255, 1)'};
117118
border-left-color: ${props => props.theme.secondary.clearer(0.5)};
118119
119120
${Actions} {
@@ -122,11 +123,11 @@ export const Container = styled.div<{ selected: boolean }>`
122123
123124
${Test} {
124125
${TestName} {
125-
background-color: rgba(0, 0, 0, 0.05);
126126
}
127127
128128
${Block} {
129-
color: rgba(255, 255, 255, 0.8);
129+
color: ${props =>
130+
props.theme.light ? 'rgba(0, 0, 0, 1)' : 'rgba(255, 255, 255, 1)'};
130131
}
131132
}
132133
}
@@ -135,21 +136,33 @@ export const Container = styled.div<{ selected: boolean }>`
135136
props.selected &&
136137
css`
137138
border-left-color: ${props.theme.secondary};
138-
background-color: rgba(0, 0, 0, 0.3);
139+
background-color: ${props =>
140+
!props.theme.light ? 'rgba(0, 0, 0, 0.2)' : 'rgba(255, 255, 255, 0.2)'};
141+
color: ${props =>
142+
props.theme.light ? 'rgba(0, 0, 0, 1)' : 'rgba(255, 255, 255, 1)'};
139143
140144
${Test} {
141145
${TestName} {
142-
background-color: rgba(0, 0, 0, 0.05);
146+
background-color: ${props =>
147+
!props.theme.light
148+
? 'rgba(0, 0, 0, 0.2)'
149+
: 'rgba(255, 255, 255, 0.2)'};
150+
color: ${props =>
151+
props.theme.light ? 'rgba(0, 0, 0, 1)' : 'rgba(255, 255, 255, 1)'};
143152
}
144153
145154
${Block} {
146-
color: rgba(255, 255, 255, 0.8);
155+
background-color: ${props =>
156+
!props.theme.light
157+
? 'rgba(0, 0, 0, 0.2)'
158+
: 'rgba(255, 255, 255, 0.2)'};
159+
color: ${props =>
160+
props.theme.light ? 'rgba(0, 0, 0, 1)' : 'rgba(255, 255, 255, 1)'};
147161
}
148162
}
149163
150164
&:hover {
151165
border-left-color: ${props.theme.secondary};
152-
background-color: rgba(0, 0, 0, 0.3);
153166
}
154167
`};
155168
`;

0 commit comments

Comments
 (0)