Skip to content

Commit 5ead922

Browse files
authored
flowtype integration_tests/utils.js (#4261)
1 parent 34f6d3a commit 5ead922

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

integration_tests/utils.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44
* This source code is licensed under the BSD-style license found in the
55
* LICENSE file in the root directory of this source tree. An additional grant
66
* of patent rights can be found in the PATENTS file in the same directory.
7+
*
8+
* @flow
79
*/
10+
811
'use strict';
912

13+
import type {Path} from 'types/Config';
14+
1015
const {spawnSync} = require('child_process');
1116
const fs = require('fs');
1217
const path = require('path');
1318
const mkdirp = require('mkdirp');
1419
const rimraf = require('rimraf');
1520

16-
const run = (cmd, cwd) => {
21+
const run = (cmd: string, cwd?: Path) => {
1722
const args = cmd.split(/\s/).slice(1);
1823
const spawnOptions = {cwd};
1924
const result = spawnSync(cmd.split(/\s/)[0], args, spawnOptions);
@@ -24,7 +29,7 @@ const run = (cmd, cwd) => {
2429
STDOUT: ${result.stdout && result.stdout.toString()}
2530
STDERR: ${result.stderr && result.stderr.toString()}
2631
STATUS: ${result.status}
27-
ERROR: ${result.error}
32+
ERROR: ${result.error && result.error.toString()}
2833
`;
2934
throw new Error(message);
3035
}
@@ -35,15 +40,15 @@ const run = (cmd, cwd) => {
3540
return result;
3641
};
3742

38-
const linkJestPackage = (packageName, cwd) => {
43+
const linkJestPackage = (packageName: string, cwd: Path) => {
3944
const packagesDir = path.resolve(__dirname, '../packages');
4045
const packagePath = path.resolve(packagesDir, packageName);
4146
const destination = path.resolve(cwd, 'node_modules/');
4247
run(`mkdir -p ${destination}`);
4348
return run(`ln -sf ${packagePath} ${destination}`);
4449
};
4550

46-
const fileExists = filePath => {
51+
const fileExists = (filePath: Path) => {
4752
try {
4853
fs.accessSync(filePath, fs.F_OK);
4954
return true;
@@ -52,9 +57,12 @@ const fileExists = filePath => {
5257
}
5358
};
5459

55-
const makeTemplate = string => {
56-
return values => {
57-
return string.replace(/\$(\d+)/g, (match, number) => {
60+
const makeTemplate = (str: string): ((values?: Array<any>) => string) => {
61+
return (values: ?Array<any>) => {
62+
return str.replace(/\$(\d+)/g, (match, number) => {
63+
if (!Array.isArray(values)) {
64+
throw new Error('Array of values must be passed to the template.');
65+
}
5866
return values[number - 1];
5967
});
6068
};
@@ -102,7 +110,10 @@ const copyDir = (src: string, dest: string) => {
102110
}
103111
};
104112

105-
const createEmptyPackage = (directory, packageJson) => {
113+
const createEmptyPackage = (
114+
directory: Path,
115+
packageJson?: {[keys: string]: any},
116+
) => {
106117
const DEFAULT_PACKAGE_JSON = {
107118
description: 'THIS IS AN AUTOGENERATED FILE AND SHOULD NOT BE ADDED TO GIT',
108119
jest: {
@@ -118,7 +129,7 @@ const createEmptyPackage = (directory, packageJson) => {
118129
);
119130
};
120131

121-
const extractSummary = stdout => {
132+
const extractSummary = (stdout: string) => {
122133
const match = stdout.match(
123134
/Test Suites:.*\nTests.*\nSnapshots.*\nTime.*(\nRan all test suites)*.*\n*$/gm,
124135
);

0 commit comments

Comments
 (0)