Skip to content

Commit 5647f97

Browse files
DrRataplanline-o
authored andcommitted
test: add tests for installing from a registry
1 parent 6252156 commit 5647f97

File tree

5 files changed

+304
-34
lines changed

5 files changed

+304
-34
lines changed

commands/package/install/local.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ const options = {
8787
alias: 'rpc',
8888
describe: 'force upload over XML-RPC API',
8989
boolean: true
90-
},
91-
v: {
92-
alias: 'verbose',
93-
describe: 'Display more information',
94-
boolean: true
9590
}
9691
}
9792

commands/package/install/registry.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,9 @@ export const builder = yargs => {
1717
string: true
1818
})
1919
.positional('package', {
20-
describe: 'The NAME of the package to install',
20+
describe: "The package's name or its abbrev",
2121
string: true
2222
})
23-
.options({
24-
v: {
25-
alias: 'verbose',
26-
describe: 'Display more information',
27-
boolean: true
28-
}
29-
}
30-
)
3123
}
3224

3325
export async function handler (argv) {
@@ -60,15 +52,18 @@ export async function handler (argv) {
6052

6153
const { success, result } = await installFromRepo(db, {
6254
publicRepoURL: registry,
63-
packageName: argv.package,
64-
version: argv.version
55+
nameOrAbbrev: argv.package,
56+
version: argv.version,
57+
verbose
6558
})
6659

6760
if (!success) {
68-
throw new Error(`${fail} ${chalk.dim(argv.package)} > could not be installed `)
61+
throw new Error(`${fail} ${chalk.dim(argv.package)} > ${result}`)
6962
}
7063

71-
logSuccess(`${chalk.dim(argv.package)} > installed ${result.version === '' ? 'latest version' : 'version ' + result.version} at ${result.target}`)
64+
logSuccess(
65+
`${chalk.dim(argv.package)} > installed ${result.version === '' ? 'latest version' : 'version ' + result.version} at ${result.target}`
66+
)
7267

7368
return 0
7469
}

modules/install-from-repo.xq

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ try {
4545
"version": $version,
4646
"target": $installation/@target/string()
4747
}
48-
},
48+
},
4949
map { "method": "json" }
5050
)
5151
}
@@ -61,7 +61,7 @@ catch * {
6161
"line": $err:line-number
6262
(: "column": $err:column :)
6363
}
64-
},
64+
},
6565
map { "method": "json" }
6666
)
6767
}

spec/test.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
import { spawn } from 'node:child_process'
22

3+
/**
4+
* Run an XST command
5+
*
6+
* @param {string} cmd - The command
7+
* @param {string[]} cmd - The arguments
8+
* @param {Record<string, unknown>} [options] - Any options to the command, like environment variables
9+
* @returns {Promise<{stderr?: string, stdout?: string, code: number}>} The result of running the command
10+
*/
311
export async function run (cmd, args, options) {
412
return new Promise((resolve, reject) => {
513
let stderr
614
let stdout
715
const proc = spawn(cmd, args, options)
8-
proc.stdout.on('data', data => {
9-
stdout ? stdout += data.toString() : stdout = data.toString()
16+
proc.stdout.on('data', (data) => {
17+
stdout ? (stdout += data.toString()) : (stdout = data.toString())
1018
})
1119

12-
proc.stderr.on('data', data => {
13-
stderr ? stderr += data.toString() : stderr = data.toString()
20+
proc.stderr.on('data', (data) => {
21+
stderr ? (stderr += data.toString()) : (stderr = data.toString())
1422
})
15-
proc.on('error', error => {
23+
proc.on('error', (error) => {
1624
reject(error)
1725
})
18-
proc.on('close', code => {
26+
proc.on('close', (code) => {
1927
resolve({ stderr, stdout, code })
2028
})
2129
})
@@ -29,20 +37,22 @@ export async function runPipe (cmd1, args1, cmd2, args2, options) {
2937
const proc2 = spawn(cmd2, args2, options)
3038
proc1.stdout.pipe(proc2.stdin)
3139

32-
proc2.stdout.on('data', data => {
33-
stdout ? stdout += data.toString() : stdout = data.toString()
40+
proc2.stdout.on('data', (data) => {
41+
stdout ? (stdout += data.toString()) : (stdout = data.toString())
3442
})
3543

36-
proc2.stderr.on('data', data => {
37-
stderr ? stderr += data.toString() : stderr = data.toString()
44+
proc2.stderr.on('data', (data) => {
45+
stderr ? (stderr += data.toString()) : (stderr = data.toString())
3846
})
39-
proc2.on('close', _ => resolve({ stderr, stdout }))
40-
proc1.on('error', error => reject(error))
41-
proc2.on('error', error => reject(error))
47+
proc2.on('close', (_) => resolve({ stderr, stdout }))
48+
proc1.on('error', (error) => reject(error))
49+
proc2.on('error', (error) => reject(error))
4250
})
4351
}
4452

45-
export const asAdmin = { env: { ...process.env, EXISTDB_USER: 'admin', EXISTDB_PASS: '' } }
53+
export const asAdmin = {
54+
env: { ...process.env, EXISTDB_USER: 'admin', EXISTDB_PASS: '' }
55+
}
4656
export function forceColorLevel (level) {
4757
return { env: { ...process.env, FORCE_COLOR: level } }
4858
}

0 commit comments

Comments
 (0)