Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error when app version cannot be detected #34

Merged
merged 1 commit into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/uploaders/BrowserUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ export async function uploadOne ({
const transformedSourceMap = await applyTransformations(fullSourceMapPath, sourceMapJson, projectRoot, logger)

if (!appVersion) {
appVersion = await detectAppVersion(projectRoot, logger)
try {
appVersion = await detectAppVersion(projectRoot, logger)
} catch (e) {
logger.error(e.message)

throw e
}
}

logger.debug(`Initiating upload "${endpoint}"`)
Expand Down Expand Up @@ -122,7 +128,13 @@ export async function uploadMultiple ({
logger.debug(` ${sourceMaps.join(', ')}`)

if (!appVersion) {
appVersion = await detectAppVersion(projectRoot, logger)
try {
appVersion = await detectAppVersion(projectRoot, logger)
} catch (e) {
logger.error(e.message)

throw e
}
}

let n = 0
Expand Down
16 changes: 14 additions & 2 deletions src/uploaders/NodeUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ export async function uploadOne ({
const transformedSourceMap = await applyTransformations(fullSourceMapPath, sourceMapJson, projectRoot, logger)

if (!appVersion) {
appVersion = await detectAppVersion(projectRoot, logger)
try {
appVersion = await detectAppVersion(projectRoot, logger)
} catch (e) {
logger.error(e.message)

throw e
}
}

logger.debug(`Initiating upload "${endpoint}"`)
Expand Down Expand Up @@ -110,7 +116,13 @@ export async function uploadMultiple ({
logger.debug(` ${sourceMaps.join(', ')}`)

if (!appVersion) {
appVersion = await detectAppVersion(projectRoot, logger)
try {
appVersion = await detectAppVersion(projectRoot, logger)
} catch (e) {
logger.error(e.message)

throw e
}
}

let n = 0
Expand Down
123 changes: 123 additions & 0 deletions src/uploaders/__test__/BrowserUploader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ test('uploadOne(): failure (sourcemap is invalid json)', async () => {
}
})

test('uploadOne(): fails when unable to detect appVersion', async () => {
const mockedRequest = request as jest.MockedFunction<typeof request>
try {
await uploadOne({
apiKey: '123',
bundleUrl: 'https://mybundle.jim/',
projectRoot: path.join(__dirname, 'fixtures/h'),
sourceMap: 'build/static/js/2.e5bb21a6.chunk.js.map',
bundle: 'build/static/js/2.e5bb21a6.chunk.js',
logger: mockLogger
})
expect(mockedRequest).not.toHaveBeenCalled()
} catch (e) {
expect(e).toBeTruthy()
expect(e.message).toBe('Unable to automatically detect app version. Provide the "--app-version" argument or add a "version" key to your package.json file.')
expect(mockLogger.error).toHaveBeenCalledWith('Unable to automatically detect app version. Provide the "--app-version" argument or add a "version" key to your package.json file.')
}
})

test('uploadOne(): failure (empty bundle)', async () => {
const mockedRequest = request as jest.MockedFunction<typeof request>
const err = new NetworkError('network error')
Expand Down Expand Up @@ -367,6 +386,92 @@ test('uploadMultiple(): success', async () => {
)
})

test('uploadMultiple(): success passing appVersion', async () => {
const mockedRequest = request as jest.MockedFunction<typeof request>
mockedRequest.mockResolvedValue()
await uploadMultiple({
apiKey: '123',
baseUrl: 'https://mybundle.jim/',
directory: 'build',
projectRoot: path.join(__dirname, 'fixtures/h'),
appVersion: '4.5.6',
logger: mockLogger
})
expect(mockedRequest).toHaveBeenCalledTimes(4)
expect(mockedRequest).toHaveBeenCalledWith(
'https://upload.bugsnag.com/',
expect.objectContaining({
apiKey: '123',
minifiedFile: expect.objectContaining({
filepath: path.join(__dirname, 'fixtures/h/build/static/js/2.e5bb21a6.chunk.js'),
data: expect.any(String)
}),
sourceMap: expect.objectContaining({
filepath: path.join(__dirname, 'fixtures/h/build/static/js/2.e5bb21a6.chunk.js.map'),
data: expect.any(String)
}),
overwrite: false,
minifiedUrl: 'https://mybundle.jim/static/js/2.e5bb21a6.chunk.js',
appVersion: '4.5.6'
}),
expect.objectContaining({})
)
expect(mockedRequest).toHaveBeenCalledWith(
'https://upload.bugsnag.com/',
expect.objectContaining({
apiKey: '123',
minifiedFile: expect.objectContaining({
filepath: path.join(__dirname, 'fixtures/h/build/static/js/3.1b8b4fc7.chunk.js'),
data: expect.any(String)
}),
sourceMap: expect.objectContaining({
filepath: path.join(__dirname, 'fixtures/h/build/static/js/3.1b8b4fc7.chunk.js.map'),
data: expect.any(String)
}),
overwrite: false,
minifiedUrl: 'https://mybundle.jim/static/js/3.1b8b4fc7.chunk.js',
appVersion: '4.5.6'
}),
expect.objectContaining({})
)
expect(mockedRequest).toHaveBeenCalledWith(
'https://upload.bugsnag.com/',
expect.objectContaining({
apiKey: '123',
minifiedFile: expect.objectContaining({
filepath: path.join(__dirname, 'fixtures/h/build/static/js/main.286ac573.chunk.js'),
data: expect.any(String)
}),
sourceMap: expect.objectContaining({
filepath: path.join(__dirname, 'fixtures/h/build/static/js/main.286ac573.chunk.js.map'),
data: expect.any(String)
}),
overwrite: false,
minifiedUrl: 'https://mybundle.jim/static/js/main.286ac573.chunk.js',
appVersion: '4.5.6'
}),
expect.objectContaining({})
)
expect(mockedRequest).toHaveBeenCalledWith(
'https://upload.bugsnag.com/',
expect.objectContaining({
apiKey: '123',
minifiedFile: expect.objectContaining({
filepath: path.join(__dirname, 'fixtures/h/build/static/js/runtime-main.ad66c902.js'),
data: expect.any(String)
}),
sourceMap: expect.objectContaining({
filepath: path.join(__dirname, 'fixtures/h/build/static/js/runtime-main.ad66c902.js.map'),
data: expect.any(String)
}),
overwrite: false,
minifiedUrl: 'https://mybundle.jim/static/js/runtime-main.ad66c902.js',
appVersion: '4.5.6'
}),
expect.objectContaining({})
)
})

test('uploadMultiple(): success using absolute path for "directory"', async () => {
const mockedRequest = request as jest.MockedFunction<typeof request>
mockedRequest.mockResolvedValue()
Expand Down Expand Up @@ -500,6 +605,24 @@ test('uploadMultiple(): invalid source map', async () => {
}
})

test('uploadMultiple(): fails when unable to detect appVersion', async () => {
const mockedRequest = request as jest.MockedFunction<typeof request>
try {
await uploadMultiple({
apiKey: '123',
baseUrl: 'https://mybundle.jim/',
directory: 'build',
projectRoot: path.join(__dirname, 'fixtures/h'),
logger: mockLogger
})
expect(mockedRequest).not.toHaveBeenCalled()
} catch (e) {
expect(e).toBeTruthy()
expect(e.message).toBe('Unable to automatically detect app version. Provide the "--app-version" argument or add a "version" key to your package.json file.')
expect(mockLogger.error).toHaveBeenCalledWith('Unable to automatically detect app version. Provide the "--app-version" argument or add a "version" key to your package.json file.')
}
})

test('uploadMultiple(): failure (timeout)', async () => {
const mockedRequest = request as jest.MockedFunction<typeof request>
const err = new NetworkError('timeout')
Expand Down
35 changes: 35 additions & 0 deletions src/uploaders/__test__/NodeUploader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ test('uploadOne(): dispatches a request with the correct params', async () => {
)
})

test('uploadOne(): fails when unable to detect appVersion', async () => {
const mockedRequest = request as jest.MockedFunction<typeof request>
try {
await uploadOne({
apiKey: '123',
projectRoot: path.join(__dirname, 'fixtures/h'),
sourceMap: 'build/static/js/2.e5bb21a6.chunk.js.map',
bundle: 'build/static/js/2.e5bb21a6.chunk.js',
logger: mockLogger
})
expect(mockedRequest).not.toHaveBeenCalled()
} catch (e) {
expect(e).toBeTruthy()
expect(e.message).toBe('Unable to automatically detect app version. Provide the "--app-version" argument or add a "version" key to your package.json file.')
expect(mockLogger.error).toHaveBeenCalledWith('Unable to automatically detect app version. Provide the "--app-version" argument or add a "version" key to your package.json file.')
}
})

test('uploadOne(): failure (unexpected network error)', async () => {
const mockedRequest = request as jest.MockedFunction<typeof request>
const err = new NetworkError('misc upload error')
Expand Down Expand Up @@ -297,6 +315,23 @@ test('uploadMultiple(): invalid source map', async () => {
}
})

test('uploadMultiple(): fails when unable to detect appVersion', async () => {
const mockedRequest = request as jest.MockedFunction<typeof request>
try {
await uploadMultiple({
apiKey: '123',
directory: 'build',
projectRoot: path.join(__dirname, 'fixtures/h'),
logger: mockLogger
})
expect(mockedRequest).not.toHaveBeenCalled()
} catch (e) {
expect(e).toBeTruthy()
expect(e.message).toBe('Unable to automatically detect app version. Provide the "--app-version" argument or add a "version" key to your package.json file.')
expect(mockLogger.error).toHaveBeenCalledWith('Unable to automatically detect app version. Provide the "--app-version" argument or add a "version" key to your package.json file.')
}
})

test('uploadMultiple(): failure (timeout)', async () => {
const mockedRequest = request as jest.MockedFunction<typeof request>
const err = new NetworkError('timeout')
Expand Down
23 changes: 23 additions & 0 deletions src/uploaders/__test__/fixtures/h/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"files": {
"main.css": "/static/css/main.ab7136cd.chunk.css",
"main.js": "/static/js/main.286ac573.chunk.js",
"main.js.map": "/static/js/main.286ac573.chunk.js.map",
"runtime-main.js": "/static/js/runtime-main.ad66c902.js",
"runtime-main.js.map": "/static/js/runtime-main.ad66c902.js.map",
"static/js/2.e5bb21a6.chunk.js": "/static/js/2.e5bb21a6.chunk.js",
"static/js/2.e5bb21a6.chunk.js.map": "/static/js/2.e5bb21a6.chunk.js.map",
"static/js/3.1b8b4fc7.chunk.js": "/static/js/3.1b8b4fc7.chunk.js",
"static/js/3.1b8b4fc7.chunk.js.map": "/static/js/3.1b8b4fc7.chunk.js.map",
"index.html": "/index.html",
"static/css/main.ab7136cd.chunk.css.map": "/static/css/main.ab7136cd.chunk.css.map",
"static/js/2.e5bb21a6.chunk.js.LICENSE.txt": "/static/js/2.e5bb21a6.chunk.js.LICENSE.txt",
"static/media/logo.103b5fa1.svg": "/static/media/logo.103b5fa1.svg"
},
"entrypoints": [
"static/js/runtime-main.ad66c902.js",
"static/js/2.e5bb21a6.chunk.js",
"static/css/main.ab7136cd.chunk.css",
"static/js/main.286ac573.chunk.js"
]
}
Binary file not shown.
1 change: 1 addition & 0 deletions src/uploaders/__test__/fixtures/h/build/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><link href="/static/css/main.ab7136cd.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,i,a=r[0],c=r[1],l=r[2],s=0,p=[];s<a.length;s++)i=a[s],Object.prototype.hasOwnProperty.call(o,i)&&o[i]&&p.push(o[i][0]),o[i]=0;for(n in c)Object.prototype.hasOwnProperty.call(c,n)&&(e[n]=c[n]);for(f&&f(r);p.length;)p.shift()();return u.push.apply(u,l||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,a=1;a<t.length;a++){var c=t[a];0!==o[c]&&(n=!1)}n&&(u.splice(r--,1),e=i(i.s=t[0]))}return e}var n={},o={1:0},u=[];function i(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,i),t.l=!0,t.exports}i.e=function(e){var r=[],t=o[e];if(0!==t)if(t)r.push(t[2]);else{var n=new Promise((function(r,n){t=o[e]=[r,n]}));r.push(t[2]=n);var u,a=document.createElement("script");a.charset="utf-8",a.timeout=120,i.nc&&a.setAttribute("nonce",i.nc),a.src=function(e){return i.p+"static/js/"+({}[e]||e)+"."+{3:"1b8b4fc7"}[e]+".chunk.js"}(e);var c=new Error;u=function(r){a.onerror=a.onload=null,clearTimeout(l);var t=o[e];if(0!==t){if(t){var n=r&&("load"===r.type?"missing":r.type),u=r&&r.target&&r.target.src;c.message="Loading chunk "+e+" failed.\n("+n+": "+u+")",c.name="ChunkLoadError",c.type=n,c.request=u,t[1](c)}o[e]=void 0}};var l=setTimeout((function(){u({type:"timeout",target:a})}),12e4);a.onerror=a.onload=u,document.head.appendChild(a)}return Promise.all(r)},i.m=e,i.c=n,i.d=function(e,r,t){i.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,r){if(1&r&&(e=i(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(i.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)i.d(t,n,function(r){return e[r]}.bind(null,n));return t},i.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(r,"a",r),r},i.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},i.p="/",i.oe=function(e){throw console.error(e),e};var a=this.webpackJsonpc=this.webpackJsonpc||[],c=a.push.bind(a);a.push=r,a=a.slice();for(var l=0;l<a.length;l++)r(a[l]);var f=c;t()}([])</script><script src="/static/js/2.e5bb21a6.chunk.js"></script><script src="/static/js/main.286ac573.chunk.js"></script></body></html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions src/uploaders/__test__/fixtures/h/build/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions src/uploaders/__test__/fixtures/h/build/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/

/** @license React v0.20.1
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v17.0.1
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v17.0.1
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v17.0.1
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

Large diffs are not rendered by default.

Loading