From 562a85bb3063407afc6f7099ba532f1bdfdfc358 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Fri, 22 Nov 2024 18:39:26 +0100 Subject: [PATCH] Remove leaking test helper --- .eslintrc.js | 6 -- e2e-tests/tests/nuxt-3.test.ts | 151 ++++++++++++++++++++++++++++-- e2e-tests/tests/nuxt-4.test.ts | 148 +++++++++++++++++++++++++++++- e2e-tests/utils/nuxtHelpers.ts | 162 --------------------------------- 4 files changed, 288 insertions(+), 179 deletions(-) delete mode 100644 e2e-tests/utils/nuxtHelpers.ts diff --git a/.eslintrc.js b/.eslintrc.js index 3c778537..ab7857aa 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -44,12 +44,6 @@ module.exports = { 'jest/globals': true, }, }, - { - files: ['nuxtHelpers.ts'], - rules: { - 'jest/no-export': 'off', - }, - }, ], settings: { jest: { diff --git a/e2e-tests/tests/nuxt-3.test.ts b/e2e-tests/tests/nuxt-3.test.ts index 19d27b1f..7c9fa498 100644 --- a/e2e-tests/tests/nuxt-3.test.ts +++ b/e2e-tests/tests/nuxt-3.test.ts @@ -1,11 +1,18 @@ import * as path from 'path'; -import { cleanupGit, revertLocalChanges } from '../utils'; import { - runWizardOnNuxtProject, - testNuxtProjectBuildsAndRuns, - testNuxtProjectConfigs, - testNuxtProjectSetup, -} from '../utils/nuxtHelpers'; + checkEnvBuildPlugin, + checkFileContents, + checkFileExists, + checkIfBuilds, + checkIfRunsOnProdMode, + checkPackageJson, + cleanupGit, + KEYS, + revertLocalChanges, + startWizardInstance, + TEST_ARGS, +} from '../utils'; +import { Integration } from '../../lib/Constants'; describe('Nuxt-3', () => { const projectDir = path.resolve( @@ -28,3 +35,135 @@ describe('Nuxt-3', () => { testNuxtProjectBuildsAndRuns(projectDir); }); + +async function runWizardOnNuxtProject(projectDir: string): Promise { + const integration = Integration.nuxt; + + const wizardInstance = startWizardInstance(integration, projectDir); + const packageManagerPrompted = await wizardInstance.waitForOutput( + 'Please select your package manager.', + ); + + const tracingOptionPrompted = + packageManagerPrompted && + (await wizardInstance.sendStdinAndWaitForOutput( + // Selecting `yarn` as the package manager + [KEYS.DOWN, KEYS.ENTER], + // "Do you want to enable Tracing", sometimes doesn't work as `Tracing` can be printed in bold. + 'to track the performance of your application?', + { + timeout: 240_000, + }, + )); + + const replayOptionPrompted = + tracingOptionPrompted && + (await wizardInstance.sendStdinAndWaitForOutput( + [KEYS.ENTER], + // "Do you want to enable Sentry Session Replay", sometimes doesn't work as `Sentry Session Replay` can be printed in bold. + 'to get a video-like reproduction of errors during a user session?', + )); + + replayOptionPrompted && + (await wizardInstance.sendStdinAndWaitForOutput( + [KEYS.ENTER], + 'Do you want to create an example page', + { + optional: true, + }, + )); + + await wizardInstance.sendStdinAndWaitForOutput( + [KEYS.ENTER, KEYS.ENTER], + 'Successfully installed the Sentry Nuxt SDK!', + ); + + wizardInstance.kill(); +} + +function testNuxtProjectSetup(projectDir: string) { + const integration = Integration.nuxt; + + test('package.json is updated correctly', () => { + checkPackageJson(projectDir, integration); + }); + + test('.env-sentry-build-plugin is created and contains the auth token', () => { + checkEnvBuildPlugin(projectDir); + }); + + test('config files created', () => { + checkFileExists(`${projectDir}/sentry.server.config.ts`); + checkFileExists(`${projectDir}/sentry.client.config.ts`); + }); + + test('example page exists', () => { + checkFileExists(`${projectDir}/pages/sentry-example-page.vue`); + checkFileExists(`${projectDir}/server/api/sentry-example-api.ts`); + }); +} + +function testNuxtProjectConfigs(projectDir: string) { + test('nuxt config contains sentry module', () => { + checkFileContents(path.resolve(projectDir, 'nuxt.config.ts'), [ + "modules: ['@sentry/nuxt/module'],", + 'sentry: {', + ' sourceMapsUploadOptions: {', + ` org: '${TEST_ARGS.ORG_SLUG}',`, + ` project: '${TEST_ARGS.PROJECT_SLUG}'`, + ' }', + '},', + 'sourcemap: {', + ' client: true', + '}', + ]); + }); + + test('sentry.client.config.ts contents', () => { + checkFileContents(path.resolve(projectDir, 'sentry.client.config.ts'), [ + 'import * as Sentry from "@sentry/nuxt";', + 'Sentry.init({', + ' // If set up, you can use your runtime config here', + ' // dsn: useRuntimeConfig().public.sentry.dsn,', + ` dsn: "${TEST_ARGS.PROJECT_DSN}",`, + ' // We recommend adjusting this value in production, or using tracesSampler', + ' // for finer control', + ' tracesSampleRate: 1.0,', + ' // This sets the sample rate to be 10%. You may want this to be 100% while', + ' // in development and sample at a lower rate in production', + ' replaysSessionSampleRate: 0.1,', + ' // If the entire session is not sampled, use the below sample rate to sample', + ' // sessions when an error occurs.', + ' replaysOnErrorSampleRate: 1.0,', + " // If you don't want to use Session Replay, just remove the line below:", + ' integrations: [Sentry.replayIntegration()],', + " // Setting this option to true will print useful information to the console while you're setting up Sentry.", + ' debug: false,', + '});', + ]); + }); + + test('sentry.server.config.ts contents', () => { + checkFileContents(path.resolve(projectDir, 'sentry.server.config.ts'), [ + 'import * as Sentry from "@sentry/nuxt";', + 'Sentry.init({', + ` dsn: "${TEST_ARGS.PROJECT_DSN}",`, + ' // We recommend adjusting this value in production, or using tracesSampler', + ' // for finer control', + ' tracesSampleRate: 1.0,', + " // Setting this option to true will print useful information to the console while you're setting up Sentry.", + ' debug: false,', + '});', + ]); + }); +} + +function testNuxtProjectBuildsAndRuns(projectDir: string) { + test('builds successfully', async () => { + await checkIfBuilds(projectDir, 'preview this build'); + }); + + test('runs on prod mode correctly', async () => { + await checkIfRunsOnProdMode(projectDir, 'Listening on'); + }); +} diff --git a/e2e-tests/tests/nuxt-4.test.ts b/e2e-tests/tests/nuxt-4.test.ts index 94a6e417..42272f86 100644 --- a/e2e-tests/tests/nuxt-4.test.ts +++ b/e2e-tests/tests/nuxt-4.test.ts @@ -1,11 +1,17 @@ import * as path from 'path'; +import { Integration } from '../../lib/Constants'; import { cleanupGit, revertLocalChanges } from '../utils'; import { - runWizardOnNuxtProject, - testNuxtProjectBuildsAndRuns, - testNuxtProjectConfigs, - testNuxtProjectSetup, -} from '../utils/nuxtHelpers'; + checkEnvBuildPlugin, + checkFileContents, + checkFileExists, + checkIfBuilds, + checkIfRunsOnProdMode, + checkPackageJson, + KEYS, + startWizardInstance, + TEST_ARGS, +} from './index'; describe('Nuxt-4', () => { const projectDir = path.resolve( @@ -28,3 +34,135 @@ describe('Nuxt-4', () => { testNuxtProjectBuildsAndRuns(projectDir); }); + +async function runWizardOnNuxtProject(projectDir: string): Promise { + const integration = Integration.nuxt; + + const wizardInstance = startWizardInstance(integration, projectDir); + const packageManagerPrompted = await wizardInstance.waitForOutput( + 'Please select your package manager.', + ); + + const tracingOptionPrompted = + packageManagerPrompted && + (await wizardInstance.sendStdinAndWaitForOutput( + // Selecting `yarn` as the package manager + [KEYS.DOWN, KEYS.ENTER], + // "Do you want to enable Tracing", sometimes doesn't work as `Tracing` can be printed in bold. + 'to track the performance of your application?', + { + timeout: 240_000, + }, + )); + + const replayOptionPrompted = + tracingOptionPrompted && + (await wizardInstance.sendStdinAndWaitForOutput( + [KEYS.ENTER], + // "Do you want to enable Sentry Session Replay", sometimes doesn't work as `Sentry Session Replay` can be printed in bold. + 'to get a video-like reproduction of errors during a user session?', + )); + + replayOptionPrompted && + (await wizardInstance.sendStdinAndWaitForOutput( + [KEYS.ENTER], + 'Do you want to create an example page', + { + optional: true, + }, + )); + + await wizardInstance.sendStdinAndWaitForOutput( + [KEYS.ENTER, KEYS.ENTER], + 'Successfully installed the Sentry Nuxt SDK!', + ); + + wizardInstance.kill(); +} + +function testNuxtProjectSetup(projectDir: string) { + const integration = Integration.nuxt; + + test('package.json is updated correctly', () => { + checkPackageJson(projectDir, integration); + }); + + test('.env-sentry-build-plugin is created and contains the auth token', () => { + checkEnvBuildPlugin(projectDir); + }); + + test('config files created', () => { + checkFileExists(`${projectDir}/sentry.server.config.ts`); + checkFileExists(`${projectDir}/sentry.client.config.ts`); + }); + + test('example page exists', () => { + checkFileExists(`${projectDir}'/app/pages/sentry-example-page.vue`); + checkFileExists(`${projectDir}/server/api/sentry-example-api.ts`); + }); +} + +function testNuxtProjectConfigs(projectDir: string) { + test('nuxt config contains sentry module', () => { + checkFileContents(path.resolve(projectDir, 'nuxt.config.ts'), [ + "modules: ['@sentry/nuxt/module'],", + 'sentry: {', + ' sourceMapsUploadOptions: {', + ` org: '${TEST_ARGS.ORG_SLUG}',`, + ` project: '${TEST_ARGS.PROJECT_SLUG}'`, + ' }', + '},', + 'sourcemap: {', + ' client: true', + '}', + ]); + }); + + test('sentry.client.config.ts contents', () => { + checkFileContents(path.resolve(projectDir, 'sentry.client.config.ts'), [ + 'import * as Sentry from "@sentry/nuxt";', + 'Sentry.init({', + ' // If set up, you can use your runtime config here', + ' // dsn: useRuntimeConfig().public.sentry.dsn,', + ` dsn: "${TEST_ARGS.PROJECT_DSN}",`, + ' // We recommend adjusting this value in production, or using tracesSampler', + ' // for finer control', + ' tracesSampleRate: 1.0,', + ' // This sets the sample rate to be 10%. You may want this to be 100% while', + ' // in development and sample at a lower rate in production', + ' replaysSessionSampleRate: 0.1,', + ' // If the entire session is not sampled, use the below sample rate to sample', + ' // sessions when an error occurs.', + ' replaysOnErrorSampleRate: 1.0,', + " // If you don't want to use Session Replay, just remove the line below:", + ' integrations: [Sentry.replayIntegration()],', + " // Setting this option to true will print useful information to the console while you're setting up Sentry.", + ' debug: false,', + '});', + ]); + }); + + test('sentry.server.config.ts contents', () => { + checkFileContents(path.resolve(projectDir, 'sentry.server.config.ts'), [ + 'import * as Sentry from "@sentry/nuxt";', + 'Sentry.init({', + ` dsn: "${TEST_ARGS.PROJECT_DSN}",`, + ' // We recommend adjusting this value in production, or using tracesSampler', + ' // for finer control', + ' tracesSampleRate: 1.0,', + " // Setting this option to true will print useful information to the console while you're setting up Sentry.", + ' debug: false,', + '});', + ]); + }); +} + +function testNuxtProjectBuildsAndRuns(projectDir: string) { + test('builds successfully', async () => { + await checkIfBuilds(projectDir, 'preview this build'); + }); + + test('runs on prod mode correctly', async () => { + await checkIfRunsOnProdMode(projectDir, 'Listening on'); + }); +} diff --git a/e2e-tests/utils/nuxtHelpers.ts b/e2e-tests/utils/nuxtHelpers.ts deleted file mode 100644 index dd190902..00000000 --- a/e2e-tests/utils/nuxtHelpers.ts +++ /dev/null @@ -1,162 +0,0 @@ -import * as fs from 'fs'; -import * as path from 'path'; -import { Integration } from '../../lib/Constants'; -import { - checkEnvBuildPlugin, - checkFileContents, - checkFileExists, - checkIfBuilds, - checkIfRunsOnProdMode, - checkPackageJson, - KEYS, - startWizardInstance, - TEST_ARGS, -} from './index'; - -export async function runWizardOnNuxtProject( - projectDir: string, -): Promise { - const integration = Integration.nuxt; - - const wizardInstance = startWizardInstance(integration, projectDir); - const packageManagerPrompted = await wizardInstance.waitForOutput( - 'Please select your package manager.', - ); - - const tracingOptionPrompted = - packageManagerPrompted && - (await wizardInstance.sendStdinAndWaitForOutput( - // Selecting `yarn` as the package manager - [KEYS.DOWN, KEYS.ENTER], - // "Do you want to enable Tracing", sometimes doesn't work as `Tracing` can be printed in bold. - 'to track the performance of your application?', - { - timeout: 240_000, - }, - )); - - const replayOptionPrompted = - tracingOptionPrompted && - (await wizardInstance.sendStdinAndWaitForOutput( - [KEYS.ENTER], - // "Do you want to enable Sentry Session Replay", sometimes doesn't work as `Sentry Session Replay` can be printed in bold. - 'to get a video-like reproduction of errors during a user session?', - )); - - replayOptionPrompted && - (await wizardInstance.sendStdinAndWaitForOutput( - [KEYS.ENTER], - 'Do you want to create an example page', - { - optional: true, - }, - )); - - await wizardInstance.sendStdinAndWaitForOutput( - [KEYS.ENTER, KEYS.ENTER], - 'Successfully installed the Sentry Nuxt SDK!', - ); - - wizardInstance.kill(); -} - -function isNuxtV4(projectDir: string) { - // This needs to be replaced with looking up the package - // version once Nuxt 4 is released as its own package. - const fileContent = fs.readFileSync( - path.resolve(projectDir, 'nuxt.config.ts'), - 'utf-8', - ); - - return fileContent.includes('future: { compatibilityVersion: 4 }'); -} - -export function testNuxtProjectSetup(projectDir: string) { - const integration = Integration.nuxt; - const isV4 = isNuxtV4(projectDir); - - test('package.json is updated correctly', () => { - checkPackageJson(projectDir, integration); - }); - - test('.env-sentry-build-plugin is created and contains the auth token', () => { - checkEnvBuildPlugin(projectDir); - }); - - test('config files created', () => { - checkFileExists(`${projectDir}/sentry.server.config.ts`); - checkFileExists(`${projectDir}/sentry.client.config.ts`); - }); - - test('example page exists', () => { - checkFileExists( - `${projectDir}${isV4 ? '/app' : ''}/pages/sentry-example-page.vue`, - ); - checkFileExists(`${projectDir}/server/api/sentry-example-api.ts`); - }); -} - -export function testNuxtProjectConfigs(projectDir: string) { - test('nuxt config contains sentry module', () => { - checkFileContents(path.resolve(projectDir, 'nuxt.config.ts'), [ - "modules: ['@sentry/nuxt/module'],", - 'sentry: {', - ' sourceMapsUploadOptions: {', - ` org: '${TEST_ARGS.ORG_SLUG}',`, - ` project: '${TEST_ARGS.PROJECT_SLUG}'`, - ' }', - '},', - 'sourcemap: {', - ' client: true', - '}', - ]); - }); - - test('sentry.client.config.ts contents', () => { - checkFileContents(path.resolve(projectDir, 'sentry.client.config.ts'), [ - 'import * as Sentry from "@sentry/nuxt";', - 'Sentry.init({', - ' // If set up, you can use your runtime config here', - ' // dsn: useRuntimeConfig().public.sentry.dsn,', - ` dsn: "${TEST_ARGS.PROJECT_DSN}",`, - ' // We recommend adjusting this value in production, or using tracesSampler', - ' // for finer control', - ' tracesSampleRate: 1.0,', - ' // This sets the sample rate to be 10%. You may want this to be 100% while', - ' // in development and sample at a lower rate in production', - ' replaysSessionSampleRate: 0.1,', - ' // If the entire session is not sampled, use the below sample rate to sample', - ' // sessions when an error occurs.', - ' replaysOnErrorSampleRate: 1.0,', - " // If you don't want to use Session Replay, just remove the line below:", - ' integrations: [Sentry.replayIntegration()],', - " // Setting this option to true will print useful information to the console while you're setting up Sentry.", - ' debug: false,', - '});', - ]); - }); - - test('sentry.server.config.ts contents', () => { - checkFileContents(path.resolve(projectDir, 'sentry.server.config.ts'), [ - 'import * as Sentry from "@sentry/nuxt";', - 'Sentry.init({', - ` dsn: "${TEST_ARGS.PROJECT_DSN}",`, - ' // We recommend adjusting this value in production, or using tracesSampler', - ' // for finer control', - ' tracesSampleRate: 1.0,', - " // Setting this option to true will print useful information to the console while you're setting up Sentry.", - ' debug: false,', - '});', - ]); - }); -} - -export function testNuxtProjectBuildsAndRuns(projectDir: string) { - test('builds successfully', async () => { - await checkIfBuilds(projectDir, 'preview this build'); - }); - - test('runs on prod mode correctly', async () => { - await checkIfRunsOnProdMode(projectDir, 'Listening on'); - }); -}