Skip to content

Commit

Permalink
test(nuxt): Use sentry.server.config.ts in E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
s1gr1d committed Oct 16, 2024
1 parent 8d5a084 commit 4064157
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 4 deletions.
52 changes: 52 additions & 0 deletions dev-packages/e2e-tests/test-applications/nuxt-3/copyIITM.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import fs from 'fs';
import path from 'path';

/* This script copies the `import-in-the-middle` content of the E2E test project root `node_modules` to the build output `node_modules`
For some reason, some files are missing in the output (like `hook.mjs`) and this is not reproducible in external, standalone projects.
Things we tried (that did not fix the problem):
- Adding a resolution for `@vercel/nft` v0.27.0 (this worked in the standalone project)
- Also adding `@vercel/nft` v0.27.0 to pnpm `peerDependencyRules`
*/
function copyFolderSync(src, dest) {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, { recursive: true });
}

const entries = fs.readdirSync(src, { withFileTypes: true });

for (let entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);

if (entry.isDirectory()) {
copyFolderSync(srcPath, destPath);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}

function getSourceFolder() {
const specificVersionFolder = `node_modules${path.sep}.pnpm${path.sep}[email protected]${path.sep}node_modules${path.sep}import-in-the-middle`;

if (fs.existsSync(specificVersionFolder)) {
return specificVersionFolder;
}

const parentFolder = `node_modules${path.sep}.pnpm`;
const folders = fs.readdirSync(parentFolder, { withFileTypes: true });

for (let folder of folders) {
if (folder.isDirectory() && folder.name.startsWith('import-in-the-middle@')) {
return path.join(parentFolder, folder.name, 'node_modules', 'import-in-the-middle');
}
}

throw new Error('No suitable import-in-the-middle folder found');
}

const sourceFolder = getSourceFolder();
const destinationFolder = `.output${path.sep}server${path.sep}node_modules${path.sep}import-in-the-middle`;

copyFolderSync(sourceFolder, destinationFolder);
5 changes: 4 additions & 1 deletion dev-packages/e2e-tests/test-applications/nuxt-3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"type": "module",
"scripts": {
"build": "nuxt build",
"build": "nuxt build && node ./copyIITM.mjs",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "NODE_OPTIONS='--import ./public/instrument.server.mjs' nuxt preview",
Expand All @@ -20,5 +20,8 @@
"@nuxt/test-utils": "^3.14.1",
"@playwright/test": "^1.44.1",
"@sentry-internal/test-utils": "link:../../../test-utils"
},
"overrides": {
"@vercel/nft": "0.27.4"
}
}
52 changes: 52 additions & 0 deletions dev-packages/e2e-tests/test-applications/nuxt-4/copyIITM.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import fs from 'fs';
import path from 'path';

/* This script copies the `import-in-the-middle` content of the E2E test project root `node_modules` to the build output `node_modules`
For some reason, some files are missing in the output (like `hook.mjs`) and this is not reproducible in external, standalone projects.
Things we tried (that did not fix the problem):
- Adding a resolution for `@vercel/nft` v0.27.0 (this worked in the standalone project)
- Also adding `@vercel/nft` v0.27.0 to pnpm `peerDependencyRules`
*/
function copyFolderSync(src, dest) {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, { recursive: true });
}

const entries = fs.readdirSync(src, { withFileTypes: true });

for (let entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);

if (entry.isDirectory()) {
copyFolderSync(srcPath, destPath);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}

function getSourceFolder() {
const specificVersionFolder = `node_modules${path.sep}.pnpm${path.sep}[email protected]${path.sep}node_modules${path.sep}import-in-the-middle`;

if (fs.existsSync(specificVersionFolder)) {
return specificVersionFolder;
}

const parentFolder = `node_modules${path.sep}.pnpm`;
const folders = fs.readdirSync(parentFolder, { withFileTypes: true });

for (let folder of folders) {
if (folder.isDirectory() && folder.name.startsWith('import-in-the-middle@')) {
return path.join(parentFolder, folder.name, 'node_modules', 'import-in-the-middle');
}
}

throw new Error('No suitable import-in-the-middle folder found');
}

const sourceFolder = getSourceFolder();
const destinationFolder = `.output${path.sep}server${path.sep}node_modules${path.sep}import-in-the-middle`;

copyFolderSync(sourceFolder, destinationFolder);
5 changes: 4 additions & 1 deletion dev-packages/e2e-tests/test-applications/nuxt-4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"type": "module",
"scripts": {
"build": "nuxt build",
"build": "nuxt build && node ./copyIITM.mjs",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "NODE_OPTIONS='--import ./public/instrument.server.mjs' nuxt preview",
Expand All @@ -20,5 +20,8 @@
"@nuxt/test-utils": "^3.14.2",
"@playwright/test": "^1.44.1",
"@sentry-internal/test-utils": "link:../../../test-utils"
},
"overrides": {
"@vercel/nft": "0.27.4"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from '@nuxt/test-utils/playwright';
import { expect, test } from '@playwright/test';
import { waitForError } from '@sentry-internal/test-utils';

test.describe('client-side errors', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from '@nuxt/test-utils/playwright';
import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';
import type { Span } from '@sentry/nuxt';

Expand Down

0 comments on commit 4064157

Please sign in to comment.