Skip to content

Commit de23fcf

Browse files
committed
refactor: pipe command
1 parent 0b63a0d commit de23fcf

File tree

2 files changed

+18
-38
lines changed

2 files changed

+18
-38
lines changed

commands/CredentialsPipe.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,12 @@ export default class CredentialsPipe extends BaseCommand {
3535
const [command, ...params] = this.command?.split(' ')
3636
const credentialsPath = this.application.resourcesPath('credentials')
3737

38-
if (!fs.existsSync(`${credentialsPath}/${env}.key`)) {
39-
this.logger.error(`Credentials key file for '${env}' environment does not exist`)
40-
return
41-
}
42-
43-
if (!fs.existsSync(`${credentialsPath}/${env}.credentials`)) {
44-
this.logger.error(`Credentials file for '${env}' environment does not exist`)
45-
return
46-
}
47-
48-
const credentials = new Credentials({ env, credentialsPath })
38+
const credentials = new Credentials({ env, credentialsPath }).get()
4939

5040
try {
5141
await execa.node(command, [...params], {
5242
stdio: 'inherit',
53-
env: { ...(credentials.get() as Record<string, string>) },
43+
env: { ...(credentials as Record<string, string>) },
5444
})
5545
} catch (error) {
5646
console.log(error)

test/credentials-pipe.spec.ts

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,30 @@ test.group('Command - Credentials Pipe', (group) => {
3535

3636
const command = new CredentialsPipe(app, new Kernel(app))
3737
command.command = `echo 'test';`
38-
await command.run()
3938

40-
assert.deepStrictEqual(
41-
command.ui.testingRenderer.logs.map((log) => ({
42-
...log,
43-
message: log.message.replace(/(\[.*?\])/g, '').trim(),
44-
})),
45-
[
46-
{
47-
stream: 'stderr',
48-
message: `Credentials key file for 'test' environment does not exist`,
49-
},
50-
]
51-
)
39+
try {
40+
await command.run()
41+
} catch (error) {
42+
assert.equal(
43+
error.message,
44+
`E_CREDENTIALS_NO_KEY: Credentials key for 'test' environment does not exist, please set it in a file or in APP_CREDENTIALS_KEY environment variable`
45+
)
46+
}
5247
})
5348

5449
test('should throw an error when credentials file does not exist', async (assert) => {
5550
await fs.remove('resources/credentials/test.credentials')
5651

5752
const command = new CredentialsPipe(app, new Kernel(app))
5853
command.command = `echo 'test';`
59-
await command.run()
6054

61-
assert.deepStrictEqual(
62-
command.ui.testingRenderer.logs.map((log) => ({
63-
...log,
64-
message: log.message.replace(/(\[.*?\])/g, '').trim(),
65-
})),
66-
[
67-
{
68-
stream: 'stderr',
69-
message: `Credentials file for 'test' environment does not exist`,
70-
},
71-
]
72-
)
55+
try {
56+
await command.run()
57+
} catch (error) {
58+
assert.equal(
59+
error.message,
60+
`E_CREDENTIALS_NO_FILE: Credentials file for 'test' environment does not exist`
61+
)
62+
}
7363
})
7464
})

0 commit comments

Comments
 (0)