Skip to content

Commit

Permalink
chore: use creatDirectory from jest-util when creating directories
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Jan 11, 2019
1 parent 4f2bcb8 commit f74a3ef
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions e2e/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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');
};
Expand Down Expand Up @@ -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])),
Expand Down Expand Up @@ -128,7 +128,7 @@ export const createEmptyPackage = (
},
};

mkdirp.sync(directory);
createDirectory(directory);
packageJson || (packageJson = DEFAULT_PACKAGE_JSON);
fs.writeFileSync(
path.resolve(directory, 'package.json'),
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/globalTeardown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions e2e/global-setup/project-1/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
*/
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');

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();
Expand Down
4 changes: 2 additions & 2 deletions e2e/global-setup/project-2/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
*/
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');

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();
Expand Down
4 changes: 2 additions & 2 deletions e2e/global-setup/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
*/
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');

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();
Expand Down
4 changes: 2 additions & 2 deletions e2e/global-teardown/project-1/teardown.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
*/
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');

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();
Expand Down
4 changes: 2 additions & 2 deletions e2e/global-teardown/project-2/teardown.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
*/
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');

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();
Expand Down
4 changes: 2 additions & 2 deletions e2e/global-teardown/teardown.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
*/
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');

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();
Expand Down
4 changes: 2 additions & 2 deletions e2e/test-environment-async/TestEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -24,7 +24,7 @@ class TestEnvironment extends JSDOMEnvironment {

teardown() {
return super.teardown().then(() => {
mkdirp.sync(DIR);
createDirectory(DIR);
fs.writeFileSync(DIR + '/teardown', 'teardown');
});
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down

0 comments on commit f74a3ef

Please sign in to comment.