Skip to content

Commit 64f6479

Browse files
committed
Chore: use async/await in tests
1 parent 66fa8ff commit 64f6479

28 files changed

+955
-1089
lines changed

.babelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"presets": ["power-assert"],
3+
"plugins": ["transform-async-to-generator"],
34
"only": "/test/*.js",
45
"sourceMaps": "inline"
56
}

bin/common/parse-cli-args.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ function createPackageConfig() {
4343
return retv
4444
}
4545

46-
Object.keys(process.env).forEach(key => {
46+
for (const key of Object.keys(process.env)) {
4747
const m = PACKAGE_CONFIG_PATTERN.exec(key)
4848
if (m != null) {
4949
overwriteConfig(retv, packageName, m[1], process.env[key])
5050
}
51-
})
51+
}
5252

5353
return retv
5454
}
@@ -62,7 +62,7 @@ function createPackageConfig() {
6262
*/
6363
function addGroup(groups, initialValues) {
6464
groups.push(Object.assign(
65-
{parallel: false, patterns: []},
65+
{ parallel: false, patterns: [] },
6666
initialValues || {}
6767
))
6868
}
@@ -183,7 +183,7 @@ function parseCLIArgsCore(set, args) { // eslint-disable-line complexity
183183
if (set.singleMode) {
184184
throw new Error(`Invalid Option: ${arg}`)
185185
}
186-
addGroup(set.groups, {parallel: true})
186+
addGroup(set.groups, { parallel: true })
187187
break
188188

189189
case "--npm-path":

bin/run-p/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const parseCLIArgs = require("../common/parse-cli-args")
2828
module.exports = function npmRunAll(args, stdout, stderr) {
2929
try {
3030
const stdin = process.stdin
31-
const argv = parseCLIArgs(args, {parallel: true}, {singleMode: true})
31+
const argv = parseCLIArgs(args, { parallel: true }, { singleMode: true })
3232
const group = argv.lastGroup
3333

3434
if (group.patterns.length === 0) {

bin/run-s/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const parseCLIArgs = require("../common/parse-cli-args")
2828
module.exports = function npmRunAll(args, stdout, stderr) {
2929
try {
3030
const stdin = process.stdin
31-
const argv = parseCLIArgs(args, {parallel: false}, {singleMode: true})
31+
const argv = parseCLIArgs(args, { parallel: false }, { singleMode: true })
3232
const group = argv.lastGroup
3333

3434
if (group.patterns.length === 0) {

lib/create-header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports = function createHeader(nameAndArgs, packageInfo, isTTY) {
3838
const packageVersion = packageInfo.body.version
3939
const scriptBody = packageInfo.body.scripts[name]
4040
const packagePath = packageInfo.path
41-
const color = isTTY ? chalk.styles.gray : {open: "", close: ""}
41+
const color = isTTY ? chalk.styles.gray : { open: "", close: "" }
4242

4343
return `
4444
${color.open}> ${packageName}@${packageVersion} ${name} ${packagePath}${color.close}

lib/create-prefix-transform-stream.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ class PrefixTransform extends stream.Transform {
4545
* Transforms the output chunk.
4646
*
4747
* @param {string|Buffer} chunk - A chunk to be transformed.
48-
* @param {string} encoding - The encoding of the chunk.
48+
* @param {string} _encoding - The encoding of the chunk.
4949
* @param {function} callback - A callback function that is called when done.
5050
* @returns {void}
5151
*/
52-
_transform(chunk, encoding, callback) {
52+
_transform(chunk, _encoding, callback) {
5353
const prefix = this.prefix
5454
const nPrefix = `\n${prefix}`
5555
const state = this.state

lib/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ function parsePatterns(patternOrPatterns, args) {
110110
function toOverwriteOptions(config) {
111111
const options = []
112112

113-
Object.keys(config).forEach(packageName => {
113+
for (const packageName of Object.keys(config)) {
114114
const packageConfig = config[packageName]
115115

116-
Object.keys(packageConfig).forEach(variableName => {
116+
for (const variableName of Object.keys(packageConfig)) {
117117
const value = packageConfig[variableName]
118118

119119
options.push(`--${packageName}:${variableName}=${value}`)
120-
})
121-
})
120+
}
121+
}
122122

123123
return options
124124
}
@@ -249,7 +249,7 @@ module.exports = function npmRunAll(patternOrPatterns, options) {
249249
return Promise.resolve()
250250
.then(() => {
251251
if (taskList != null) {
252-
return {taskList, packageInfo: null}
252+
return { taskList, packageInfo: null }
253253
}
254254
return readPackageJson()
255255
})

lib/match-tasks.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const Minimatch = require("minimatch").Minimatch
1717
//------------------------------------------------------------------------------
1818

1919
const COLON_OR_SLASH = /[:/]/g
20-
const CONVERT_MAP = {":": "/", "/": ":"}
20+
const CONVERT_MAP = { ":": "/", "/": ":" }
2121

2222
/**
2323
* Swaps ":" and "/", in order to use ":" as the separator in minimatch.
@@ -46,7 +46,7 @@ function createFilter(pattern) {
4646
const matcher = new Minimatch(swapColonAndSlash(task))
4747
const match = matcher.match.bind(matcher)
4848

49-
return {match, task, args}
49+
return { match, task, args }
5050
}
5151

5252
/**
@@ -97,18 +97,18 @@ module.exports = function matchTasks(taskList, patterns) {
9797
const unknownSet = Object.create(null)
9898

9999
// Take tasks while keep the order of patterns.
100-
filters.forEach(filter => {
100+
for (const filter of filters) {
101101
let found = false
102102

103-
candidates.forEach(candidate => {
103+
for (const candidate of candidates) {
104104
if (filter.match(candidate)) {
105105
found = true
106106
taskSet.add(
107107
swapColonAndSlash(candidate) + filter.args,
108108
filter.task
109109
)
110110
}
111-
})
111+
}
112112

113113
// Built-in tasks should be allowed.
114114
if (!found && (filter.task === "restart" || filter.task === "env")) {
@@ -118,7 +118,7 @@ module.exports = function matchTasks(taskList, patterns) {
118118
if (!found) {
119119
unknownSet[filter.task] = true
120120
}
121-
})
121+
}
122122

123123
const unknownTasks = Object.keys(unknownSet)
124124
if (unknownTasks.length > 0) {

lib/read-package-json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ module.exports = function readPackageJson() {
2626
const path = joinPath(process.cwd(), "package.json")
2727
return readPkg(path).then(body => ({
2828
taskList: Object.keys(body.scripts || {}),
29-
packageInfo: {path, body},
29+
packageInfo: { path, body },
3030
}))
3131
}

lib/run-task.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ const colors = [chalk.cyan, chalk.green, chalk.magenta, chalk.yellow, chalk.red]
3333
function selectColor(taskName) {
3434
let hash = 0
3535

36-
for (const i in taskName) {
37-
hash = ((hash << 5) - hash) + taskName.charCodeAt(i)
36+
for (const c of taskName) {
37+
hash = ((hash << 5) - hash) + c
3838
hash |= 0
3939
}
4040

@@ -124,7 +124,7 @@ module.exports = function runTask(task, options) {
124124
const stdinKind = detectStreamKind(stdin, process.stdin)
125125
const stdoutKind = detectStreamKind(stdout, process.stdout)
126126
const stderrKind = detectStreamKind(stderr, process.stderr)
127-
const spawnOptions = {stdio: [stdinKind, stdoutKind, stderrKind]}
127+
const spawnOptions = { stdio: [stdinKind, stdoutKind, stderrKind] }
128128

129129
// Print task name.
130130
if (options.printName && stdout != null) {
@@ -164,10 +164,10 @@ module.exports = function runTask(task, options) {
164164
stdin.pipe(cp.stdin)
165165
}
166166
if (stdoutKind === "pipe") {
167-
cp.stdout.pipe(stdout, {end: false})
167+
cp.stdout.pipe(stdout, { end: false })
168168
}
169169
if (stderrKind === "pipe") {
170-
cp.stderr.pipe(stderr, {end: false})
170+
cp.stderr.pipe(stderr, { end: false })
171171
}
172172

173173
// Register
@@ -177,7 +177,7 @@ module.exports = function runTask(task, options) {
177177
})
178178
cp.on("close", (code) => {
179179
cp = null
180-
resolve({task, code})
180+
resolve({ task, code })
181181
})
182182
})
183183

0 commit comments

Comments
 (0)