Skip to content

Commit 23980a0

Browse files
authored
test: Ensure browser-integration-tests cannot conflict due to build (#13338)
This streamlines some stuff in our browser integration tests, to fix some flakiness (hopefully). The biggest change is that instead of always building into `dist` for each test file, each test will now build into a random subfolder, e.g. `dist/abc`. This way, multiple tests in a single file will never conflict with each other. Additionally it also streamlines some of the tests I encountered while looking at stuff, hopefully reducing flakes further. Closes #13321
1 parent 0af5b4f commit 23980a0

File tree

59 files changed

+516
-620
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+516
-620
lines changed

dev-packages/browser-integration-tests/loader-suites/loader/noOnLoad/sdkLoadedInMeanwhile/test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import fs from 'fs';
2-
import path from 'path';
1+
import * as fs from 'fs';
2+
import * as path from 'path';
33
import { expect } from '@playwright/test';
44

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

31+
const tmpDir = await getLocalTestUrl({ testDir: __dirname, skipRouteHandler: true });
32+
3133
await page.route(`${TEST_HOST}/*.*`, route => {
3234
const file = route.request().url().split('/').pop();
3335

3436
if (file === 'cdn.bundle.js') {
3537
cdnLoadedCount++;
3638
}
3739

38-
const filePath = path.resolve(__dirname, `./dist/${file}`);
40+
const filePath = path.resolve(tmpDir, `./${file}`);
3941

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

43-
const url = await getLocalTestUrl({ testDir: __dirname, skipRouteHandler: true });
45+
const url = `${TEST_HOST}/index.html`;
46+
4447
const req = await waitForErrorRequestOnUrl(page, url);
4548

4649
const eventData = envelopeRequestParser(req);

dev-packages/browser-integration-tests/playwright.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const config: PlaywrightTestConfig = {
3131
],
3232

3333
globalSetup: require.resolve('./playwright.setup.ts'),
34+
globalTeardown: require.resolve('./playwright.teardown.ts'),
3435
};
3536

3637
export default config;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as childProcess from 'child_process';
2+
3+
export default function globalTeardown(): void {
4+
childProcess.execSync('yarn clean', { stdio: 'inherit', cwd: process.cwd() });
5+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
fetch('http://localhost:7654/foo').then(() => {
1+
fetch('http://sentry-test.io/foo').then(() => {
22
Sentry.captureException('test error');
33
});

dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/fetch/get/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ sentryTest('captures Breadcrumb for basic GET request', async ({ getLocalTestUrl
3131
data: {
3232
method: 'GET',
3333
status_code: 200,
34-
url: 'http://localhost:7654/foo',
34+
url: 'http://sentry-test.io/foo',
3535
},
3636
});
3737
});
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
fetch(new Request('http://localhost:7654/foo')).then(() => {
1+
fetch(new Request('http://sentry-test.io/foo')).then(() => {
22
Sentry.captureException('test error');
33
});

dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/fetch/getWithRequestObj/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ sentryTest('captures Breadcrumb for basic GET request that uses request object',
3131
data: {
3232
method: 'GET',
3333
status_code: 200,
34-
url: 'http://localhost:7654/foo',
34+
url: 'http://sentry-test.io/foo',
3535
},
3636
});
3737
});

dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/fetch/post/subject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
fetch('http://localhost:7654/foo', {
1+
fetch('http://sentry-test.io/foo', {
22
method: 'POST',
33
body: '{"my":"body"}',
44
headers: {

dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/fetch/post/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ sentryTest('captures Breadcrumb for POST request', async ({ getLocalTestUrl, pag
3131
data: {
3232
method: 'POST',
3333
status_code: 200,
34-
url: 'http://localhost:7654/foo',
34+
url: 'http://sentry-test.io/foo',
3535
},
3636
});
3737
});

dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/xhr/get/subject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const xhr = new XMLHttpRequest();
22

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

66
xhr.addEventListener('readystatechange', function () {

dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/xhr/get/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ sentryTest('captures Breadcrumb for basic GET request', async ({ getLocalTestUrl
3232
data: {
3333
method: 'GET',
3434
status_code: 200,
35-
url: 'http://localhost:7654/foo',
35+
url: 'http://sentry-test.io/foo',
3636
},
3737
});
3838
});

dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/xhr/post/subject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const xhr = new XMLHttpRequest();
22

3-
xhr.open('POST', 'http://localhost:7654/foo');
3+
xhr.open('POST', 'http://sentry-test.io/foo');
44
xhr.setRequestHeader('Accept', 'application/json');
55
xhr.setRequestHeader('Content-Type', 'application/json');
66
xhr.send('{"my":"body"}');

dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/xhr/post/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ sentryTest('captures Breadcrumb for POST request', async ({ getLocalTestUrl, pag
3131
data: {
3232
method: 'POST',
3333
status_code: 200,
34-
url: 'http://localhost:7654/foo',
34+
url: 'http://sentry-test.io/foo',
3535
},
3636
});
3737
});

dev-packages/browser-integration-tests/suites/integrations/httpclient/axios/subject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import axios from 'axios';
22

33
axios
4-
.get('http://localhost:7654/foo', {
4+
.get('http://sentry-test.io/foo', {
55
headers: { Accept: 'application/json', 'Content-Type': 'application/json', Cache: 'no-cache' },
66
})
77
.then(response => {

dev-packages/browser-integration-tests/suites/integrations/httpclient/axios/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ sentryTest(
4444
],
4545
},
4646
request: {
47-
url: 'http://localhost:7654/foo',
47+
url: 'http://sentry-test.io/foo',
4848
method: 'GET',
4949
headers: {
5050
accept: 'application/json',

dev-packages/browser-integration-tests/suites/integrations/httpclient/fetch/simple/subject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
fetch('http://localhost:7654/foo', {
1+
fetch('http://sentry-test.io/foo', {
22
method: 'GET',
33
credentials: 'include',
44
headers: {

dev-packages/browser-integration-tests/suites/integrations/httpclient/fetch/simple/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ sentryTest(
4646
],
4747
},
4848
request: {
49-
url: 'http://localhost:7654/foo',
49+
url: 'http://sentry-test.io/foo',
5050
method: 'GET',
5151
headers: {
5252
accept: 'application/json',

dev-packages/browser-integration-tests/suites/integrations/httpclient/fetch/withAbortController/subject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const startFetch = e => {
1010
forceTransaction: true,
1111
},
1212
async () => {
13-
await fetch('http://localhost:7654/foo', { signal })
13+
await fetch('http://sentry-test.io/foo', { signal })
1414
.then(response => response.json())
1515
.then(data => {
1616
console.log('Fetch succeeded:', data);

dev-packages/browser-integration-tests/suites/integrations/httpclient/fetch/withRequest/subject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const request = new Request('http://localhost:7654/foo', {
1+
const request = new Request('http://sentry-test.io/foo', {
22
method: 'POST',
33
credentials: 'include',
44
headers: {

dev-packages/browser-integration-tests/suites/integrations/httpclient/fetch/withRequest/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ sentryTest('works with a Request passed in', async ({ getLocalTestPath, page })
4242
],
4343
},
4444
request: {
45-
url: 'http://localhost:7654/foo',
45+
url: 'http://sentry-test.io/foo',
4646
method: 'POST',
4747
headers: {
4848
accept: 'application/json',

dev-packages/browser-integration-tests/suites/integrations/httpclient/fetch/withRequestAndBodyAndOptions/subject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const request = new Request('http://localhost:7654/foo', {
1+
const request = new Request('http://sentry-test.io/foo', {
22
method: 'POST',
33
credentials: 'include',
44
headers: {

dev-packages/browser-integration-tests/suites/integrations/httpclient/fetch/withRequestAndBodyAndOptions/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ sentryTest(
4444
],
4545
},
4646
request: {
47-
url: 'http://localhost:7654/foo',
47+
url: 'http://sentry-test.io/foo',
4848
method: 'POST',
4949
headers: {
5050
accept: 'application/json',

dev-packages/browser-integration-tests/suites/integrations/httpclient/fetch/withRequestAndOptions/subject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const request = new Request('http://localhost:7654/foo', {
1+
const request = new Request('http://sentry-test.io/foo', {
22
method: 'POST',
33
credentials: 'include',
44
headers: {

dev-packages/browser-integration-tests/suites/integrations/httpclient/fetch/withRequestAndOptions/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ sentryTest('works with a Request (without body) & options passed in', async ({ g
4242
],
4343
},
4444
request: {
45-
url: 'http://localhost:7654/foo',
45+
url: 'http://sentry-test.io/foo',
4646
method: 'POST',
4747
headers: {
4848
accept: 'application/json',

dev-packages/browser-integration-tests/suites/integrations/httpclient/httpClientIntegration/subject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const xhr = new XMLHttpRequest();
22

3-
xhr.open('GET', 'http://localhost:7654/foo', true);
3+
xhr.open('GET', 'http://sentry-test.io/foo', true);
44
xhr.withCredentials = true;
55
xhr.setRequestHeader('Accept', 'application/json');
66
xhr.setRequestHeader('Content-Type', 'application/json');

dev-packages/browser-integration-tests/suites/integrations/httpclient/httpClientIntegration/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ sentryTest('works with httpClientIntegration', async ({ getLocalTestPath, page }
4242
],
4343
},
4444
request: {
45-
url: 'http://localhost:7654/foo',
45+
url: 'http://sentry-test.io/foo',
4646
method: 'GET',
4747
headers: {
4848
accept: 'application/json',

dev-packages/browser-integration-tests/suites/integrations/httpclient/xhr/subject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const xhr = new XMLHttpRequest();
22

3-
xhr.open('GET', 'http://localhost:7654/foo', true);
3+
xhr.open('GET', 'http://sentry-test.io/foo', true);
44
xhr.withCredentials = true;
55
xhr.setRequestHeader('Accept', 'application/json');
66
xhr.setRequestHeader('Content-Type', 'application/json');

dev-packages/browser-integration-tests/suites/integrations/httpclient/xhr/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ sentryTest(
4444
],
4545
},
4646
request: {
47-
url: 'http://localhost:7654/foo',
47+
url: 'http://sentry-test.io/foo',
4848
method: 'GET',
4949
headers: {
5050
accept: 'application/json',

dev-packages/browser-integration-tests/suites/public-api/init/built-pkg/test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import { expect } from '@playwright/test';
66
import { sentryTest } from '../../../../utils/fixtures';
77

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

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

16-
const subjectBundle = fs.readFileSync(path.join(__dirname, 'dist', 'subject.bundle.js'), 'utf-8');
16+
const subjectBundle = fs.readFileSync(path.join(tmpDir, 'subject.bundle.js'), 'utf-8');
1717
expect(subjectBundle.length).toBeGreaterThan(0);
1818
expect(subjectBundle).not.toContain('tslib_1__default');
1919
});

dev-packages/browser-integration-tests/suites/replay/captureReplay/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalT
3434
timestamp: expect.any(Number),
3535
error_ids: [],
3636
trace_ids: [],
37-
urls: [expect.stringContaining('/dist/index.html')],
37+
urls: [expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/)],
3838
replay_id: expect.stringMatching(/\w{32}/),
3939
replay_start_timestamp: expect.any(Number),
4040
segment_id: 0,
@@ -57,7 +57,7 @@ sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalT
5757
name: 'sentry.javascript.browser',
5858
},
5959
request: {
60-
url: expect.stringContaining('/dist/index.html'),
60+
url: expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/),
6161
headers: {
6262
'User-Agent': expect.stringContaining(''),
6363
},
@@ -94,7 +94,7 @@ sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalT
9494
name: 'sentry.javascript.browser',
9595
},
9696
request: {
97-
url: expect.stringContaining('/dist/index.html'),
97+
url: expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/),
9898
headers: {
9999
'User-Agent': expect.stringContaining(''),
100100
},

dev-packages/browser-integration-tests/suites/replay/captureReplayFromReplayPackage/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ sentryTest('should capture replays (@sentry-internal/replay export)', async ({ g
3434
timestamp: expect.any(Number),
3535
error_ids: [],
3636
trace_ids: [],
37-
urls: [expect.stringContaining('/dist/index.html')],
37+
urls: [expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/)],
3838
replay_id: expect.stringMatching(/\w{32}/),
3939
replay_start_timestamp: expect.any(Number),
4040
segment_id: 0,
@@ -57,7 +57,7 @@ sentryTest('should capture replays (@sentry-internal/replay export)', async ({ g
5757
name: 'sentry.javascript.browser',
5858
},
5959
request: {
60-
url: expect.stringContaining('/dist/index.html'),
60+
url: expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/),
6161
headers: {
6262
'User-Agent': expect.stringContaining(''),
6363
},
@@ -94,7 +94,7 @@ sentryTest('should capture replays (@sentry-internal/replay export)', async ({ g
9494
name: 'sentry.javascript.browser',
9595
},
9696
request: {
97-
url: expect.stringContaining('/dist/index.html'),
97+
url: expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/),
9898
headers: {
9999
'User-Agent': expect.stringContaining(''),
100100
},

dev-packages/browser-integration-tests/suites/replay/extendNetworkBreadcrumbs/fetch/captureRequestBody/init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ window.Replay = Sentry.replayIntegration({
66
flushMaxDelay: 200,
77
minReplayDuration: 0,
88

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

0 commit comments

Comments
 (0)