|
|
@@ -20,7 +20,7 @@ describe('npm-installed CLI commands', () => {
|
|
|
const launchAgents = join(root, 'Library', 'LaunchAgents')
|
|
|
mkdirSync(launchAgents, { recursive: true })
|
|
|
plist = join(launchAgents, `${label}.plist`)
|
|
|
- for (const name of ['yaoyao', 'hermes-yaoyao']) symlinkSync(entry, join(bin, name))
|
|
|
+ symlinkSync(entry, join(bin, 'yaoyao'))
|
|
|
writeFileSync(join(bin, 'launchctl'), `#!${process.execPath}
|
|
|
import { appendFileSync } from 'node:fs'
|
|
|
const args = process.argv.slice(2)
|
|
|
@@ -35,8 +35,8 @@ if (args[0] === 'print' && process.env.YAOYAO_CLI_TEST_LOADED !== '1') process.e
|
|
|
|
|
|
afterEach(() => { rmSync(root, { recursive: true, force: true }) })
|
|
|
|
|
|
- function runCli(args: string[], env: NodeJS.ProcessEnv = {}, name = 'yaoyao') {
|
|
|
- return spawnSync(process.execPath, [join(root, 'bin', name), ...args], {
|
|
|
+ function runCli(args: string[], env: NodeJS.ProcessEnv = {}) {
|
|
|
+ return spawnSync(process.execPath, [join(root, 'bin', 'yaoyao'), ...args], {
|
|
|
cwd: root,
|
|
|
encoding: 'utf8',
|
|
|
timeout: 5_000,
|
|
|
@@ -57,24 +57,22 @@ if (args[0] === 'print' && process.env.YAOYAO_CLI_TEST_LOADED !== '1') process.e
|
|
|
return existsSync(log) ? readFileSync(log, 'utf8').trim().split('\n').map(line => JSON.parse(line)) : []
|
|
|
}
|
|
|
|
|
|
- it.each(['version', '--version', '-v'])('queries the package version through both npm bin aliases: %s', command => {
|
|
|
- for (const name of ['yaoyao', 'hermes-yaoyao']) {
|
|
|
- const result = runCli([command], {}, name)
|
|
|
- expect(result.status).toBe(0)
|
|
|
- expect(result.stdout).toBe(`${version}\n`)
|
|
|
- expect(result.stderr).toBe('')
|
|
|
- }
|
|
|
+ it.each(['version', '--version', '-v'])('queries the package version through yaoyao: %s', command => {
|
|
|
+ const result = runCli([command])
|
|
|
+ expect(result.status).toBe(0)
|
|
|
+ expect(result.stdout).toBe(`${version}\n`)
|
|
|
+ expect(result.stderr).toBe('')
|
|
|
expect(calls()).toEqual([])
|
|
|
expect(existsSync(join(root, 'data'))).toBe(false)
|
|
|
})
|
|
|
|
|
|
- it.each(['yaoyao', 'hermes-yaoyao'])('restarts the installed service through %s while preserving its configuration and data', name => {
|
|
|
+ it('restarts the installed service while preserving its configuration and data', () => {
|
|
|
writeFileSync(plist, 'saved service configuration')
|
|
|
mkdirSync(join(root, 'data'))
|
|
|
const data = join(root, 'data', 'keep.txt')
|
|
|
writeFileSync(data, 'saved user data')
|
|
|
|
|
|
- const result = runCli(['service', 'restart'], { YAOYAO_CLI_TEST_LOADED: '1' }, name)
|
|
|
+ const result = runCli(['service', 'restart'], { YAOYAO_CLI_TEST_LOADED: '1' })
|
|
|
|
|
|
expect(result.status).toBe(0)
|
|
|
expect(result.stdout).toBe(`已重启 ${label}\n`)
|