-
Notifications
You must be signed in to change notification settings - Fork 28.2k
/
Copy pathcompilation-and-prefixing.test.ts
191 lines (177 loc) · 6.09 KB
/
compilation-and-prefixing.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* eslint-env jest */
import { nextTestSetup } from 'e2e-utils'
const nextConfig = {
productionBrowserSourceMaps: true,
}
describe.each([
{ dependencies: { sass: '1.54.0' }, nextConfig },
{
dependencies: { 'sass-embedded': '1.75.0' },
nextConfig: {
...nextConfig,
sassOptions: {
implementation: 'sass-embedded',
},
},
},
])('SCSS Support ($dependencies)', ({ dependencies, nextConfig }) => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname,
// This test is skipped because it is reading files in the `.next` file which
// isn't available/necessary in a deployment environment.
skipDeployment: true,
dependencies,
nextConfig,
})
if (skipped) return // TODO: Figure out this test for dev and Turbopack
;(isNextDev ? describe.skip : describe)('Production only', () => {
describe('CSS Compilation and Prefixing', () => {
it(`should've compiled and prefixed`, async () => {
const $ = await next.render$('/')
const cssSheet = $('link[rel="stylesheet"]')
expect(cssSheet.length).toBe(1)
const stylesheetUrl = cssSheet.attr('href')
const cssContent = await next
.fetch(stylesheetUrl)
.then((res) => res.text())
const cssContentWithoutSourceMap = cssContent
.replace(/\/\*.*?\*\//g, '')
.trim()
if (process.env.TURBOPACK) {
if (dependencies.sass) {
expect(cssContentWithoutSourceMap).toMatchInlineSnapshot(
`".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}"`
)
} else {
expect(cssContentWithoutSourceMap).toMatchInlineSnapshot(
`".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}"`
)
}
} else {
if (dependencies.sass) {
expect(cssContentWithoutSourceMap).toMatchInlineSnapshot(
`".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}"`
)
} else {
expect(cssContentWithoutSourceMap).toMatchInlineSnapshot(
`".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}"`
)
}
}
// Contains a source map
expect(cssContent).toMatch(/\/\*#\s*sourceMappingURL=(.+\.map)\s*\*\//)
// Check sourcemap
const sourceMapUrl = /\/\*#\s*sourceMappingURL=(.+\.map)\s*\*\//.exec(
cssContent
)[1]
const actualSourceMapUrl = stylesheetUrl.replace(/[^/]+$/, sourceMapUrl)
const sourceMapContent = await next
.fetch(actualSourceMapUrl)
.then((res) => res.text())
const sourceMapContentParsed = JSON.parse(sourceMapContent)
// Ensure it doesn't have a specific path in the snapshot.
delete sourceMapContentParsed.file
delete sourceMapContentParsed.sources
if (process.env.TURBOPACK) {
if (dependencies.sass) {
expect(sourceMapContentParsed).toMatchInlineSnapshot(`
{
"sections": [
{
"map": {
"mappings": "AAAA,iCAAiC",
"names": [],
"sources": [
"turbopack:///[project]/styles/global.scss.css",
],
"sourcesContent": [
".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}",
],
"version": 3,
},
"offset": {
"column": 0,
"line": 1,
},
},
],
"version": 3,
}
`)
} else {
expect(sourceMapContentParsed).toMatchInlineSnapshot(`
{
"sections": [
{
"map": {
"mappings": "AAAA,iCAAiC",
"names": [],
"sources": [
"turbopack:///[project]/styles/global.scss.css",
],
"sourcesContent": [
".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}",
],
"version": 3,
},
"offset": {
"column": 0,
"line": 1,
},
},
],
"version": 3,
}
`)
}
} else {
if (dependencies.sass) {
expect(sourceMapContentParsed).toMatchInlineSnapshot(`
{
"ignoreList": [],
"mappings": "AAEE,uBACE,SAHE,CAON,cACE,2CAAA",
"names": [],
"sourceRoot": "",
"sourcesContent": [
"$var: red;
.redText {
::placeholder {
color: $var;
}
}
.flex-parsing {
flex: 0 0 calc(50% - var(--vertical-gutter));
}
",
],
"version": 3,
}
`)
} else {
expect(sourceMapContentParsed).toMatchInlineSnapshot(`
{
"ignoreList": [],
"mappings": "AAEE,uBACE,SAHE,CAON,cACE,2CAAA",
"names": [],
"sourceRoot": "",
"sourcesContent": [
"$var: red;
.redText {
::placeholder {
color: $var;
}
}
.flex-parsing {
flex: 0 0 calc(50% - var(--vertical-gutter));
}
",
],
"version": 3,
}
`)
}
}
})
})
})
})