Skip to content

Commit 1f10c88

Browse files
Sebastian McKenziebestander
Sebastian McKenzie
authored andcommitted
Enable Flow types on tests (#140)
* enable flow types on tests * add ava.babel = "inherit" config
1 parent 0e819a8 commit 1f10c88

19 files changed

+70
-26
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"test": "make test"
6868
},
6969
"ava": {
70+
"babel": "inherit",
7071
"require": [
7172
"./test/_register.js"
7273
]

src/fetchers/_base.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import * as fs from "../util/fs.js";
2020
let path = require("path");
2121

2222
export default class BaseFetcher {
23-
constructor(remote: PackageRemote, config: Config, saveForOffline: boolean) {
23+
constructor(remote: PackageRemote, config: Config, saveForOffline?: boolean) {
2424
this.reference = remote.reference;
2525
this.registry = remote.registry;
2626
this.hash = remote.hash;
2727
this.config = config;
28-
this.saveForOffline = saveForOffline;
28+
this.saveForOffline = !!saveForOffline;
2929
}
3030

3131
registry: RegistryNames;

src/fetchers/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* @flow
1010
*/
1111

12-
export { default as git } from "./git";
13-
export { default as copy } from "./copy";
14-
export { default as tarball } from "./tarball";
12+
export { default as base } from "./_base.js";
13+
export { default as git } from "./git.js";
14+
export { default as copy } from "./copy.js";
15+
export { default as tarball } from "./tarball.js";

src/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export type PersonObject = {
3131

3232
// package remote that's used to store how to fetch a package
3333
export type PackageRemote = {
34-
type: "tarball" | "git" | "copy",
34+
type: "tarball" | "git" | "copy" | "base",
3535
registry: RegistryNames,
3636
reference: string,
3737
resolved?: ?string,

src/util/normalise-manifest/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function normalisePerson(person: mixed): mixed | PersonObject {
6161
return parsePerson(stringifyPerson(person));
6262
}
6363

64-
export function extractDescription(readme: string): ?string {
64+
export function extractDescription(readme: ?string): ?string {
6565
if (!readme) return;
6666

6767
// split into lines

test/_temp.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @flow
810
*/
911

1012
let temp = require("temp").track();
1113

12-
export default function (filename: string): Promise<string> {
14+
export default function (filename?: string): Promise<string> {
1315
return new Promise((resolve, reject) => {
1416
temp.mkdir(filename, function (err, path) {
1517
if (err) {

test/commands/install.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @flow
810
*/
911

12+
import { Reporter } from "../../src/reporters/index.js";
1013
import * as reporters from "../../src/reporters/index.js";
1114
import * as constants from "../../src/constants.js";
1215
import { default as Lockfile, parse } from "../../src/lockfile/index.js";
@@ -18,8 +21,8 @@ import assert from "assert";
1821
import semver from "semver";
1922

2023
let stream = require("stream");
21-
let test = require("ava");
22-
let path = require("path");
24+
let test = require("ava");
25+
let path = require("path");
2326

2427
let fixturesLoc = path.join(__dirname, "..", "fixtures", "install");
2528

@@ -41,7 +44,13 @@ async function createLockfile(dir, strict, save) {
4144
return new Lockfile(lockfile, strict, save);
4245
}
4346

44-
async function run(flags, args, name, checkInstalled, beforeInstall) {
47+
async function run(
48+
flags: Object,
49+
args: Array<string>,
50+
name: string,
51+
checkInstalled: ?(config: Config, reporter: Reporter) => ?Promise<void>,
52+
beforeInstall: ?(cwd: string) => ?Promise<void>
53+
) {
4554
let out = "";
4655
let stdout = new stream.Writable({
4756
write(data) {
@@ -117,7 +126,6 @@ test("[network] install with arg that has binaries", () => {
117126
test("[network] install with --save and offline mirror", () => {
118127
let mirrorPath = "mirror-for-offline";
119128
return run({save: true}, ["is-array@1.0.1"], "install-with-save-offline-mirror", async (config) => {
120-
121129
let allFiles = await fs.walk(config.cwd);
122130

123131
assert(allFiles.findIndex((file) => {
@@ -131,7 +139,6 @@ test("[network] install with --save and offline mirror", () => {
131139

132140
await fs.unlink(path.join(config.cwd, mirrorPath));
133141
await fs.unlink(path.join(config.cwd, "package.json"));
134-
return allFiles;
135142
});
136143
});
137144

@@ -152,7 +159,6 @@ test("[network] install with --save and without offline mirror", () => {
152159

153160
await fs.unlink(path.join(config.cwd, mirrorPath));
154161
await fs.unlink(path.join(config.cwd, "package.json"));
155-
return allFiles;
156162
});
157163
});
158164

@@ -164,8 +170,6 @@ test("install from offline mirror", () => {
164170
assert(allFiles.findIndex((file) => {
165171
return file.relative === "node_modules/fake-fbkpm-dependency/package.json";
166172
}) !== -1);
167-
168-
return allFiles;
169173
});
170174
});
171175

test/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @flow
810
*/
911

1012
import { getPathKey } from "../src/constants.js";

test/fetchers.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,33 @@
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @flow
810
*/
911
/* eslint max-len: 0 */
1012

11-
import TarballFetcher from "../src/fetchers/tarball";
12-
import BaseFetcher from "../src/fetchers/_base";
13-
import CopyFetcher from "../src/fetchers/copy";
14-
import GitFetcher from "../src/fetchers/git";
15-
import Config from "../src/config";
13+
import TarballFetcher from "../src/fetchers/tarball.js";
14+
import BaseFetcher from "../src/fetchers/_base.js";
15+
import CopyFetcher from "../src/fetchers/copy.js";
16+
import GitFetcher from "../src/fetchers/git.js";
17+
import { NoopReporter } from "../src/reporters/index.js";
18+
import Config from "../src/config.js";
1619
import mkdir from "./_temp.js";
1720
import * as fs from "../src/util/fs.js";
1821

1922
let path = require("path");
2023
let test = require("ava");
2124

2225
async function createConfig() {
23-
let config = new Config;
26+
let config = new Config(new NoopReporter);
2427
await config.init();
2528
return config;
2629
}
2730

2831
test("BaseFetcher.fetch", async (t) => {
2932
let dir = await mkdir("base-fetcher");
3033
let fetcher = new BaseFetcher({
31-
type: "",
34+
type: "base",
3235
registry: "npm",
3336
reference: ""
3437
}, await createConfig());

test/lockfile.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @flow
810
*/
911
/* eslint quotes: 0 */
1012

@@ -140,7 +142,9 @@ test("Lockfile.getLockfile", (t) => {
140142
resolved: "http://example.com/barfoo",
141143
registry: "bower"
142144
}
143-
}
145+
},
146+
147+
foobar2: {}
144148
};
145149

146150
patterns.foobar2 = patterns.foobar;
@@ -194,6 +198,8 @@ test("Lockfile.getLockfile (sorting)", (t) => {
194198
registry: "npm"
195199
}
196200
},
201+
202+
foobar1: {}
197203
};
198204

199205
patterns.foobar1 = patterns.foobar2;

test/normalise-manifest.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @flow
810
*/
911
/* eslint max-len: 0 */
1012

test/package-resolver.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @flow
810
*/
911
/* eslint max-len: 0 */
1012

test/reporters/_mock.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,34 @@
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @flow
810
*/
911

1012
let Stdin = require("mock-stdin").stdin.Class;
1113
let { Writable } = require("stream");
1214

1315
export default function (Reporter: Function, interceptor: Function) {
14-
return async function (callback) {
16+
return async function (
17+
callback: (reporter: Reporter, opts: Object) => ?Promise<void>
18+
) {
1519
let data = {
1620
stderr: "",
1721
stdout: ""
1822
};
1923

2024
let buildStream = (key) => {
2125
let stream = new Writable;
26+
27+
// $FlowFixMe: TODO add to flow definition
2228
stream.columns = 1000;
29+
30+
// $FlowFixMe: TODO ditto
2331
stream.write = (msg) => {
2432
stream.emit("data", msg);
2533
data[key] += msg;
2634
};
35+
2736
return stream;
2837
};
2938

test/reporters/base.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @flow
810
*/
911

1012
import BaseReporter from "../../lib/reporters/_base.js";

test/reporters/buffer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @flow
810
*/
911

1012
import BufferReporter from "../../lib/reporters/buffer.js";

test/reporters/console.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @flow
810
*/
911

1012
import ProgressBar from "../../lib/reporters/console/progress-bar.js";

test/reporters/json.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @flow
810
*/
911
/* eslint quotes: 0 */
1012

test/util/blocking-queue.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @flow
810
*/
911

1012
import BlockingQueue from "../../src/util/blocking-queue.js";
@@ -18,7 +20,7 @@ test("max concurrency", async function () {
1820
let running = 0;
1921

2022
function create() {
21-
return queue.push(++i, async function () {
23+
return queue.push(++i + "", async function () {
2224
running++;
2325
await wait(100);
2426

test/util/promise.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* This source code is licensed under the BSD-style license found in the
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @flow
810
*/
911

1012
import * as promise from "../../src/util/promise.js";

0 commit comments

Comments
 (0)