Skip to content

Commit f6fdc2e

Browse files
authored
Fix a bug with build metadata option (#101)
* fix: 🐛 don't try to access metadata build option when not provided * fix linting issue * test: ✅ make test more robust by not requiring a specific order * test: ✅ add new test for un-set metadata * test: ✅ make source map uploader assertions less tight
1 parent 18a7735 commit f6fdc2e

File tree

8 files changed

+96
-12
lines changed

8 files changed

+96
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
- Fixed an issue when build metadata option is not provided (#101)
6+
37
## [2.2.2] - 2025-07-03
48

59
- Ensure that we correctly pass the metadata the BugSnag CLI create build command (#100)

build-reporter-plugin.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ class BugsnagBuildReporterPlugin {
6262
const optionalOpts = {
6363
autoAssignRelease: opts.build.autoAssignRelease,
6464
builderName: opts.build.builderName,
65-
metadata: Object.entries(opts.build.metadata)
66-
.map(([key, value]) => `${key}=${value}`)
67-
.join(','),
65+
metadata: opts.build.metadata
66+
? Object.entries(opts.build.metadata)
67+
.map(([key, value]) => `${key}=${value}`)
68+
.join(',')
69+
: undefined,
6870
provider: opts.build.sourceControl.provider,
6971
repository: opts.build.sourceControl.repository,
7072
revision: opts.build.sourceControl.revision,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
"author": "Bugsnag Inc.",
1818
"license": "MIT",
1919
"devDependencies": {
20+
"@randomgoods/tap-spec": "^5.0.4",
2021
"concat-stream": "^1.6.2",
21-
"once": "^1.4.0",
2222
"formidable": "^3.5.1",
23+
"once": "^1.4.0",
2324
"standard": "^16.0.1",
24-
"@randomgoods/tap-spec": "^5.0.4",
2525
"tape": "^5.0.1"
2626
},
2727
"dependencies": {

test/build-reporter-plugin.test.mjs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,19 @@ test('it sends upon successful build', t => {
4141
})
4242
})
4343
server.listen()
44+
45+
// Add timeout to prevent hanging
46+
const timeout = setTimeout(() => {
47+
server.close()
48+
t.fail('Test timed out - webpack process may be hanging')
49+
t.end()
50+
}, 30000) // 30 second timeout
51+
4452
exec(join(__dirname, '..', 'node_modules', '.bin', 'webpack'), {
4553
env: generateEnv(server),
4654
cwd: join(__dirname, 'fixtures', 'a')
4755
}, (err, stdout, stderr) => {
56+
clearTimeout(timeout)
4857
server.close()
4958
if (err) { console.info(err, '\n\n\n', stdout, '\n\n\n', stderr) }
5059
if (err) return t.fail(err.message)
@@ -62,12 +71,62 @@ test('it doesn’t send upon unsuccessful build', t => {
6271
})
6372
})
6473
server.listen()
74+
75+
// Add timeout to prevent hanging
76+
const timeout = setTimeout(() => {
77+
server.close()
78+
t.fail('Test timed out - webpack process may be hanging')
79+
t.end()
80+
}, 30000) // 30 second timeout
81+
6582
exec(join(__dirname, '..', 'node_modules', '.bin', 'webpack'), {
6683
env: generateEnv(server),
6784
cwd: join(__dirname, 'fixtures', 'b')
6885
}, (err, stdout, stderr) => {
86+
clearTimeout(timeout)
87+
server.close()
88+
t.ok(err, 'webpack should fail due to syntax error')
89+
t.end()
90+
})
91+
})
92+
93+
test('it sends upon successful build without metadata', t => {
94+
t.plan(3)
95+
const server = createServer((req, res) => {
96+
let body = ''
97+
req.on('data', (d) => { body += d })
98+
req.on('end', () => {
99+
res.end('ok')
100+
let j
101+
try {
102+
j = JSON.parse(body)
103+
} catch (e) {
104+
server.close()
105+
t.fail('failed to parse body as json')
106+
}
107+
t.ok(j, 'json body was received')
108+
t.equal(j.appVersion, '1.2.3', 'body should contain app version')
109+
t.equal(j.apiKey, 'YOUR_API_KEY', 'body should contain api key')
110+
// Note: no metadata check since none was provided
111+
})
112+
})
113+
server.listen()
114+
115+
// Add timeout to prevent hanging
116+
const timeout = setTimeout(() => {
117+
server.close()
118+
t.fail('Test timed out - webpack process may be hanging')
119+
t.end()
120+
}, 30000) // 30 second timeout
121+
122+
exec(join(__dirname, '..', 'node_modules', '.bin', 'webpack'), {
123+
env: generateEnv(server),
124+
cwd: join(__dirname, 'fixtures', 'i')
125+
}, (err, stdout, stderr) => {
126+
clearTimeout(timeout)
69127
server.close()
70-
t.ok(err)
128+
if (err) { console.info(err, '\n\n\n', stdout, '\n\n\n', stderr) }
129+
if (err) return t.fail(err.message)
71130
t.end()
72131
})
73132
})

test/fixtures/i/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bundle.js

test/fixtures/i/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('hello world without metadata')

test/fixtures/i/webpack.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const BugsnagBuildReporterPlugin = require('../../../').BugsnagBuildReporterPlugin
2+
3+
module.exports = {
4+
entry: './app.js',
5+
output: {
6+
path: __dirname,
7+
filename: './bundle.js'
8+
},
9+
plugins: [
10+
new BugsnagBuildReporterPlugin({
11+
apiKey: 'YOUR_API_KEY',
12+
appVersion: '1.2.3',
13+
endpoint: `http://localhost:${process.env.PORT}`
14+
// Note: no metadata provided
15+
})
16+
]
17+
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ if (process.env.WEBPACK_VERSION !== '3') {
197197

198198
const done = () => {
199199
t.equal(requests[0].minifiedUrl, '*/dist/main.js')
200-
t.match(requests[0].parts[1].filename, /main\.js$/)
201-
t.match(requests[0].parts[0].filename, /main\.js\.map$/)
200+
t.match(requests[0].parts.find(p => p.filename.includes('.js') && !p.filename.includes('.map'))?.filename, /main\.js$/)
201+
t.match(requests[0].parts.find(p => p.filename.includes('.js.map'))?.filename, /main\.js\.map$/)
202202
end()
203203
}
204204

@@ -246,11 +246,11 @@ if (process.env.WEBPACK_VERSION !== '3') {
246246
const done = () => {
247247
requests.sort((a, b) => a.minifiedUrl < b.minifiedUrl ? -1 : 1)
248248
t.equal(requests[0].minifiedUrl, '*/dist/main.css')
249-
t.match(requests[0].parts[0].filename, /main\.css/)
250-
t.match(requests[0].parts[0].filename, /main\.css\.map/)
249+
t.match(requests[0].parts.find(p => p.filename.includes('.css'))?.filename, /main\.css/)
250+
t.match(requests[0].parts.find(p => p.filename.includes('.map'))?.filename, /main\.css\.map/)
251251
t.equal(requests[1].minifiedUrl, '*/dist/main.js')
252-
t.match(requests[1].parts[0].filename, /main\.js/)
253-
t.match(requests[1].parts[0].filename, /main\.js\.map/)
252+
t.match(requests[1].parts.find(p => p.filename.includes('.js') && !p.filename.includes('.map'))?.filename, /main\.js/)
253+
t.match(requests[1].parts.find(p => p.filename.includes('.js.map'))?.filename, /main\.js\.map/)
254254
end()
255255
}
256256

0 commit comments

Comments
 (0)