Skip to content

Commit e5afd92

Browse files
authored
chore(tests): resuse tmp file helpers from utils (#3119)
1 parent 63689e3 commit e5afd92

File tree

4 files changed

+9
-18
lines changed

4 files changed

+9
-18
lines changed

test/defaultbrowsercontext.jest.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ const fs = require('fs');
1919
const path = require('path');
2020
const utils = require('./utils');
2121
const os = require('os');
22-
const {promisify} = require('util');
2322

24-
const mkdtempAsync = promisify(fs.mkdtemp);
25-
const {makeUserDataDir, removeUserDataDir} = utils;
23+
const {mkdtempAsync, makeUserDataDir, removeUserDataDir} = utils;
2624
const {FFOX, MAC, CHROMIUM, WEBKIT, WIN, USES_HOOKS} = testOptions;
2725

2826
registerFixture('userDataDir', async ({}, test) => {

test/download.jest.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ const fs = require('fs');
1818
const path = require('path');
1919
const util = require('util');
2020
const os = require('os');
21-
const removeFolder = require('rimraf');
22-
const mkdtempAsync = util.promisify(fs.mkdtemp);
23-
const removeFolderAsync = util.promisify(removeFolder);
21+
const {mkdtempAsync, removeFolderAsync} = require('./utils');
2422

2523
const {FFOX, CHROMIUM, WEBKIT, HEADLESS} = testOptions;
2624

test/downloadsPath.jest.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@
1616

1717
const path = require('path');
1818
const fs = require('fs');
19-
const util = require('util');
20-
const utils = require('./utils');
2119
const os = require('os');
22-
const removeFolder = require('rimraf');
23-
const mkdtempAsync = util.promisify(fs.mkdtemp);
24-
const removeFolderAsync = util.promisify(removeFolder);
25-
26-
const {FFOX, CHROMIUM, WEBKIT, CHANNEL} = testOptions;
20+
const {mkdtempAsync, removeFolderAsync} = require('./utils');
2721

2822
registerFixture('downloadsPath', async ({}, test) => {
2923
const downloadsPath = await mkdtempAsync(path.join(os.tmpdir(), 'playwright-test-'));

test/utils.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ const removeFolder = require('rimraf');
2424
const {FlakinessDashboard} = require('../utils/flakiness-dashboard');
2525
const PROJECT_ROOT = fs.existsSync(path.join(__dirname, '..', 'package.json')) ? path.join(__dirname, '..') : path.join(__dirname, '..', '..');
2626

27-
const mkdtempAsync = util.promisify(require('fs').mkdtemp);
28-
const removeFolderAsync = util.promisify(removeFolder);
29-
3027
let platform = os.platform();
3128

3229
const utils = module.exports = {
30+
mkdtempAsync: util.promisify(fs.mkdtemp),
31+
32+
removeFolderAsync: util.promisify(removeFolder),
33+
3334
/**
3435
* @return {string}
3536
*/
@@ -180,11 +181,11 @@ const utils = module.exports = {
180181
},
181182

182183
makeUserDataDir: async function() {
183-
return await mkdtempAsync(path.join(os.tmpdir(), 'playwright_dev_profile-'));
184+
return await utils.mkdtempAsync(path.join(os.tmpdir(), 'playwright_dev_profile-'));
184185
},
185186

186187
removeUserDataDir: async function(dir) {
187-
await removeFolderAsync(dir).catch(e => {});
188+
await utils.removeFolderAsync(dir).catch(e => {});
188189
},
189190

190191
testOptions(browserType) {

0 commit comments

Comments
 (0)