Skip to content

Commit

Permalink
Remove leaking test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiborza committed Nov 22, 2024
1 parent 0c0ce30 commit 562a85b
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 179 deletions.
6 changes: 0 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ module.exports = {
'jest/globals': true,
},
},
{
files: ['nuxtHelpers.ts'],
rules: {
'jest/no-export': 'off',
},
},
],
settings: {
jest: {
Expand Down
151 changes: 145 additions & 6 deletions e2e-tests/tests/nuxt-3.test.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -28,3 +35,135 @@ describe('Nuxt-3', () => {

testNuxtProjectBuildsAndRuns(projectDir);
});

async function runWizardOnNuxtProject(projectDir: string): Promise<void> {
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');
});
}
148 changes: 143 additions & 5 deletions e2e-tests/tests/nuxt-4.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Check failure on line 14 in e2e-tests/tests/nuxt-4.test.ts

View workflow job for this annotation

GitHub Actions / Build

Cannot find module './index' or its corresponding type declarations.

describe('Nuxt-4', () => {
const projectDir = path.resolve(
Expand All @@ -28,3 +34,135 @@ describe('Nuxt-4', () => {

testNuxtProjectBuildsAndRuns(projectDir);
});

async function runWizardOnNuxtProject(projectDir: string): Promise<void> {
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');
});
}
Loading

0 comments on commit 562a85b

Please sign in to comment.