mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: replace rimraf in tests with a helper with retries (#9888)
This commit is contained in:
parent
9150cfe253
commit
f1488b6c3a
@ -23,9 +23,8 @@ import {
|
|||||||
PuppeteerLaunchOptions,
|
PuppeteerLaunchOptions,
|
||||||
PuppeteerNode,
|
PuppeteerNode,
|
||||||
} from 'puppeteer-core/internal/node/PuppeteerNode.js';
|
} from 'puppeteer-core/internal/node/PuppeteerNode.js';
|
||||||
import rimraf from 'rimraf';
|
|
||||||
|
|
||||||
import {getTestState} from './mocha-utils.js';
|
import {getTestState, rmSync} from './mocha-utils.js';
|
||||||
|
|
||||||
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
|
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
|
||||||
|
|
||||||
@ -237,7 +236,9 @@ describe('headful tests', function () {
|
|||||||
});
|
});
|
||||||
await headlessBrowser.close();
|
await headlessBrowser.close();
|
||||||
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
||||||
await rimraf(userDataDir).catch(() => {});
|
try {
|
||||||
|
rmSync(userDataDir);
|
||||||
|
} catch {}
|
||||||
expect(cookie).toBe('foo=true');
|
expect(cookie).toBe('foo=true');
|
||||||
});
|
});
|
||||||
// TODO: Support OOOPIF. @see https://github.com/puppeteer/puppeteer/issues/2548
|
// TODO: Support OOOPIF. @see https://github.com/puppeteer/puppeteer/issues/2548
|
||||||
|
@ -23,16 +23,11 @@ import {Protocol} from 'devtools-protocol';
|
|||||||
import expect from 'expect';
|
import expect from 'expect';
|
||||||
import {BrowserFetcher, TimeoutError} from 'puppeteer';
|
import {BrowserFetcher, TimeoutError} from 'puppeteer';
|
||||||
import {Page} from 'puppeteer-core/internal/api/Page.js';
|
import {Page} from 'puppeteer-core/internal/api/Page.js';
|
||||||
import rimraf from 'rimraf';
|
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
|
|
||||||
import {getTestState, itOnlyRegularInstall} from './mocha-utils.js';
|
import {getTestState, itOnlyRegularInstall, rmSync} from './mocha-utils.js';
|
||||||
import utils from './utils.js';
|
import utils from './utils.js';
|
||||||
|
|
||||||
const rmAsync = (filename: string) => {
|
|
||||||
return rimraf(filename);
|
|
||||||
};
|
|
||||||
|
|
||||||
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
|
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
|
||||||
const FIREFOX_TIMEOUT = 30 * 1000;
|
const FIREFOX_TIMEOUT = 30 * 1000;
|
||||||
|
|
||||||
@ -77,12 +72,10 @@ describe('Launcher specs', function () {
|
|||||||
expect((await stat(revisionInfo.executablePath)).mode & 0o777).toBe(
|
expect((await stat(revisionInfo.executablePath)).mode & 0o777).toBe(
|
||||||
expectedPermissions
|
expectedPermissions
|
||||||
);
|
);
|
||||||
expect(await browserFetcher.localRevisions()).toEqual([
|
expect(browserFetcher.localRevisions()).toEqual([expectedRevision]);
|
||||||
expectedRevision,
|
|
||||||
]);
|
|
||||||
await browserFetcher.remove(expectedRevision);
|
await browserFetcher.remove(expectedRevision);
|
||||||
expect(await browserFetcher.localRevisions()).toEqual([]);
|
expect(browserFetcher.localRevisions()).toEqual([]);
|
||||||
await rmAsync(downloadsFolder);
|
rmSync(downloadsFolder);
|
||||||
});
|
});
|
||||||
it('should download and extract firefox linux binary', async () => {
|
it('should download and extract firefox linux binary', async () => {
|
||||||
const {server} = getTestState();
|
const {server} = getTestState();
|
||||||
@ -127,7 +120,7 @@ describe('Launcher specs', function () {
|
|||||||
]);
|
]);
|
||||||
await browserFetcher.remove(expectedVersion);
|
await browserFetcher.remove(expectedVersion);
|
||||||
expect(await browserFetcher.localRevisions()).toEqual([]);
|
expect(await browserFetcher.localRevisions()).toEqual([]);
|
||||||
await rmAsync(downloadsFolder);
|
rmSync(downloadsFolder);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -248,7 +241,9 @@ describe('Launcher specs', function () {
|
|||||||
await browser.close();
|
await browser.close();
|
||||||
expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
|
expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
|
||||||
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
||||||
await rmAsync(userDataDir).catch(() => {});
|
try {
|
||||||
|
rmSync(userDataDir);
|
||||||
|
} catch {}
|
||||||
});
|
});
|
||||||
it('tmp profile should be cleaned up', async () => {
|
it('tmp profile should be cleaned up', async () => {
|
||||||
const {defaultBrowserOptions, puppeteer} = getTestState();
|
const {defaultBrowserOptions, puppeteer} = getTestState();
|
||||||
@ -301,7 +296,9 @@ describe('Launcher specs', function () {
|
|||||||
expect(await readFile(prefsJSPath, 'utf8')).toBe(prefsJSContent);
|
expect(await readFile(prefsJSPath, 'utf8')).toBe(prefsJSContent);
|
||||||
|
|
||||||
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
||||||
await rmAsync(userDataDir).catch(() => {});
|
try {
|
||||||
|
rmSync(userDataDir);
|
||||||
|
} catch {}
|
||||||
});
|
});
|
||||||
it('userDataDir argument', async () => {
|
it('userDataDir argument', async () => {
|
||||||
const {isChrome, puppeteer, defaultBrowserOptions} = getTestState();
|
const {isChrome, puppeteer, defaultBrowserOptions} = getTestState();
|
||||||
@ -325,13 +322,15 @@ describe('Launcher specs', function () {
|
|||||||
await browser.close();
|
await browser.close();
|
||||||
expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
|
expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
|
||||||
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
||||||
await rmAsync(userDataDir).catch(() => {});
|
try {
|
||||||
|
rmSync(userDataDir);
|
||||||
|
} catch {}
|
||||||
});
|
});
|
||||||
it('userDataDir argument with non-existent dir', async () => {
|
it('userDataDir argument with non-existent dir', async () => {
|
||||||
const {isChrome, puppeteer, defaultBrowserOptions} = getTestState();
|
const {isChrome, puppeteer, defaultBrowserOptions} = getTestState();
|
||||||
|
|
||||||
const userDataDir = await mkdtemp(TMP_FOLDER);
|
const userDataDir = await mkdtemp(TMP_FOLDER);
|
||||||
await rmAsync(userDataDir);
|
rmSync(userDataDir);
|
||||||
const options = Object.assign({}, defaultBrowserOptions);
|
const options = Object.assign({}, defaultBrowserOptions);
|
||||||
if (isChrome) {
|
if (isChrome) {
|
||||||
options.args = [
|
options.args = [
|
||||||
@ -350,7 +349,9 @@ describe('Launcher specs', function () {
|
|||||||
await browser.close();
|
await browser.close();
|
||||||
expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
|
expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
|
||||||
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
||||||
await rmAsync(userDataDir).catch(() => {});
|
try {
|
||||||
|
rmSync(userDataDir);
|
||||||
|
} catch {}
|
||||||
});
|
});
|
||||||
it('userDataDir option should restore state', async () => {
|
it('userDataDir option should restore state', async () => {
|
||||||
const {server, puppeteer, defaultBrowserOptions} = getTestState();
|
const {server, puppeteer, defaultBrowserOptions} = getTestState();
|
||||||
@ -375,7 +376,9 @@ describe('Launcher specs', function () {
|
|||||||
).toBe('hello');
|
).toBe('hello');
|
||||||
await browser2.close();
|
await browser2.close();
|
||||||
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
||||||
await rmAsync(userDataDir).catch(() => {});
|
try {
|
||||||
|
rmSync(userDataDir);
|
||||||
|
} catch {}
|
||||||
});
|
});
|
||||||
it('userDataDir option should restore cookies', async () => {
|
it('userDataDir option should restore cookies', async () => {
|
||||||
const {server, puppeteer, defaultBrowserOptions} = getTestState();
|
const {server, puppeteer, defaultBrowserOptions} = getTestState();
|
||||||
@ -401,7 +404,9 @@ describe('Launcher specs', function () {
|
|||||||
).toBe('doSomethingOnlyOnce=true');
|
).toBe('doSomethingOnlyOnce=true');
|
||||||
await browser2.close();
|
await browser2.close();
|
||||||
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
||||||
await rmAsync(userDataDir).catch(() => {});
|
try {
|
||||||
|
rmSync(userDataDir);
|
||||||
|
} catch {}
|
||||||
});
|
});
|
||||||
it('should return the default arguments', async () => {
|
it('should return the default arguments', async () => {
|
||||||
const {isChrome, isFirefox, puppeteer} = getTestState();
|
const {isChrome, isFirefox, puppeteer} = getTestState();
|
||||||
|
@ -34,7 +34,6 @@ import {
|
|||||||
PuppeteerNode,
|
PuppeteerNode,
|
||||||
} from 'puppeteer-core/internal/node/PuppeteerNode.js';
|
} from 'puppeteer-core/internal/node/PuppeteerNode.js';
|
||||||
import {isErrorLike} from 'puppeteer-core/internal/util/ErrorLike.js';
|
import {isErrorLike} from 'puppeteer-core/internal/util/ErrorLike.js';
|
||||||
import rimraf from 'rimraf';
|
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
|
|
||||||
import {extendExpectWithToBeGolden} from './utils.js';
|
import {extendExpectWithToBeGolden} from './utils.js';
|
||||||
@ -128,7 +127,7 @@ const setupGoldenAssertions = (): void => {
|
|||||||
const GOLDEN_DIR = path.join(__dirname, `../golden-${suffix}`);
|
const GOLDEN_DIR = path.join(__dirname, `../golden-${suffix}`);
|
||||||
const OUTPUT_DIR = path.join(__dirname, `../output-${suffix}`);
|
const OUTPUT_DIR = path.join(__dirname, `../output-${suffix}`);
|
||||||
if (fs.existsSync(OUTPUT_DIR)) {
|
if (fs.existsSync(OUTPUT_DIR)) {
|
||||||
rimraf.sync(OUTPUT_DIR);
|
rmSync(OUTPUT_DIR);
|
||||||
}
|
}
|
||||||
extendExpectWithToBeGolden(GOLDEN_DIR, OUTPUT_DIR);
|
extendExpectWithToBeGolden(GOLDEN_DIR, OUTPUT_DIR);
|
||||||
};
|
};
|
||||||
@ -332,3 +331,11 @@ export const createTimeout = <T>(
|
|||||||
}, n);
|
}, n);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function rmSync(target: string): void {
|
||||||
|
fs.rmSync(target, {
|
||||||
|
force: true,
|
||||||
|
recursive: true,
|
||||||
|
maxRetries: 5,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user