- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.7k
feat(nuxt): Add Sentry Pinia plugin #14047
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
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            3 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            73 changes: 73 additions & 0 deletions
          
          73 
        
  dev-packages/e2e-tests/test-applications/nuxt-4/app/pages/pinia-cart.vue
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| <script setup lang="ts"> | ||
| import { ref } from '#imports' | ||
| import { useCartStore } from '~~/stores/cart' | ||
|  | ||
| const cart = useCartStore() | ||
|  | ||
| const itemName = ref('') | ||
|  | ||
| function addItemToCart() { | ||
| if (!itemName.value) return | ||
| cart.addItem(itemName.value) | ||
| itemName.value = '' | ||
| } | ||
|  | ||
| function throwError() { | ||
| throw new Error('This is an error') | ||
| } | ||
|  | ||
| function clearCart() { | ||
| if (window.confirm('Are you sure you want to clear the cart?')) { | ||
| cart.rawItems = [] | ||
| } | ||
| } | ||
| </script> | ||
|  | ||
| <template> | ||
| <Layout> | ||
| <div> | ||
| <div style="margin: 1rem 0;"> | ||
| <PiniaLogo /> | ||
| </div> | ||
|  | ||
| <form @submit.prevent="addItemToCart" data-testid="add-items"> | ||
| <input id="item-input" type="text" v-model="itemName" /> | ||
| <button id="item-add">Add</button> | ||
| <button id="throw-error" @click="throwError">Throw error</button> | ||
| </form> | ||
|  | ||
| <form> | ||
| <ul data-testid="items"> | ||
| <li v-for="item in cart.items" :key="item.name"> | ||
| {{ item.name }} ({{ item.amount }}) | ||
| <button | ||
| @click="cart.removeItem(item.name)" | ||
| type="button" | ||
| >X</button> | ||
| </li> | ||
| </ul> | ||
|  | ||
| <button | ||
| :disabled="!cart.items.length" | ||
| @click="clearCart" | ||
| type="button" | ||
| data-testid="clear" | ||
| >Clear the cart</button> | ||
| </form> | ||
| </div> | ||
| </Layout> | ||
| </template> | ||
|  | ||
|  | ||
|  | ||
| <style scoped> | ||
| img { | ||
| width: 200px; | ||
| } | ||
|  | ||
| button, | ||
| input { | ||
| margin-right: 0.5rem; | ||
| margin-bottom: 0.5rem; | ||
| } | ||
| </style> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            43 changes: 43 additions & 0 deletions
          
          43 
        
  dev-packages/e2e-tests/test-applications/nuxt-4/stores/cart.ts
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { acceptHMRUpdate, defineStore } from '#imports'; | ||
|  | ||
| export const useCartStore = defineStore({ | ||
| id: 'cart', | ||
| state: () => ({ | ||
| rawItems: [] as string[], | ||
| }), | ||
| getters: { | ||
| items: (state): Array<{ name: string; amount: number }> => | ||
| state.rawItems.reduce( | ||
| (items: any, item: any) => { | ||
| const existingItem = items.find((it: any) => it.name === item); | ||
|  | ||
| if (!existingItem) { | ||
| items.push({ name: item, amount: 1 }); | ||
| } else { | ||
| existingItem.amount++; | ||
| } | ||
|  | ||
| return items; | ||
| }, | ||
| [] as Array<{ name: string; amount: number }>, | ||
| ), | ||
| }, | ||
| actions: { | ||
| addItem(name: string) { | ||
| this.rawItems.push(name); | ||
| }, | ||
|  | ||
| removeItem(name: string) { | ||
| const i = this.rawItems.lastIndexOf(name); | ||
| if (i > -1) this.rawItems.splice(i, 1); | ||
| }, | ||
|  | ||
| throwError() { | ||
| throw new Error('error'); | ||
| }, | ||
| }, | ||
| }); | ||
|  | ||
| if (import.meta.hot) { | ||
| import.meta.hot.accept(acceptHMRUpdate(useCartStore, import.meta.hot)); | ||
| } | 
        
          
          
            35 changes: 35 additions & 0 deletions
          
          35 
        
  dev-packages/e2e-tests/test-applications/nuxt-4/tests/pinia.test.ts
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForError } from '@sentry-internal/test-utils'; | ||
|  | ||
| test('sends pinia action breadcrumbs and state context', async ({ page }) => { | ||
| await page.goto('/pinia-cart'); | ||
|  | ||
| await page.locator('#item-input').fill('item'); | ||
| await page.locator('#item-add').click(); | ||
|  | ||
| const errorPromise = waitForError('nuxt-4', async errorEvent => { | ||
| return errorEvent?.exception?.values?.[0].value === 'This is an error'; | ||
| }); | ||
|  | ||
| await page.locator('#throw-error').click(); | ||
|  | ||
| const error = await errorPromise; | ||
|  | ||
| expect(error).toBeTruthy(); | ||
| expect(error.breadcrumbs?.length).toBeGreaterThan(0); | ||
|  | ||
| const actionBreadcrumb = error.breadcrumbs?.find(breadcrumb => breadcrumb.category === 'action'); | ||
|  | ||
| expect(actionBreadcrumb).toBeDefined(); | ||
| expect(actionBreadcrumb?.message).toBe('Transformed: addItem'); | ||
| expect(actionBreadcrumb?.level).toBe('info'); | ||
|  | ||
| const stateContext = error.contexts?.state?.state; | ||
|  | ||
| expect(stateContext).toBeDefined(); | ||
| expect(stateContext?.type).toBe('pinia'); | ||
| expect(stateContext?.value).toEqual({ | ||
| transformed: true, | ||
| rawItems: ['item'], | ||
| }); | ||
| }); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.