Skip to content

Commit

Permalink
fix(tests): use vitest runIf to conditionally run tests based on libc…
Browse files Browse the repository at this point in the history
…url version
  • Loading branch information
JCMais committed Dec 9, 2024
1 parent 4d02eef commit 5f0e800
Show file tree
Hide file tree
Showing 5 changed files with 362 additions and 361 deletions.
18 changes: 10 additions & 8 deletions test/curl/callbacks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ describe('Callbacks', () => {
}, 10000)
}, 10000)

if (Curl.isVersionGreaterOrEqualThan(7, 64, 0)) {
describe('trailer', function () {
describe.runIf(Curl.isVersionGreaterOrEqualThan(7, 64, 0))(
'trailer',
function () {
it('should work', async () => {
let wasCalled = false
let isFirstCall = true
Expand Down Expand Up @@ -293,11 +294,12 @@ describe('Callbacks', () => {
curl.perform()
})
})
})
}
},
)

if (Curl.isVersionGreaterOrEqualThan(7, 80, 0)) {
describe('prereq', function () {
describe.runIf(Curl.isVersionGreaterOrEqualThan(7, 80, 0))(
'prereq',
function () {
it('should work', async () => {
let wasCalled = false

Expand Down Expand Up @@ -395,6 +397,6 @@ describe('Callbacks', () => {
curl.perform()
})
})
})
}
},
)
}, 5000)
43 changes: 22 additions & 21 deletions test/curl/easy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ describe('easy', () => {
)
})

if (Curl.isVersionGreaterOrEqualThan(7, 64, 0)) {
it('TRAILERFUNCTION - should rethrow error', () => {
describe.runIf(Curl.isVersionGreaterOrEqualThan(7, 64, 0))(
'TRAILERFUNCTION - should rethrow error',
() => {
curl.setOpt('UPLOAD', true)

Check failure on line 92 in test/curl/easy.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-release-nodejs (ubuntu-20.04, 7.86.0, 21)

test/curl/easy.spec.ts

TypeError: Cannot read properties of undefined (reading 'setOpt') ❯ test/curl/easy.spec.ts:92:14

Check failure on line 92 in test/curl/easy.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-release-nodejs (ubuntu-20.04, 7.86.0, 18)

test/curl/easy.spec.ts

TypeError: Cannot read properties of undefined (reading 'setOpt') ❯ test/curl/easy.spec.ts:92:14

Check failure on line 92 in test/curl/easy.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-release-nodejs (ubuntu-20.04, 7.86.0, 20)

test/curl/easy.spec.ts

TypeError: Cannot read properties of undefined (reading 'setOpt') ❯ test/curl/easy.spec.ts:92:14

Check failure on line 92 in test/curl/easy.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-release-nodejs (ubuntu-20.04, 7.86.0, 22)

test/curl/easy.spec.ts

TypeError: Cannot read properties of undefined (reading 'setOpt') ❯ test/curl/easy.spec.ts:92:14
curl.setOpt('HTTPHEADER', ['x-random-header: random-value'])
// @ts-ignore
Expand All @@ -103,27 +104,27 @@ describe('easy', () => {
return buffer.write(data)
})
expect(() => curl.perform()).toThrow('Error thrown on callback')
})
},
)

it('TRAILERFUNCTION - should throw error if has invalid return type', () => {
curl.setOpt('UPLOAD', true)
curl.setOpt('HTTPHEADER', ['x-random-header: random-value'])
// @ts-ignore
curl.setOpt('TRAILERFUNCTION', () => {
return {}
})
let finished = false
curl.setOpt(Curl.option.READFUNCTION, (buffer, _size, _nmemb) => {
if (finished) return 0
it('TRAILERFUNCTION - should throw error if has invalid return type', () => {
curl.setOpt('UPLOAD', true)
curl.setOpt('HTTPHEADER', ['x-random-header: random-value'])
// @ts-ignore
curl.setOpt('TRAILERFUNCTION', () => {
return {}
})
let finished = false
curl.setOpt(Curl.option.READFUNCTION, (buffer, _size, _nmemb) => {
if (finished) return 0

const data = 'HELLO'
finished = true
return buffer.write(data)
})
expect(() => curl.perform()).toThrow(
'Return value from the Trailer callback must be an array of strings or false.',
)
const data = 'HELLO'
finished = true
return buffer.write(data)
})
}
expect(() => curl.perform()).toThrow(
'Return value from the Trailer callback must be an array of strings or false.',
)
})
})
})
Loading

0 comments on commit 5f0e800

Please sign in to comment.