Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 844af21

Browse files
committedJan 14, 2025··
fix browser scripts
1 parent 4b2157e commit 844af21

File tree

10 files changed

+105
-81
lines changed

10 files changed

+105
-81
lines changed
 

‎plugins/css-blank-pseudo/test/_browser.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ if (!process.env.DEBUG) {
5858
test('browser', { skip: process.env.GITHUB_ACTIONS && !process.env.BROWSER_TESTS }, async () => {
5959
const cleanup = startServers();
6060

61-
const browser = await puppeteer.launch({
62-
headless: 'new',
63-
});
61+
let browser;
6462

6563
try {
64+
browser = await puppeteer.launch({
65+
headless: 'new',
66+
});
67+
6668
const page = await browser.newPage();
6769
page.on('pageerror', (msg) => {
6870
throw msg;
@@ -238,7 +240,7 @@ if (!process.env.DEBUG) {
238240
}
239241
}
240242
} finally {
241-
await browser.close();
243+
await browser?.close();
242244

243245
await cleanup();
244246
}

‎plugins/css-has-pseudo/test/_browser.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ if (!process.env.DEBUG) {
8383
test('browser', { skip: process.env.GITHUB_ACTIONS && !process.env.BROWSER_TESTS }, async () => {
8484
const cleanup = startServers();
8585

86-
const browser = await puppeteer.launch({
87-
headless: 'new',
88-
});
86+
let browser;
8987

9088
try {
89+
browser = await puppeteer.launch({
90+
headless: 'new',
91+
});
92+
9193
const page = await browser.newPage();
9294
page.on('pageerror', (msg) => {
9395
throw msg;
@@ -127,7 +129,7 @@ if (!process.env.DEBUG) {
127129
}
128130
}
129131
} finally {
130-
await browser.close();
132+
await browser?.close();
131133

132134
await cleanup();
133135
}

‎plugins/css-prefers-color-scheme/test/_browser.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ if (!process.env.DEBUG) {
7272
test('browser', { skip: process.env.GITHUB_ACTIONS && !process.env.BROWSER_TESTS }, async () => {
7373
const cleanup = startServers();
7474

75-
const browser = await puppeteer.launch({
76-
headless: 'new',
77-
});
75+
let browser;
7876

7977
try {
78+
browser = await puppeteer.launch({
79+
headless: 'new',
80+
});
81+
8082
const page = await browser.newPage();
8183
page.on('pageerror', (msg) => {
8284
throw msg;
@@ -160,7 +162,7 @@ if (!process.env.DEBUG) {
160162
}
161163
}
162164
} finally {
163-
await browser.close();
165+
await browser?.close();
164166

165167
await cleanup();
166168
}

‎plugins/postcss-cascade-layers/test/_browser.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ if (!process.env.DEBUG) {
9797
test('browser', { skip: process.env.GITHUB_ACTIONS && !process.env.BROWSER_TESTS }, async () => {
9898
const cleanup = startServers();
9999

100-
const browser = await puppeteer.launch({
101-
headless: 'new',
102-
});
100+
let browser;
103101

104102
try {
103+
browser = await puppeteer.launch({
104+
headless: 'new',
105+
});
106+
105107
const page = await browser.newPage();
106108
page.on('pageerror', (msg) => {
107109
throw msg;
@@ -127,7 +129,7 @@ if (!process.env.DEBUG) {
127129
}
128130
}
129131
} finally {
130-
await browser.close();
132+
await browser?.close();
131133

132134
await cleanup();
133135
}

‎plugins/postcss-focus-visible/test/_browser.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ if (!process.env.DEBUG) {
4343
test('browser', { skip: process.env.GITHUB_ACTIONS && !process.env.BROWSER_TESTS }, async () => {
4444
const cleanup = startServers();
4545

46-
const browser = await puppeteer.launch({
47-
headless: 'new',
48-
});
46+
let browser;
4947

5048
try {
49+
browser = await puppeteer.launch({
50+
headless: 'new',
51+
});
52+
5153
const page = await browser.newPage();
5254
page.on('pageerror', (msg) => {
5355
throw msg;
@@ -98,7 +100,7 @@ if (!process.env.DEBUG) {
98100
await page.evaluate(async () => window.checkElement('click', 'c', false));
99101
}
100102
} finally {
101-
await browser.close();
103+
await browser?.close();
102104

103105
await cleanup();
104106
}

‎plugins/postcss-focus-within/test/_browser.mjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ if (!process.env.DEBUG) {
5858
test('browser', { skip: process.env.GITHUB_ACTIONS && !process.env.BROWSER_TESTS }, async () => {
5959
const cleanup = startServers();
6060

61-
const browser = await puppeteer.launch({
62-
headless: 'new',
63-
});
61+
let browser;
6462

6563
try {
64+
browser = await puppeteer.launch({
65+
headless: 'new',
66+
});
67+
6668
const page = await browser.newPage();
6769
page.on('pageerror', (msg) => {
6870
throw msg;
@@ -162,7 +164,8 @@ if (!process.env.DEBUG) {
162164
await page.evaluate(async () => window.checkElement('default', 'a-child-input', false));
163165
}
164166
} finally {
165-
await browser.close();
167+
await browser?.close();
168+
166169
await cleanup();
167170
}
168171
});

‎plugins/postcss-is-pseudo-class/test/_browser.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ if (!process.env.DEBUG) {
4141
test('browser', { skip: process.env.GITHUB_ACTIONS && !process.env.BROWSER_TESTS }, async () => {
4242
const cleanup = startServers();
4343

44-
const browser = await puppeteer.launch({
45-
headless: 'new',
46-
});
44+
let browser;
4745

4846
try {
47+
browser = await puppeteer.launch({
48+
headless: 'new',
49+
});
50+
4951
const page = await browser.newPage();
5052
page.on('pageerror', (msg) => {
5153
throw msg;
@@ -59,7 +61,7 @@ if (!process.env.DEBUG) {
5961
throw new Error('Test failed, expected "window.runTest()" to return true');
6062
}
6163
} finally {
62-
await browser.close();
64+
await browser?.close();
6365

6466
await cleanup();
6567
}

‎plugins/postcss-light-dark-function/test/_browser.mjs

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -96,55 +96,60 @@ if (!process.env.DEBUG) {
9696
test('browser', { skip: process.env.GITHUB_ACTIONS && !process.env.BROWSER_TESTS }, async () => {
9797
const cleanup = startServers();
9898

99-
const browser = await puppeteer.launch({
100-
headless: 'new',
101-
});
102-
103-
const page = await browser.newPage();
104-
page.on('pageerror', (msg) => {
105-
throw msg;
106-
});
107-
108-
for (const url of [
109-
'wpt/light-dark-basic.html',
110-
'wpt/light-dark-currentcolor-in-color.html',
111-
'wpt/light-dark-inherited.html',
112-
]) {
113-
await page.goto('http://localhost:8080/' + url);
114-
115-
try {
116-
await page.evaluate(async () => {
117-
// eslint-disable-next-line no-undef
118-
return await window.runTest();
119-
});
120-
} catch (err) {
121-
errors.push(err);
99+
let browser;
100+
101+
try {
102+
browser = await puppeteer.launch({
103+
headless: 'new',
104+
});
105+
106+
const page = await browser.newPage();
107+
page.on('pageerror', (msg) => {
108+
throw msg;
109+
});
110+
111+
for (const url of [
112+
'wpt/light-dark-basic.html',
113+
'wpt/light-dark-currentcolor-in-color.html',
114+
'wpt/light-dark-inherited.html',
115+
]) {
116+
await page.goto('http://localhost:8080/' + url);
117+
118+
try {
119+
await page.evaluate(async () => {
120+
// eslint-disable-next-line no-undef
121+
return await window.runTest();
122+
});
123+
} catch (err) {
124+
errors.push(err);
125+
}
122126
}
123-
}
124127

125-
await page.emulateMediaFeatures([
126-
{ name: 'prefers-color-scheme', value: 'dark' },
127-
]);
128-
129-
for (const url of [
130-
'wpt/light-dark-basic.html',
131-
'wpt/light-dark-currentcolor-in-color.html',
132-
'wpt/light-dark-inherited.html',
133-
]) {
134-
await page.goto('http://localhost:8080/' + url);
135-
136-
try {
137-
await page.evaluate(async () => {
138-
// eslint-disable-next-line no-undef
139-
return await window.runTest();
140-
});
141-
} catch (err) {
142-
errors.push(err);
128+
await page.emulateMediaFeatures([
129+
{ name: 'prefers-color-scheme', value: 'dark' },
130+
]);
131+
132+
for (const url of [
133+
'wpt/light-dark-basic.html',
134+
'wpt/light-dark-currentcolor-in-color.html',
135+
'wpt/light-dark-inherited.html',
136+
]) {
137+
await page.goto('http://localhost:8080/' + url);
138+
139+
try {
140+
await page.evaluate(async () => {
141+
// eslint-disable-next-line no-undef
142+
return await window.runTest();
143+
});
144+
} catch (err) {
145+
errors.push(err);
146+
}
143147
}
144-
}
148+
} finally {
149+
await browser?.close();
145150

146-
await browser.close();
147-
await cleanup();
151+
await cleanup();
152+
}
148153

149154
if (errors.length > 0) {
150155
errors.forEach((err) => {

‎plugins/postcss-media-minmax/test/_browser.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ if (!process.env.DEBUG) {
8383
test('browser', { skip: process.env.GITHUB_ACTIONS && !process.env.BROWSER_TESTS }, async () => {
8484
const cleanup = startServers();
8585

86-
const browser = await puppeteer.launch({
87-
headless: 'new',
88-
});
86+
let browser;
8987

9088
try {
89+
browser = await puppeteer.launch({
90+
headless: 'new',
91+
});
92+
9193
const page = await browser.newPage();
9294

9395
await page.setViewport({
@@ -113,7 +115,7 @@ if (!process.env.DEBUG) {
113115
}
114116
}
115117
} finally {
116-
await browser.close();
118+
await browser?.close();
117119

118120
await cleanup();
119121
}

‎plugins/postcss-nesting/test/_browser.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ if (!process.env.DEBUG) {
8989
test('browser', { skip: process.env.GITHUB_ACTIONS && !process.env.BROWSER_TESTS }, async () => {
9090
const cleanup = startServers();
9191

92-
const browser = await puppeteer.launch({
93-
headless: 'new',
94-
});
92+
let browser;
9593

9694
try {
95+
browser = await puppeteer.launch({
96+
headless: 'new',
97+
});
98+
9799
const page = await browser.newPage();
98100
page.on('pageerror', (msg) => {
99101
throw msg;
@@ -115,7 +117,7 @@ if (!process.env.DEBUG) {
115117
}
116118
}
117119
} finally {
118-
await browser.close();
120+
await browser?.close();
119121

120122
await cleanup();
121123
}

0 commit comments

Comments
 (0)
Please sign in to comment.