Skip to content

Commit

Permalink
Merge pull request #23 from bugsnag/tom/npm-update-aug23
Browse files Browse the repository at this point in the history
chore(build): update npm dependencies
  • Loading branch information
tomlongridge authored Apr 29, 2024
2 parents bf67a2e + 02c52de commit 62255e8
Show file tree
Hide file tree
Showing 10 changed files with 6,247 additions and 3,249 deletions.
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ work on your suggested feature.
That said, we have had some tremendous contributions from the community in the past,
so use your best judgement. What we want to avoid here is anybody feeling like they’ve
wasted their time!

## Testing

Run `npm test` to execute the unit tests.

Note – you'll need to have Mercurial (`hg`) installed to execute them successfully
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = (build, opts) => {
}

const onSuccess = () => {
log.info(`build info sent`)
log.info('build info sent')
resolve()
}
makePayload(build, path, log, (err, data) => {
Expand Down
10 changes: 5 additions & 5 deletions lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const pfx = `[bugsnag-build-reporter]`
const pfx = '[bugsnag-build-reporter]'
const chalk = require('chalk')

module.exports = logLevel => {
logLevel = logLevel || 'info'
return {
debug: function () {
if ([ 'debug' ].indexOf(logLevel) === -1) return
if (['debug'].indexOf(logLevel) === -1) return
console.log.bind(console, chalk.gray(pfx)).apply(console, arguments)
},
info: function () {
if ([ 'debug', 'info' ].indexOf(logLevel) === -1) return
if (['debug', 'info'].indexOf(logLevel) === -1) return
console.log.bind(console, chalk.blue(pfx)).apply(console, arguments)
},
warn: function () {
if ([ 'debug', 'info', 'warn' ].indexOf(logLevel) === -1) return
if (['debug', 'info', 'warn'].indexOf(logLevel) === -1) return
console.log.bind(console, chalk.yellow(pfx)).apply(console, arguments)
},
error: function () {
if ([ 'debug', 'info', 'warn', 'error' ].indexOf(logLevel) === -1) return
if (['debug', 'info', 'warn', 'error'].indexOf(logLevel) === -1) return
console.log.bind(console, chalk.red(pfx)).apply(console, arguments)
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const https = require('https')
const http = require('http')
const concat = require('concat-stream')
const url = require('url')
const { URL } = require('url')
const once = require('once')

const MAX_ATTEMPTS = 5
Expand All @@ -23,7 +23,7 @@ module.exports = (endpoint, data, onSuccess, onError) => {

const send = (endpoint, data, onSuccess, onError) => {
onError = once(onError)
const parsedUrl = url.parse(endpoint)
const parsedUrl = new URL(endpoint)
const payload = JSON.stringify(data)
const req = (parsedUrl.protocol === 'https:' ? https : http).request({
method: 'POST',
Expand Down
4 changes: 2 additions & 2 deletions lib/source-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ module.exports = (path, log, cb) => {
}
if (!data) return cb(null, null)
const repository = (data[0] && data[0].repository)
? data[0].repository
: ((data[1] && data[1].repository)
? data[0].repository
: ((data[1] && data[1].repository)
? data[1].repository
: undefined)
const provider = getProviderFromUrl(repository)
Expand Down
8 changes: 4 additions & 4 deletions lib/test/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('schema: invalid', t => {
t.ok(err)
t.ok(Array.isArray(err.errors))
t.equal(err.errors.length, 2)
t.deepEqual(err.errors, [ 'apiKey is required (got "undefined")', 'appVersion is required (got "undefined")' ])
t.deepEqual(err.errors, ['apiKey is required (got "undefined")', 'appVersion is required (got "undefined")'])
t.end()
})
})
Expand All @@ -18,7 +18,7 @@ test('schema: invalid 2', t => {
apiKey: '123',
appVersion: '1.2.3',
sourceControl: { foo: 10 },
metadata: { nested: { objs: [ 'are', 'not', 'allowed' ] } }
metadata: { nested: { objs: ['are', 'not', 'allowed'] } }
}, (err) => {
if (!err) return t.fail('error expected')
t.ok(err)
Expand Down Expand Up @@ -62,7 +62,7 @@ test('schema: valid 2', t => {
validate(schema)({
apiKey: '123',
appVersion: '1.2.3',
metadata: { 'foo': 'bar', 'meta': 'data' },
metadata: { foo: 'bar', meta: 'data' },
sourceControl: {
repository: 'https://github.com/org/repo',
revision: 'ababababa',
Expand All @@ -81,7 +81,7 @@ test('schema: valid 3', t => {
validate(schema)({
apiKey: '123',
appVersion: '1.2.3',
metadata: { 'foo': 'bar', 'meta': 'data' },
metadata: { foo: 'bar', meta: 'data' },
sourceControl: {
repository: 'https://github.com/org/repo',
revision: 'ababababa',
Expand Down
4 changes: 2 additions & 2 deletions lib/test/send.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ test('send(): unsuccessful (400)', t => {
server.close()
t.ok(err)
t.equal(err.message, 'Invalid payload sent to builds API')
t.deepEqual(err.errors, [ 'flipflop is not a valid crankworble' ])
t.deepEqual(err.errors, ['flipflop is not a valid crankworble'])
t.end()
})
})
Expand All @@ -113,7 +113,7 @@ test('send(): unsuccessful, doesn’t retry (400)', t => {
t.ok(err)
t.equal(n, 1, 'It should never retry a bad request')
t.equal(err.message, 'Invalid payload sent to builds API')
t.deepEqual(err.errors, [ 'flipflop is not a valid crankworble' ])
t.deepEqual(err.errors, ['flipflop is not a valid crankworble'])
t.end()
})
})
Expand Down
97 changes: 49 additions & 48 deletions lib/test/source-control.test.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,81 @@
const autoDetectSourceControl = require('../source-control')
const test = require('tape')
const noopLogger = { debug: () => {}, info: () => {}, warn: () => {}, error: () => {} }
const copy = require('directory-copy')
const copy = require('recursive-copy')
const tempy = require('tempy')
const fs = require('fs')
const path = require('path')

test('autoDetectSourceControl(): git repo', t => {
const tmp = tempy.directory()
copy({
src: `${__dirname}/fixtures/git`,
dest: tmp
}, (err) => {
t.ok(!err)
fs.renameSync(`${tmp}/_git`, `${tmp}/.git`)
autoDetectSourceControl(tmp, noopLogger, (err, sourceControl) => {
copy(
path.join(__dirname, 'fixtures', 'git'),
tmp,
(err, res) => {
t.ok(!err)
t.deepEqual(sourceControl, {
provider: 'github',
repository: '[email protected]:bugsnag/fictional-repo.git',
revision: '436739224cebc54aee8c5a61b8e00d68d4759faf'
fs.renameSync(`${tmp}/_git`, `${tmp}/.git`)
autoDetectSourceControl(tmp, noopLogger, (err, sourceControl) => {
t.ok(!err)
t.deepEqual(sourceControl, {
provider: 'github',
repository: '[email protected]:bugsnag/fictional-repo.git',
revision: '436739224cebc54aee8c5a61b8e00d68d4759faf'
})
t.end()
})
t.end()
})
})
})

test('autoDetectSourceControl(): mercurial repo', t => {
const tmp = tempy.directory()
copy({
src: `${__dirname}/fixtures/hg`,
dest: tmp
}, (err) => {
t.ok(!err)
autoDetectSourceControl(tmp, noopLogger, (err, sourceControl) => {
copy(
path.join(__dirname, 'fixtures', 'hg'),
tmp,
(err, res) => {
t.ok(!err)
t.deepEqual(sourceControl, {
provider: 'bitbucket',
repository: 'https://[email protected]/bugsnag/fictional_repo',
revision: '4d1ccd3c4b12'
autoDetectSourceControl(tmp, noopLogger, (err, sourceControl) => {
t.ok(!err)
t.deepEqual(sourceControl, {
provider: 'bitbucket',
repository: 'https://[email protected]/bugsnag/fictional_repo',
revision: '4d1ccd3c4b12'
})
t.end()
})
t.end()
})
})
})

test('autoDetectSourceControl(): git+package.json repo', t => {
const tmp = tempy.directory()
copy({
src: `${__dirname}/fixtures/pkg`,
dest: tmp
}, (err) => {
t.ok(!err)
fs.renameSync(`${tmp}/_git`, `${tmp}/.git`)
autoDetectSourceControl(tmp, noopLogger, (err, sourceControl) => {
copy(
path.join(__dirname, 'fixtures', 'pkg'),
tmp,
(err, res) => {
t.ok(!err)
t.deepEqual(sourceControl, {
provider: 'github',
repository: 'https://github.com/bugsnag/not-real.git',
revision: 'c177f39c361696468126a191ea29e01868ee6c55'
fs.renameSync(`${tmp}/_git`, `${tmp}/.git`)
autoDetectSourceControl(tmp, noopLogger, (err, sourceControl) => {
t.ok(!err)
t.deepEqual(sourceControl, {
provider: 'github',
repository: 'https://github.com/bugsnag/not-real.git',
revision: 'c177f39c361696468126a191ea29e01868ee6c55'
})
t.end()
})
t.end()
})
})
})

test('autoDetectSourceControl(): directory with no repo or manifest', t => {
const tmp = tempy.directory()
copy({
src: `${__dirname}/fixtures/nothing`,
dest: tmp
}, (err) => {
t.ok(!err)
autoDetectSourceControl(tmp, noopLogger, (err, sourceControl) => {
copy(
path.join(__dirname, 'fixtures', 'nothing'),
tmp,
(err, res) => {
t.ok(!err)
t.equal(sourceControl, null)
t.end()
autoDetectSourceControl(tmp, noopLogger, (err, sourceControl) => {
t.ok(!err)
t.equal(sourceControl, null)
t.end()
})
})
})
})
Loading

0 comments on commit 62255e8

Please sign in to comment.