Skip to content

Commit 20e13c9

Browse files
committed
test: slacken bundle and sourcemap filename tests
1 parent b66b2f0 commit 20e13c9

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

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

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,22 @@ describe('BugsnagSourceMapUploaderPlugin', () => {
6767

6868
const sourcemapUpload = vi.mocked(Bugsnag.Upload.Js)
6969
const outputDir = resolve(fixturesPath, 'dist')
70-
const bundlePath = resolve(outputDir, 'assets/index-DTHX3LI9.js')
71-
const sourceMapPath = resolve(outputDir, 'assets/index-DTHX3LI9.js.map')
7270

7371
expect(mockLogger.info).toHaveBeenCalledWith('[BugsnagSourceMapUploaderPlugin] uploading sourcemaps using the bugsnag-cli')
7472
expect(mockLogger.info).toHaveBeenCalledWith('[BugsnagSourceMapUploaderPlugin] Sourcemaps uploaded successfully')
75-
expect(sourcemapUpload).toHaveBeenCalledExactlyOnceWith({
76-
apiKey: 'test-api',
77-
bundleUrl: 'https://bugsnag.com/assets/index-DTHX3LI9.js',
78-
bundle: bundlePath,
79-
projectRoot: fixturesPath,
80-
sourceMap: sourceMapPath,
81-
versionName: '1.0.0'
82-
},
83-
outputDir
84-
)
73+
expect(sourcemapUpload).toHaveBeenCalledOnce()
74+
75+
const [uploadOptions, targetDir] = sourcemapUpload.mock.calls[0]
76+
expect(uploadOptions).toBeDefined()
77+
expect(uploadOptions).toMatchObject({
78+
apiKey: 'test-api',
79+
projectRoot: fixturesPath,
80+
versionName: '1.0.0'
81+
})
82+
expect(uploadOptions!.bundleUrl).toMatch(/^https:\/\/bugsnag\.com\/assets\/index-[a-zA-Z0-9]+\.js$/)
83+
expect(uploadOptions!.bundle).toMatch(/\/assets\/index-[a-zA-Z0-9]+\.js$/)
84+
expect(uploadOptions!.sourceMap).toMatch(/\/assets\/index-[a-zA-Z0-9]+\.js\.map$/)
85+
expect(targetDir).toBe(outputDir)
8586
})
8687

8788
test('should use the relative filepath for bundleUrl if base is not provided in config', async () => {
@@ -110,21 +111,22 @@ describe('BugsnagSourceMapUploaderPlugin', () => {
110111

111112
const sourcemapUpload = vi.mocked(Bugsnag.Upload.Js)
112113
const outputDir = resolve(fixturePath, 'dist')
113-
const bundlePath = resolve(outputDir, 'assets/index-DTHX3LI9.js')
114-
const sourceMapPath = resolve(outputDir, 'assets/index-DTHX3LI9.js.map')
115114

116115
expect(mockLogger.info).toHaveBeenCalledWith('[BugsnagSourceMapUploaderPlugin] uploading sourcemaps using the bugsnag-cli')
117116
expect(mockLogger.info).toHaveBeenCalledWith('[BugsnagSourceMapUploaderPlugin] Sourcemaps uploaded successfully')
118-
expect(sourcemapUpload).toHaveBeenCalledExactlyOnceWith({
119-
apiKey: 'test-api',
120-
bundleUrl: '/assets/index-DTHX3LI9.js',
121-
bundle: bundlePath,
122-
projectRoot: fixturePath,
123-
sourceMap: sourceMapPath,
124-
versionName: version
125-
},
126-
outputDir
127-
)
117+
expect(sourcemapUpload).toHaveBeenCalledOnce()
118+
119+
const [uploadOptions, targetDir] = sourcemapUpload.mock.calls[0]
120+
expect(uploadOptions).toBeDefined()
121+
expect(uploadOptions).toMatchObject({
122+
apiKey: 'test-api',
123+
projectRoot: fixturePath,
124+
versionName: version
125+
})
126+
expect(uploadOptions!.bundleUrl).toMatch(/^\/assets\/index-[a-zA-Z0-9]+\.js$/)
127+
expect(uploadOptions!.bundle).toMatch(/\/assets\/index-[a-zA-Z0-9]+\.js$/)
128+
expect(uploadOptions!.sourceMap).toMatch(/\/assets\/index-[a-zA-Z0-9]+\.js\.map$/)
129+
expect(targetDir).toBe(outputDir)
128130
})
129131

130132
test('logs an error if the upload fails', async () => {

0 commit comments

Comments
 (0)