Skip to content

Commit

Permalink
Add nuxt 4 e2e test app
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiborza committed Nov 22, 2024
1 parent 6f3fadf commit 0c0ce30
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 184 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ module.exports = {
'jest/globals': true,
},
},
{
files: ['nuxtHelpers.ts'],
rules: {
'jest/no-export': 'off',
},
},
],
settings: {
jest: {
Expand Down
192 changes: 8 additions & 184 deletions e2e-tests/tests/nuxt-3.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import * as path from 'path';
import { Integration } from '../../lib/Constants';
import { cleanupGit, revertLocalChanges } from '../utils';
import {
checkEnvBuildPlugin,
checkFileContents,
checkFileExists,
checkIfBuilds,
checkIfRunsOnProdMode,
checkPackageJson,
cleanupGit,
KEYS,
revertLocalChanges,
startWizardInstance,
TEST_ARGS,
} from '../utils';
import fs from 'fs';
runWizardOnNuxtProject,
testNuxtProjectBuildsAndRuns,
testNuxtProjectConfigs,
testNuxtProjectSetup,
} from '../utils/nuxtHelpers';

describe('Nuxt 3', () => {
describe('Nuxt-3', () => {
const projectDir = path.resolve(
__dirname,
'../test-applications/nuxt-3-test-app',
Expand All @@ -34,173 +26,5 @@ describe('Nuxt 3', () => {

testNuxtProjectConfigs(projectDir);

testNuxtProjectBuildAndRun(projectDir);
testNuxtProjectBuildsAndRuns(projectDir);
});

describe('Nuxt 4', () => {
const projectDir = path.resolve(
__dirname,
'../test-applications/nuxt-4-test-app',
);

beforeAll(async () => {
await runWizardOnNuxtProject(projectDir);
});

afterAll(() => {
revertLocalChanges(projectDir);
cleanupGit(projectDir);
});

testNuxtProjectSetup(projectDir);

testNuxtProjectConfigs(projectDir);

testNuxtProjectBuildAndRun(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 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 }');
}

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`);
});
}

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 testNuxtProjectBuildAndRun(projectDir: string) {
test('builds successfully', async () => {
await checkIfBuilds(projectDir, 'preview this build');
});

test('runs on prod mode correctly', async () => {
await checkIfRunsOnProdMode(projectDir, 'Listening on');
});
}
30 changes: 30 additions & 0 deletions e2e-tests/tests/nuxt-4.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as path from 'path';
import { cleanupGit, revertLocalChanges } from '../utils';
import {
runWizardOnNuxtProject,
testNuxtProjectBuildsAndRuns,
testNuxtProjectConfigs,
testNuxtProjectSetup,
} from '../utils/nuxtHelpers';

describe('Nuxt-4', () => {
const projectDir = path.resolve(
__dirname,
'../test-applications/nuxt-4-test-app',
);

beforeAll(async () => {
await runWizardOnNuxtProject(projectDir);
});

afterAll(() => {
revertLocalChanges(projectDir);
cleanupGit(projectDir);
});

testNuxtProjectSetup(projectDir);

testNuxtProjectConfigs(projectDir);

testNuxtProjectBuildsAndRuns(projectDir);
});
Loading

0 comments on commit 0c0ce30

Please sign in to comment.