Skip to content

Commit b66b2f0

Browse files
committed
test: clear mocks between tests using beforeEach
1 parent e4fefa4 commit b66b2f0

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

test/source-map-uploader-plugin.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Bugsnag from '@bugsnag/cli'
22
import { resolve } from 'path'
33
import { build } from 'vite'
4-
import { describe, expect, test, vi } from 'vitest'
4+
import { beforeEach, describe, expect, test, vi } from 'vitest'
55
import { BugsnagSourceMapUploaderPlugin } from '../src/source-map-uploader-plugin'
66
import cleanBuildDir from './lib/clean-build-dir'
77

@@ -16,6 +16,10 @@ vi.mock('@bugsnag/cli', () => ({
1616
}))
1717

1818
describe('BugsnagSourceMapUploaderPlugin', () => {
19+
beforeEach(() => {
20+
vi.mocked(Bugsnag.Upload.Js).mockClear()
21+
})
22+
1923
test('should return a valid plugin object', async () => {
2024
const plugin = BugsnagSourceMapUploaderPlugin({
2125
apiKey: 'test-api',
@@ -78,8 +82,6 @@ describe('BugsnagSourceMapUploaderPlugin', () => {
7882
},
7983
outputDir
8084
)
81-
82-
sourcemapUpload.mockClear()
8385
})
8486

8587
test('should use the relative filepath for bundleUrl if base is not provided in config', async () => {
@@ -123,8 +125,6 @@ describe('BugsnagSourceMapUploaderPlugin', () => {
123125
},
124126
outputDir
125127
)
126-
127-
sourcemapUpload.mockClear()
128128
})
129129

130130
test('logs an error if the upload fails', async () => {
@@ -159,7 +159,5 @@ describe('BugsnagSourceMapUploaderPlugin', () => {
159159
expect(mockLogger.info).toHaveBeenCalledWith('[BugsnagSourceMapUploaderPlugin] uploading sourcemaps using the bugsnag-cli')
160160
expect(mockLogger.error).toHaveBeenCalledWith('[BugsnagSourceMapUploaderPlugin] Error: Upload failed')
161161
expect(mockLogger.info).not.toHaveBeenCalledWith('[BugsnagSourceMapUploaderPlugin] Sourcemaps uploaded successfully')
162-
163-
sourcemapUpload.mockClear()
164162
})
165163
})

0 commit comments

Comments
 (0)