Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use createDirectory from jest-util when creating directories #7610

Merged
merged 5 commits into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ jobs:
- store_test_results:
path: reports/junit

test-jest-workers:
working_directory: ~/jest
docker:
- image: circleci/node:10
steps:
- checkout
- restore-cache: *restore-cache
- run: yarn --no-progress
- save-cache: *save-cache
- run:
command: NODE_OPTIONS=--experimental-worker yarn test-ci-partial
- store_test_results:
path: reports/junit

test-node-11:
working_directory: ~/jest
docker:
Expand Down Expand Up @@ -136,6 +150,7 @@ workflows:
- test-node-8
- test-node-10
- test-jest-circus
- test-jest-workers
- test-node-11 # current
- test-browser
- test-or-deploy-website:
Expand Down
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
22 changes: 22 additions & 0 deletions packages/jest-util/src/createDirectory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import type {Path} from 'types/Config';

import mkdirp from 'mkdirp';

export default function createDirectory(path: Path) {
try {
mkdirp.sync(path, '777');
} catch (e) {
if (e.code !== 'EEXIST') {
throw e;
}
}
}
13 changes: 1 addition & 12 deletions packages/jest-util/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
* @flow
*/

import mkdirp from 'mkdirp';

import BufferedConsole from './BufferedConsole';
import clearLine from './clearLine';
import CustomConsole from './CustomConsole';
import createDirectory from './createDirectory';
import ErrorWithStack from './ErrorWithStack';
import FakeTimers from './FakeTimers';
import formatTestResults from './formatTestResults';
Expand All @@ -26,16 +25,6 @@ import deepCyclicCopy from './deepCyclicCopy';
import convertDescriptorToString from './convertDescriptorToString';
import * as specialChars from './specialChars';

const createDirectory = (path: string) => {
try {
mkdirp.sync(path, '777');
} catch (e) {
if (e.code !== 'EEXIST') {
throw e;
}
}
};

module.exports = {
BufferedConsole,
Console: CustomConsole,
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