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

flowtype integration_tests/utils.js #4261

Merged
Merged
Changes from all 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
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