Skip to content

Commit

Permalink
flowtype integration_tests/utils.js (jestjs#4261)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronabramov authored Aug 14, 2017
1 parent a8931b9 commit 8226ea7
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions integration_tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/

'use strict';

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

const {spawnSync} = require('child_process');
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');
const rimraf = require('rimraf');

const run = (cmd, cwd) => {
const run = (cmd: string, cwd?: Path) => {
const args = cmd.split(/\s/).slice(1);
const spawnOptions = {cwd};
const result = spawnSync(cmd.split(/\s/)[0], args, spawnOptions);
Expand All @@ -24,7 +29,7 @@ const run = (cmd, cwd) => {
STDOUT: ${result.stdout && result.stdout.toString()}
STDERR: ${result.stderr && result.stderr.toString()}
STATUS: ${result.status}
ERROR: ${result.error}
ERROR: ${result.error && result.error.toString()}
`;
throw new Error(message);
}
Expand All @@ -35,15 +40,15 @@ const run = (cmd, cwd) => {
return result;
};

const linkJestPackage = (packageName, cwd) => {
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/');
run(`mkdir -p ${destination}`);
return run(`ln -sf ${packagePath} ${destination}`);
};

const fileExists = filePath => {
const fileExists = (filePath: Path) => {
try {
fs.accessSync(filePath, fs.F_OK);
return true;
Expand All @@ -52,9 +57,12 @@ const fileExists = filePath => {
}
};

const makeTemplate = string => {
return values => {
return string.replace(/\$(\d+)/g, (match, number) => {
const makeTemplate = (str: string): ((values?: Array<any>) => string) => {
return (values: ?Array<any>) => {
return str.replace(/\$(\d+)/g, (match, number) => {
if (!Array.isArray(values)) {
throw new Error('Array of values must be passed to the template.');
}
return values[number - 1];
});
};
Expand Down Expand Up @@ -102,7 +110,10 @@ const copyDir = (src: string, dest: string) => {
}
};

const createEmptyPackage = (directory, packageJson) => {
const createEmptyPackage = (
directory: Path,
packageJson?: {[keys: string]: any},
) => {
const DEFAULT_PACKAGE_JSON = {
description: 'THIS IS AN AUTOGENERATED FILE AND SHOULD NOT BE ADDED TO GIT',
jest: {
Expand All @@ -118,7 +129,7 @@ const createEmptyPackage = (directory, packageJson) => {
);
};

const extractSummary = stdout => {
const extractSummary = (stdout: string) => {
const match = stdout.match(
/Test Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm,
);
Expand Down

0 comments on commit 8226ea7

Please sign in to comment.