From f74a3ef8008247629dbaf11d300f5e1611ccd217 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 11 Jan 2019 18:08:24 +0100 Subject: [PATCH] chore: use creatDirectory from jest-util when creating directories --- e2e/Utils.js | 10 +++++----- e2e/__tests__/globalTeardown.test.js | 4 ++-- e2e/global-setup/project-1/setup.js | 4 ++-- e2e/global-setup/project-2/setup.js | 4 ++-- e2e/global-setup/setup.js | 4 ++-- e2e/global-teardown/project-1/teardown.js | 4 ++-- e2e/global-teardown/project-2/teardown.js | 4 ++-- e2e/global-teardown/teardown.js | 4 ++-- e2e/test-environment-async/TestEnvironment.js | 4 ++-- scripts/build.js | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/e2e/Utils.js b/e2e/Utils.js index c99ae907ce33..fd845622a45f 100644 --- a/e2e/Utils.js +++ b/e2e/Utils.js @@ -14,7 +14,7 @@ import type {Path} from 'types/Config'; import {sync as spawnSync} from 'execa'; import fs from 'fs'; import path from 'path'; -import mkdirp from 'mkdirp'; +import {createDirectory} from 'jest-util'; import rimraf from 'rimraf'; export const run = (cmd: string, cwd?: Path) => { @@ -43,7 +43,7 @@ export const linkJestPackage = (packageName: string, cwd: Path) => { const packagesDir = path.resolve(__dirname, '../packages'); const packagePath = path.resolve(packagesDir, packageName); const destination = path.resolve(cwd, 'node_modules/', packageName); - mkdirp.sync(destination); + createDirectory(destination); rimraf.sync(destination); fs.symlinkSync(packagePath, destination, 'dir'); }; @@ -74,13 +74,13 @@ export const writeFiles = ( directory: string, files: {[filename: string]: string}, ) => { - mkdirp.sync(directory); + createDirectory(directory); Object.keys(files).forEach(fileOrPath => { const filePath = fileOrPath.split('/'); // ['tmp', 'a.js'] const filename = filePath.pop(); // filepath becomes dirPath (no filename) if (filePath.length) { - mkdirp.sync(path.join.apply(path, [directory].concat(filePath))); + createDirectory(path.join.apply(path, [directory].concat(filePath))); } fs.writeFileSync( path.resolve.apply(path, [directory].concat(filePath, [filename])), @@ -128,7 +128,7 @@ export const createEmptyPackage = ( }, }; - mkdirp.sync(directory); + createDirectory(directory); packageJson || (packageJson = DEFAULT_PACKAGE_JSON); fs.writeFileSync( path.resolve(directory, 'package.json'), diff --git a/e2e/__tests__/globalTeardown.test.js b/e2e/__tests__/globalTeardown.test.js index 8f776ae30e8e..0f83b55c8e65 100644 --- a/e2e/__tests__/globalTeardown.test.js +++ b/e2e/__tests__/globalTeardown.test.js @@ -8,7 +8,7 @@ 'use strict'; import fs from 'fs'; -import mkdirp from 'mkdirp'; +import {createDirectory} from 'jest-util'; import os from 'os'; import path from 'path'; import runJest, {json as runWithJson} from '../runJest'; @@ -30,7 +30,7 @@ afterAll(() => { }); test('globalTeardown is triggered once after all test suites', () => { - mkdirp.sync(DIR); + createDirectory(DIR); const teardownPath = path.resolve( __dirname, '../global-teardown/teardown.js', diff --git a/e2e/global-setup/project-1/setup.js b/e2e/global-setup/project-1/setup.js index 51e0ce22576f..f5374c480b30 100644 --- a/e2e/global-setup/project-1/setup.js +++ b/e2e/global-setup/project-1/setup.js @@ -6,7 +6,7 @@ */ const crypto = require('crypto'); const fs = require('fs'); -const mkdirp = require('mkdirp'); +const {createDirectory} = require('jest-util'); const os = require('os'); const path = require('path'); @@ -14,7 +14,7 @@ const DIR = path.join(os.tmpdir(), 'jest-global-setup-project-1'); module.exports = function() { return new Promise((resolve, reject) => { - mkdirp.sync(DIR); + createDirectory(DIR); const fileId = crypto.randomBytes(20).toString('hex'); fs.writeFileSync(path.join(DIR, fileId), 'setup'); resolve(); diff --git a/e2e/global-setup/project-2/setup.js b/e2e/global-setup/project-2/setup.js index 3f57e1cec83b..383f473c424e 100644 --- a/e2e/global-setup/project-2/setup.js +++ b/e2e/global-setup/project-2/setup.js @@ -6,7 +6,7 @@ */ const crypto = require('crypto'); const fs = require('fs'); -const mkdirp = require('mkdirp'); +const {createDirectory} = require('jest-util'); const os = require('os'); const path = require('path'); @@ -14,7 +14,7 @@ const DIR = path.join(os.tmpdir(), 'jest-global-setup-project-2'); module.exports = function() { return new Promise((resolve, reject) => { - mkdirp.sync(DIR); + createDirectory(DIR); const fileId = crypto.randomBytes(20).toString('hex'); fs.writeFileSync(path.join(DIR, fileId), 'setup'); resolve(); diff --git a/e2e/global-setup/setup.js b/e2e/global-setup/setup.js index 79a7ed3c2c24..94c420cd1be3 100644 --- a/e2e/global-setup/setup.js +++ b/e2e/global-setup/setup.js @@ -6,7 +6,7 @@ */ const crypto = require('crypto'); const fs = require('fs'); -const mkdirp = require('mkdirp'); +const {createDirectory} = require('jest-util'); const os = require('os'); const path = require('path'); @@ -14,7 +14,7 @@ const DIR = path.join(os.tmpdir(), 'jest-global-setup'); module.exports = function() { return new Promise((resolve, reject) => { - mkdirp.sync(DIR); + createDirectory(DIR); const fileId = crypto.randomBytes(20).toString('hex'); fs.writeFileSync(path.join(DIR, fileId), 'setup'); resolve(); diff --git a/e2e/global-teardown/project-1/teardown.js b/e2e/global-teardown/project-1/teardown.js index 13f842d15c14..d153236c1e7c 100644 --- a/e2e/global-teardown/project-1/teardown.js +++ b/e2e/global-teardown/project-1/teardown.js @@ -6,7 +6,7 @@ */ const crypto = require('crypto'); const fs = require('fs'); -const mkdirp = require('mkdirp'); +const {createDirectory} = require('jest-util'); const os = require('os'); const path = require('path'); @@ -14,7 +14,7 @@ const DIR = path.join(os.tmpdir(), 'jest-global-teardown-project-1'); module.exports = function() { return new Promise((resolve, reject) => { - mkdirp.sync(DIR); + createDirectory(DIR); const fileId = crypto.randomBytes(20).toString('hex'); fs.writeFileSync(path.join(DIR, fileId), 'teardown'); resolve(); diff --git a/e2e/global-teardown/project-2/teardown.js b/e2e/global-teardown/project-2/teardown.js index 97aeedc4e592..95eb1b32a6b0 100644 --- a/e2e/global-teardown/project-2/teardown.js +++ b/e2e/global-teardown/project-2/teardown.js @@ -6,7 +6,7 @@ */ const crypto = require('crypto'); const fs = require('fs'); -const mkdirp = require('mkdirp'); +const {createDirectory} = require('jest-util'); const os = require('os'); const path = require('path'); @@ -14,7 +14,7 @@ const DIR = path.join(os.tmpdir(), 'jest-global-teardown-project-2'); module.exports = function() { return new Promise((resolve, reject) => { - mkdirp.sync(DIR); + createDirectory(DIR); const fileId = crypto.randomBytes(20).toString('hex'); fs.writeFileSync(path.join(DIR, fileId), 'teardown'); resolve(); diff --git a/e2e/global-teardown/teardown.js b/e2e/global-teardown/teardown.js index c318daacf16b..e5c4d27a9b62 100644 --- a/e2e/global-teardown/teardown.js +++ b/e2e/global-teardown/teardown.js @@ -6,7 +6,7 @@ */ const crypto = require('crypto'); const fs = require('fs'); -const mkdirp = require('mkdirp'); +const {createDirectory} = require('jest-util'); const os = require('os'); const path = require('path'); @@ -14,7 +14,7 @@ const DIR = path.join(os.tmpdir(), 'jest-global-teardown'); module.exports = function() { return new Promise((resolve, reject) => { - mkdirp.sync(DIR); + createDirectory(DIR); const fileId = crypto.randomBytes(20).toString('hex'); fs.writeFileSync(path.join(DIR, fileId), 'teardown'); resolve(); diff --git a/e2e/test-environment-async/TestEnvironment.js b/e2e/test-environment-async/TestEnvironment.js index 88182fb04b4f..c33865fe673d 100644 --- a/e2e/test-environment-async/TestEnvironment.js +++ b/e2e/test-environment-async/TestEnvironment.js @@ -4,7 +4,7 @@ const fs = require('fs'); const os = require('os'); -const mkdirp = require('mkdirp'); +const {createDirectory} = require('jest-util'); const JSDOMEnvironment = require('jest-environment-jsdom'); const DIR = os.tmpdir() + '/jest-test-environment'; @@ -24,7 +24,7 @@ class TestEnvironment extends JSDOMEnvironment { teardown() { return super.teardown().then(() => { - mkdirp.sync(DIR); + createDirectory(DIR); fs.writeFileSync(DIR + '/teardown', 'teardown'); }); } diff --git a/scripts/build.js b/scripts/build.js index 243df45bc3ba..2dd1420aceca 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -133,7 +133,7 @@ function buildFile(file, silent) { return; } - mkdirp.sync(path.dirname(destPath)); + mkdirp.sync(path.dirname(destPath), '777'); if (!micromatch.isMatch(file, JS_FILES_PATTERN)) { fs.createReadStream(file).pipe(fs.createWriteStream(destPath)); silent ||