Skip to content

Commit

Permalink
fix: crash on lazy loading when using Runtime Config (#286)
Browse files Browse the repository at this point in the history
Co-authored-by: Rafał Chłodnicki <[email protected]>
  • Loading branch information
mikeapr4 and rchl authored Mar 18, 2021
1 parent 5e8eb0a commit 074bf77
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/plugin.lazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async function loadSentry (ctx, inject) {

const runtimeConfigKey = <%= serialize(options.runtimeConfigKey) %>
if (ctx.$config && runtimeConfigKey && ctx.$config[runtimeConfigKey]) {
const merge = await import(/* <%= magicComments.join(', ') %> */ 'lodash.merge')
const { default: merge } = await import(/* <%= magicComments.join(', ') %> */ 'lodash.merge')
merge(config, ctx.$config[runtimeConfigKey].config, ctx.$config[runtimeConfigKey].clientConfig)
}

Expand Down
7 changes: 7 additions & 0 deletions test/default.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ describe('Smoke test (default)', () => {

test('builds and runs', async () => {
const page = await browser.newPage()
/** @type {string[]} */
const errors = []
page.on('pageerror', (error) => {
errors.push(error.message)
})
await page.goto(url('/'))

expect(await $$('#server-side', page)).toBe('Works!')
expect(await $$('#client-side', page)).toBe('Works!')
expect(errors).toEqual([])
})
})
7 changes: 7 additions & 0 deletions test/fixture/lazy/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ const config = {
// Integration from @Sentry/browser package.
TryCatch: { eventTarget: false }
}
},
publicRuntimeConfig: {
sentry: {
config: {
environment: 'production'
}
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion test/lazy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ describe('Smoke test (lazy)', () => {
await nuxt.close()
})

test('builds and runs', async () => {
test('builds, runs and there are no errors', async () => {
const page = await browser.newPage()

/** @type {string[]} */
const errors = []
page.on('pageerror', (error) => {
errors.push(error.message)
})
await page.goto(url('/'))

expect(await $$('#server-side', page)).toBe('Works!')
expect(await $$('#client-side', page)).toBe('Works and is ready!')
expect(errors).toEqual([])
})
})
6 changes: 6 additions & 0 deletions test/with-lazy-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ describe('Smoke test (lazy config)', () => {
page.on('console', (msg) => {
messages.push(msg.text())
})
/** @type {string[]} */
const errors = []
page.on('pageerror', (error) => {
errors.push(error.message)
})
await page.goto(url('/'))

expect(messages).toEqual(expect.arrayContaining(['Caught expected error on $sentry.captureEvent']))
Expand All @@ -35,5 +40,6 @@ describe('Smoke test (lazy config)', () => {
await page.waitForTimeout(1100)
expect(await $$('#client-side', page)).toBe('Works and is ready!')
expect(messages).toEqual(expect.arrayContaining(['Sentry is ready']))
expect(errors).toEqual([])
})
})

0 comments on commit 074bf77

Please sign in to comment.