Skip to content

Commit de1edd1

Browse files
james2doyleOrKoN
authored andcommitted
test: tweak other test to try and pass on windows
1 parent 5a20b4c commit de1edd1

File tree

1 file changed

+47
-21
lines changed

1 file changed

+47
-21
lines changed

tests/tools/screenshot.test.ts

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
import assert from 'node:assert';
7-
import {rm, stat, mkdir, chmod} from 'node:fs/promises';
7+
import {rm, stat, mkdir, chmod, writeFile} from 'node:fs/promises';
88
import {tmpdir} from 'node:os';
99
import {join} from 'node:path';
1010
import {describe, it} from 'node:test';
@@ -145,27 +145,53 @@ describe('screenshot', () => {
145145
});
146146

147147
it('with unwritable filePath', async () => {
148-
const dir = join(tmpdir(), 'readonly-dir-for-screenshot-test');
149-
await mkdir(dir, {recursive: true});
150-
await chmod(dir, 0o500);
151-
const filePath = join(dir, 'test-screenshot.png');
148+
if (process.platform === 'win32') {
149+
const filePath = join(tmpdir(), 'readonly-file-for-screenshot-test.png');
150+
// Create the file and make it read-only.
151+
await writeFile(filePath, '');
152+
await chmod(filePath, 0o400);
152153

153-
try {
154-
await withBrowser(async (response, context) => {
155-
const fixture = screenshots.basic;
156-
const page = context.getSelectedPage();
157-
await page.setContent(fixture.html);
158-
await assert.rejects(
159-
screenshot.handler(
160-
{params: {format: 'png', filePath}},
161-
response,
162-
context,
163-
),
164-
);
165-
});
166-
} finally {
167-
await chmod(dir, 0o700);
168-
await rm(dir, {recursive: true, force: true});
154+
try {
155+
await withBrowser(async (response, context) => {
156+
const fixture = screenshots.basic;
157+
const page = context.getSelectedPage();
158+
await page.setContent(fixture.html);
159+
await assert.rejects(
160+
screenshot.handler(
161+
{params: {format: 'png', filePath}},
162+
response,
163+
context,
164+
),
165+
);
166+
});
167+
} finally {
168+
// Make the file writable again so it can be deleted.
169+
await chmod(filePath, 0o600);
170+
await rm(filePath, {force: true});
171+
}
172+
} else {
173+
const dir = join(tmpdir(), 'readonly-dir-for-screenshot-test');
174+
await mkdir(dir, {recursive: true});
175+
await chmod(dir, 0o500);
176+
const filePath = join(dir, 'test-screenshot.png');
177+
178+
try {
179+
await withBrowser(async (response, context) => {
180+
const fixture = screenshots.basic;
181+
const page = context.getSelectedPage();
182+
await page.setContent(fixture.html);
183+
await assert.rejects(
184+
screenshot.handler(
185+
{params: {format: 'png', filePath}},
186+
response,
187+
context,
188+
),
189+
);
190+
});
191+
} finally {
192+
await chmod(dir, 0o700);
193+
await rm(dir, {recursive: true, force: true});
194+
}
169195
}
170196
});
171197

0 commit comments

Comments
 (0)