Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Nov 2, 2024
1 parent c7179b2 commit 360fb85
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions tests/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,28 @@ import { fetchVersion } from '../src/install.js'
import { getNameByArchitecture, parseParams } from '../src/utils.js'
import { EDGE_PRODUCTS_API } from '../src/constants.js'

import apiResponse from './__fixtures__/api.json' assert { type: 'json' }

vi.mock('node:os', () => ({
default: {
arch: vi.fn(),
platform: vi.fn()
}
}))

vi.mock('node-fetch', async (orig) => {
const origFetch: any = await orig()
const apiResponse = await import('./__fixtures__/api.json', { assert: { type: 'json' } })
return {
default: vi.fn(async (url) => {
if (url === EDGE_PRODUCTS_API) {
return {
json: vi.fn().mockResolvedValue(apiResponse.default)
}
} else if (!url.includes('LATEST_RELEASE')) {
return {
text: vi.fn().mockResolvedValue('��123.456.789.0')
}
}

return origFetch.default(url)
})
const origFetch = globalThis.fetch
vi.stubGlobal('fetch', async (url) => {
if (url === EDGE_PRODUCTS_API) {
return {
json: vi.fn().mockResolvedValue(apiResponse)
}
} else if (!url.includes('LATEST_RELEASE')) {
return {
text: vi.fn().mockResolvedValue('��123.456.789.0')
}
}

return origFetch(url)
})

test('fetchVersion', async () => {
Expand Down

0 comments on commit 360fb85

Please sign in to comment.