Skip to content

Commit 73aa038

Browse files
committed
test(dlx): add binaryName assertions and fix lenient coana test
Unit test improvements: - Add binaryName assertions for all resolve functions (coana, cdxgen, synp) - Update tests to use 'details' property instead of deprecated 'packageSpec' - Verify binary names are correct when package name differs from binary name E2E test improvements: - Remove lenient error handling in coana test that was masking failures - Make coana test require success instead of allowing failures - Add new test verifying binary name resolution from package name - Fix import paths to use correct module locations These changes ensure tests catch issues where binaryName is missing or incorrect, preventing bugs like the @coana-tech/cli resolution failure.
1 parent af51da6 commit 73aa038

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

packages/cli/src/utils/dlx/resolve-binary.test.mts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ describe('resolve-binary', () => {
4444
>
4545

4646
expect(result.type).toBe('dlx')
47-
expect(result.packageSpec.name).toBe('@coana-tech/cli')
48-
expect(result.packageSpec.version).toContain('~')
47+
expect(result.details.name).toBe('@coana-tech/cli')
48+
expect(result.details.version).toContain('~')
49+
expect(result.details.binaryName).toBe('coana')
4950
})
5051

5152
it('should prefer local path over dlx when both available', () => {
@@ -82,7 +83,8 @@ describe('resolve-binary', () => {
8283
>
8384

8485
expect(result.type).toBe('dlx')
85-
expect(result.packageSpec.name).toBe('@cyclonedx/cdxgen')
86+
expect(result.details.name).toBe('@cyclonedx/cdxgen')
87+
expect(result.details.binaryName).toBe('cdxgen')
8688
})
8789
})
8890

@@ -133,7 +135,8 @@ describe('resolve-binary', () => {
133135
const result = resolveSynp() as Extract<BinaryResolution, { type: 'dlx' }>
134136

135137
expect(result.type).toBe('dlx')
136-
expect(result.packageSpec.name).toBe('synp')
138+
expect(result.details.name).toBe('synp')
139+
expect(result.details.binaryName).toBe('synp')
137140
})
138141

139142
it('should return dlx even if environment variables are set', () => {
@@ -142,7 +145,8 @@ describe('resolve-binary', () => {
142145
const result = resolveSynp() as Extract<BinaryResolution, { type: 'dlx' }>
143146

144147
expect(result.type).toBe('dlx')
145-
expect(result.packageSpec.name).toBe('synp')
148+
expect(result.details.name).toBe('synp')
149+
expect(result.details.binaryName).toBe('synp')
146150
})
147151
})
148152

packages/cli/test/e2e/dlx-spawn.e2e.test.mts

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -140,42 +140,51 @@ describe('dlx e2e tests', () => {
140140

141141
describe('spawnCoanaDlx e2e tests', () => {
142142
it.skipIf(!ENV.RUN_E2E_TESTS || !hasAuth)(
143-
'executes coana-tech/cli via dlx',
143+
'executes coana-tech/cli via dlx with correct binary name',
144144
async () => {
145-
const { spawnCoanaDlx } = await import('./spawn.mts')
145+
const { spawnCoanaDlx } = await import('../../src/utils/dlx/spawn.mts')
146146
const result = await spawnCoanaDlx(['--help'])
147147

148-
// Coana might fail due to network issues or package availability
148+
// Coana should succeed - if it fails, it indicates a real issue.
149149
expect(result).toBeDefined()
150-
expect(typeof result.ok).toBe('boolean')
150+
expect(result.ok).toBe(true)
151151

152152
if (result.ok && result.data) {
153+
// Verify we got output from coana binary.
153154
expect(result.data).toContain('coana')
154-
} else if (!result.ok) {
155-
// Log the error for debugging but don't fail the test
156-
console.log(
157-
'Coana failed (expected in some environments):',
158-
result.message,
159-
)
160-
expect(result.message).toBeDefined()
155+
} else {
156+
// If coana fails, the test should fail to catch real issues.
157+
throw new Error(`Coana execution failed: ${result.message}`)
161158
}
162159
},
163160
30000,
164161
)
165162

166163
it.skipIf(!ENV.RUN_E2E_TESTS || !hasAuth)(
167-
'handles error from spawn',
164+
'verifies coana binary is correctly resolved from package name',
168165
async () => {
169-
const { spawnCoanaDlx } = await import('./spawn.mts')
170-
// Pass invalid args to trigger an error.
171-
const result = await spawnCoanaDlx([
172-
'--invalid-flag-that-does-not-exist',
173-
])
166+
const { spawnCoanaDlx } = await import('../../src/utils/dlx/spawn.mts')
167+
const { resolveCoana } = await import(
168+
'../../src/utils/dlx/resolve-binary.mts'
169+
)
170+
171+
// Verify the resolution includes correct binary name.
172+
const resolution = resolveCoana()
173+
if (resolution.type === 'dlx') {
174+
expect(resolution.details.name).toBe('@coana-tech/cli')
175+
expect(resolution.details.binaryName).toBe('coana')
176+
}
177+
178+
// Verify execution works with resolved binary name.
179+
const result = await spawnCoanaDlx(['--version'])
174180

175-
// The command might still succeed if the tool ignores unknown flags.
176-
// Just verify we get a result.
177181
expect(result).toBeDefined()
178-
expect(typeof result.ok).toBe('boolean')
182+
expect(result.ok).toBe(true)
183+
184+
if (result.ok && result.data) {
185+
// Version output should contain coana information.
186+
expect(result.data).toBeTruthy()
187+
}
179188
},
180189
30000,
181190
)

0 commit comments

Comments
 (0)