Skip to content

test: Ensure browser-integration-tests cannot conflict due to build #13338

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 2 commits into from
Aug 14, 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import path from 'path';
import * as fs from 'fs';
import * as path from 'path';
import { expect } from '@playwright/test';

import { TEST_HOST, sentryTest } from '../../../../utils/fixtures';
Expand Down Expand Up @@ -28,19 +28,22 @@ sentryTest('it does not download the SDK if the SDK was loaded in the meanwhile'
});
});

const tmpDir = await getLocalTestUrl({ testDir: __dirname, skipRouteHandler: true });

await page.route(`${TEST_HOST}/*.*`, route => {
const file = route.request().url().split('/').pop();

if (file === 'cdn.bundle.js') {
cdnLoadedCount++;
}

const filePath = path.resolve(__dirname, `./dist/${file}`);
const filePath = path.resolve(tmpDir, `./${file}`);

return fs.existsSync(filePath) ? route.fulfill({ path: filePath }) : route.continue();
});

const url = await getLocalTestUrl({ testDir: __dirname, skipRouteHandler: true });
const url = `${TEST_HOST}/index.html`;

const req = await waitForErrorRequestOnUrl(page, url);

const eventData = envelopeRequestParser(req);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const config: PlaywrightTestConfig = {
],

globalSetup: require.resolve('./playwright.setup.ts'),
globalTeardown: require.resolve('./playwright.teardown.ts'),
};

export default config;
5 changes: 5 additions & 0 deletions dev-packages/browser-integration-tests/playwright.teardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as childProcess from 'child_process';

export default function globalTeardown(): void {
childProcess.execSync('yarn clean', { stdio: 'inherit', cwd: process.cwd() });
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fetch('http://localhost:7654/foo').then(() => {
fetch('http://sentry-test.io/foo').then(() => {
Sentry.captureException('test error');
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sentryTest('captures Breadcrumb for basic GET request', async ({ getLocalTestUrl
data: {
method: 'GET',
status_code: 200,
url: 'http://localhost:7654/foo',
url: 'http://sentry-test.io/foo',
},
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fetch(new Request('http://localhost:7654/foo')).then(() => {
fetch(new Request('http://sentry-test.io/foo')).then(() => {
Sentry.captureException('test error');
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sentryTest('captures Breadcrumb for basic GET request that uses request object',
data: {
method: 'GET',
status_code: 200,
url: 'http://localhost:7654/foo',
url: 'http://sentry-test.io/foo',
},
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fetch('http://localhost:7654/foo', {
fetch('http://sentry-test.io/foo', {
method: 'POST',
body: '{"my":"body"}',
headers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sentryTest('captures Breadcrumb for POST request', async ({ getLocalTestUrl, pag
data: {
method: 'POST',
status_code: 200,
url: 'http://localhost:7654/foo',
url: 'http://sentry-test.io/foo',
},
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const xhr = new XMLHttpRequest();

xhr.open('GET', 'http://localhost:7654/foo');
xhr.open('GET', 'http://sentry-test.io/foo');
xhr.send();

xhr.addEventListener('readystatechange', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sentryTest('captures Breadcrumb for basic GET request', async ({ getLocalTestUrl
data: {
method: 'GET',
status_code: 200,
url: 'http://localhost:7654/foo',
url: 'http://sentry-test.io/foo',
},
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const xhr = new XMLHttpRequest();

xhr.open('POST', 'http://localhost:7654/foo');
xhr.open('POST', 'http://sentry-test.io/foo');
xhr.setRequestHeader('Accept', 'application/json');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send('{"my":"body"}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sentryTest('captures Breadcrumb for POST request', async ({ getLocalTestUrl, pag
data: {
method: 'POST',
status_code: 200,
url: 'http://localhost:7654/foo',
url: 'http://sentry-test.io/foo',
},
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';

axios
.get('http://localhost:7654/foo', {
.get('http://sentry-test.io/foo', {
headers: { Accept: 'application/json', 'Content-Type': 'application/json', Cache: 'no-cache' },
})
.then(response => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sentryTest(
],
},
request: {
url: 'http://localhost:7654/foo',
url: 'http://sentry-test.io/foo',
method: 'GET',
headers: {
accept: 'application/json',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fetch('http://localhost:7654/foo', {
fetch('http://sentry-test.io/foo', {
method: 'GET',
credentials: 'include',
headers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ sentryTest(
],
},
request: {
url: 'http://localhost:7654/foo',
url: 'http://sentry-test.io/foo',
method: 'GET',
headers: {
accept: 'application/json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const startFetch = e => {
forceTransaction: true,
},
async () => {
await fetch('http://localhost:7654/foo', { signal })
await fetch('http://sentry-test.io/foo', { signal })
.then(response => response.json())
.then(data => {
console.log('Fetch succeeded:', data);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const request = new Request('http://localhost:7654/foo', {
const request = new Request('http://sentry-test.io/foo', {
method: 'POST',
credentials: 'include',
headers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ sentryTest('works with a Request passed in', async ({ getLocalTestPath, page })
],
},
request: {
url: 'http://localhost:7654/foo',
url: 'http://sentry-test.io/foo',
method: 'POST',
headers: {
accept: 'application/json',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const request = new Request('http://localhost:7654/foo', {
const request = new Request('http://sentry-test.io/foo', {
method: 'POST',
credentials: 'include',
headers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sentryTest(
],
},
request: {
url: 'http://localhost:7654/foo',
url: 'http://sentry-test.io/foo',
method: 'POST',
headers: {
accept: 'application/json',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const request = new Request('http://localhost:7654/foo', {
const request = new Request('http://sentry-test.io/foo', {
method: 'POST',
credentials: 'include',
headers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ sentryTest('works with a Request (without body) & options passed in', async ({ g
],
},
request: {
url: 'http://localhost:7654/foo',
url: 'http://sentry-test.io/foo',
method: 'POST',
headers: {
accept: 'application/json',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const xhr = new XMLHttpRequest();

xhr.open('GET', 'http://localhost:7654/foo', true);
xhr.open('GET', 'http://sentry-test.io/foo', true);
xhr.withCredentials = true;
xhr.setRequestHeader('Accept', 'application/json');
xhr.setRequestHeader('Content-Type', 'application/json');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ sentryTest('works with httpClientIntegration', async ({ getLocalTestPath, page }
],
},
request: {
url: 'http://localhost:7654/foo',
url: 'http://sentry-test.io/foo',
method: 'GET',
headers: {
accept: 'application/json',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const xhr = new XMLHttpRequest();

xhr.open('GET', 'http://localhost:7654/foo', true);
xhr.open('GET', 'http://sentry-test.io/foo', true);
xhr.withCredentials = true;
xhr.setRequestHeader('Accept', 'application/json');
xhr.setRequestHeader('Content-Type', 'application/json');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sentryTest(
],
},
request: {
url: 'http://localhost:7654/foo',
url: 'http://sentry-test.io/foo',
method: 'GET',
headers: {
accept: 'application/json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { expect } from '@playwright/test';
import { sentryTest } from '../../../../utils/fixtures';

// Regression test against https://github.com/getsentry/sentry-javascript/pull/1896
sentryTest('should not contain tslib_1__default', async ({ getLocalTestPath }) => {
await getLocalTestPath({ testDir: __dirname });
sentryTest('should not contain tslib_1__default', async ({ getLocalTestUrl }) => {
const tmpDir = await getLocalTestUrl({ testDir: __dirname, skipRouteHandler: true });

const initBundle = fs.readFileSync(path.join(__dirname, 'dist', 'init.bundle.js'), 'utf-8');
const initBundle = fs.readFileSync(path.join(tmpDir, 'init.bundle.js'), 'utf-8');
expect(initBundle.length).toBeGreaterThan(0);
expect(initBundle).not.toContain('tslib_1__default');

const subjectBundle = fs.readFileSync(path.join(__dirname, 'dist', 'subject.bundle.js'), 'utf-8');
const subjectBundle = fs.readFileSync(path.join(tmpDir, 'subject.bundle.js'), 'utf-8');
expect(subjectBundle.length).toBeGreaterThan(0);
expect(subjectBundle).not.toContain('tslib_1__default');
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalT
timestamp: expect.any(Number),
error_ids: [],
trace_ids: [],
urls: [expect.stringContaining('/dist/index.html')],
urls: [expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/)],
replay_id: expect.stringMatching(/\w{32}/),
replay_start_timestamp: expect.any(Number),
segment_id: 0,
Expand All @@ -57,7 +57,7 @@ sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalT
name: 'sentry.javascript.browser',
},
request: {
url: expect.stringContaining('/dist/index.html'),
url: expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/),
headers: {
'User-Agent': expect.stringContaining(''),
},
Expand Down Expand Up @@ -94,7 +94,7 @@ sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalT
name: 'sentry.javascript.browser',
},
request: {
url: expect.stringContaining('/dist/index.html'),
url: expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/),
headers: {
'User-Agent': expect.stringContaining(''),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sentryTest('should capture replays (@sentry-internal/replay export)', async ({ g
timestamp: expect.any(Number),
error_ids: [],
trace_ids: [],
urls: [expect.stringContaining('/dist/index.html')],
urls: [expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/)],
replay_id: expect.stringMatching(/\w{32}/),
replay_start_timestamp: expect.any(Number),
segment_id: 0,
Expand All @@ -57,7 +57,7 @@ sentryTest('should capture replays (@sentry-internal/replay export)', async ({ g
name: 'sentry.javascript.browser',
},
request: {
url: expect.stringContaining('/dist/index.html'),
url: expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/),
headers: {
'User-Agent': expect.stringContaining(''),
},
Expand Down Expand Up @@ -94,7 +94,7 @@ sentryTest('should capture replays (@sentry-internal/replay export)', async ({ g
name: 'sentry.javascript.browser',
},
request: {
url: expect.stringContaining('/dist/index.html'),
url: expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/),
headers: {
'User-Agent': expect.stringContaining(''),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ window.Replay = Sentry.replayIntegration({
flushMaxDelay: 200,
minReplayDuration: 0,

networkDetailAllowUrls: ['http://localhost:7654/foo', 'http://sentry-test.io/foo'],
networkDetailAllowUrls: ['http://sentry-test.io/foo'],
networkCaptureBodies: true,
});

Expand Down
Loading
Loading