test: create tmp folder in os.tmp() folder (#1982)
This commit is contained in:
parent
4046415f01
commit
18c975509f
13
test/test.js
13
test/test.js
@ -14,11 +14,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const os = require('os');
|
||||||
const rm = require('rimraf').sync;
|
const rm = require('rimraf').sync;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const {helper} = require('../lib/helper');
|
const {helper} = require('../lib/helper');
|
||||||
if (process.env.COVERAGE)
|
if (process.env.COVERAGE)
|
||||||
helper.recordPublicAPICoverage();
|
helper.recordPublicAPICoverage();
|
||||||
|
const mkdtempAsync = helper.promisify(fs.mkdtemp);
|
||||||
|
const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-');
|
||||||
|
|
||||||
const PROJECT_ROOT = fs.existsSync(path.join(__dirname, '..', 'package.json')) ? path.join(__dirname, '..') : path.join(__dirname, '..', '..');
|
const PROJECT_ROOT = fs.existsSync(path.join(__dirname, '..', 'package.json')) ? path.join(__dirname, '..') : path.join(__dirname, '..', '..');
|
||||||
|
|
||||||
@ -137,7 +140,7 @@ describe('Puppeteer', function() {
|
|||||||
expect(waitError.message.startsWith('Failed to launch chrome! spawn random-invalid-path ENOENT')).toBe(true);
|
expect(waitError.message.startsWith('Failed to launch chrome! spawn random-invalid-path ENOENT')).toBe(true);
|
||||||
});
|
});
|
||||||
it('userDataDir option', async({server}) => {
|
it('userDataDir option', async({server}) => {
|
||||||
const userDataDir = fs.mkdtempSync(path.join(__dirname, 'test-user-data-dir'));
|
const userDataDir = await mkdtempAsync(TMP_FOLDER);
|
||||||
const options = Object.assign({userDataDir}, defaultBrowserOptions);
|
const options = Object.assign({userDataDir}, defaultBrowserOptions);
|
||||||
const browser = await puppeteer.launch(options);
|
const browser = await puppeteer.launch(options);
|
||||||
expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
|
expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
|
||||||
@ -146,7 +149,7 @@ describe('Puppeteer', function() {
|
|||||||
rm(userDataDir);
|
rm(userDataDir);
|
||||||
});
|
});
|
||||||
it('userDataDir argument', async({server}) => {
|
it('userDataDir argument', async({server}) => {
|
||||||
const userDataDir = fs.mkdtempSync(path.join(__dirname, 'test-user-data-dir'));
|
const userDataDir = await mkdtempAsync(TMP_FOLDER);
|
||||||
const options = Object.assign({}, defaultBrowserOptions);
|
const options = Object.assign({}, defaultBrowserOptions);
|
||||||
options.args = [`--user-data-dir=${userDataDir}`].concat(options.args);
|
options.args = [`--user-data-dir=${userDataDir}`].concat(options.args);
|
||||||
const browser = await puppeteer.launch(options);
|
const browser = await puppeteer.launch(options);
|
||||||
@ -156,7 +159,7 @@ describe('Puppeteer', function() {
|
|||||||
rm(userDataDir);
|
rm(userDataDir);
|
||||||
});
|
});
|
||||||
it('userDataDir option should restore state', async({server}) => {
|
it('userDataDir option should restore state', async({server}) => {
|
||||||
const userDataDir = fs.mkdtempSync(path.join(__dirname, 'test-user-data-dir'));
|
const userDataDir = await mkdtempAsync(TMP_FOLDER);
|
||||||
const options = Object.assign({userDataDir}, defaultBrowserOptions);
|
const options = Object.assign({userDataDir}, defaultBrowserOptions);
|
||||||
const browser = await puppeteer.launch(options);
|
const browser = await puppeteer.launch(options);
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
@ -173,7 +176,7 @@ describe('Puppeteer', function() {
|
|||||||
});
|
});
|
||||||
// @see https://github.com/GoogleChrome/puppeteer/issues/1537
|
// @see https://github.com/GoogleChrome/puppeteer/issues/1537
|
||||||
xit('userDataDir option should restore cookies', async({server}) => {
|
xit('userDataDir option should restore cookies', async({server}) => {
|
||||||
const userDataDir = fs.mkdtempSync(path.join(__dirname, 'test-user-data-dir'));
|
const userDataDir = await mkdtempAsync(TMP_FOLDER);
|
||||||
const options = Object.assign({userDataDir}, defaultBrowserOptions);
|
const options = Object.assign({userDataDir}, defaultBrowserOptions);
|
||||||
const browser = await puppeteer.launch(options);
|
const browser = await puppeteer.launch(options);
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
@ -189,7 +192,7 @@ describe('Puppeteer', function() {
|
|||||||
rm(userDataDir);
|
rm(userDataDir);
|
||||||
});
|
});
|
||||||
xit('headless should be able to read cookies written by headful', async({server}) => {
|
xit('headless should be able to read cookies written by headful', async({server}) => {
|
||||||
const userDataDir = fs.mkdtempSync(path.join(__dirname, 'test-user-data-dir'));
|
const userDataDir = await mkdtempAsync(TMP_FOLDER);
|
||||||
const options = Object.assign({userDataDir}, defaultBrowserOptions);
|
const options = Object.assign({userDataDir}, defaultBrowserOptions);
|
||||||
// Write a cookie in headful chrome
|
// Write a cookie in headful chrome
|
||||||
options.headless = false;
|
options.headless = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user