Skip to content

test(nuxt): Add Nuxt 3 E2E test for client-side #13002

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 6 commits into from
Jul 22, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ jobs:
'node-exports-test-app',
'node-koa',
'node-connect',
'nuxt-3',
'vue-3',
'webpack-4',
'webpack-5'
Expand Down
24 changes: 24 additions & 0 deletions dev-packages/e2e-tests/test-applications/nuxt-3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Nuxt dev/build outputs
.output
.data
.nuxt
.nitro
.cache
dist

# Node dependencies
node_modules

# Logs
logs
*.log

# Misc
.DS_Store
.fleet
.idea

# Local env files
.env
.env.*
!.env.example
2 changes: 2 additions & 0 deletions dev-packages/e2e-tests/test-applications/nuxt-3/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@sentry:registry=http://127.0.0.1:4873
@sentry-internal:registry=http://127.0.0.1:4873
13 changes: 13 additions & 0 deletions dev-packages/e2e-tests/test-applications/nuxt-3/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<NuxtLayout>
<header>
<nav>
<ul>
<li><NuxtLink to="/client-error">Client Error</NuxtLink></li>
</ul>
</nav>
</header>
<NuxtPage />
</NuxtLayout>
</template>

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup>
const triggerError = () => {
throw new Error('Error thrown from Nuxt-3 E2E test app');
};
</script>

<template>
<button id="errorBtn" @click="triggerError">Trigger Error</button>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
modules: ['@sentry/nuxt/module'],
});
24 changes: 24 additions & 0 deletions dev-packages/e2e-tests/test-applications/nuxt-3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "nuxt-3",
"private": true,
"type": "module",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"clean": "npx nuxi cleanup",
"test": "playwright test",
"test:build": "pnpm install && npx playwright install && pnpm build",
"test:assert": "pnpm test"
},
"dependencies": {
"@sentry/nuxt": "latest || *",
"nuxt": "3.11.2"
},
"devDependencies": {
"@nuxt/test-utils": "^3.13.1",
"@playwright/test": "^1.44.1",
"@sentry-internal/test-utils": "link:../../../test-utils"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script setup>
import ErrorButton from '../components/ErrorButton.vue';
</script>

<template>
<ErrorButton />
</template>



Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<h1>Hello!</h1>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { fileURLToPath } from 'node:url';
import type { ConfigOptions } from '@nuxt/test-utils/playwright';
import { getPlaywrightConfig } from '@sentry-internal/test-utils';

const nuxtConfigOptions: ConfigOptions = {
nuxt: {
rootDir: fileURLToPath(new URL('.', import.meta.url)),
},
};

const config = getPlaywrightConfig({
startCommand: `pnpm preview`,
use: { ...nuxtConfigOptions },
});

export default config;
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Sentry from '@sentry/nuxt';

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: 'https://[email protected]/1337',
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1.0,
integrations: [Sentry.browserTracingIntegration()],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { startEventProxyServer } from '@sentry-internal/test-utils';

startEventProxyServer({
port: 3031,
proxyServerName: 'nuxt-3',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { expect, test } from '@nuxt/test-utils/playwright';
import { waitForError } from '@sentry-internal/test-utils';

test.describe('client-side errors', async () => {
test('captures error thrown on click', async ({ page }) => {
const errorPromise = waitForError('nuxt-3', async errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'Error thrown from Nuxt-3 E2E test app';
});

await page.goto(`/client-error`);
await page.locator('#errorBtn').click();

const error = await errorPromise;

expect(error).toMatchObject({
exception: {
values: [
{
type: 'Error',
value: 'Error thrown from Nuxt-3 E2E test app',
mechanism: {
handled: false,
},
},
],
},
});
expect(error.transaction).toEqual('/client-error');
});
});
4 changes: 4 additions & 0 deletions dev-packages/e2e-tests/test-applications/nuxt-3/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
// https://nuxt.com/docs/guide/concepts/typescript
"extends": "./.nuxt/tsconfig.json"
}
Loading