Skip to content

Commit 4800458

Browse files
authored
test: Refactor playwright bundle generation (#8029)
1 parent b9fb55f commit 4800458

File tree

12 files changed

+152
-100
lines changed

12 files changed

+152
-100
lines changed

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
*.md
22
.nxcache
3-
packages/browser-integration-tests/fixtures

packages/browser-integration-tests/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
'loader-suites/**/subject.js',
1212
'scripts/**',
1313
'fixtures/**',
14+
'tmp/**',
1415
],
1516
parserOptions: {
1617
sourceType: 'module',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
test-results
2+
tmp
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tmp
2+
fixtures

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fs from 'fs';
33
import path from 'path';
44

55
import { sentryTest, TEST_HOST } from '../../../../utils/fixtures';
6-
import { LOADER_CONFIGS } from '../../../../utils/generatePage';
6+
import { LOADER_CONFIGS } from '../../../../utils/generatePlugin';
77
import { envelopeRequestParser, waitForErrorRequest } from '../../../../utils/helpers';
88

99
const bundle = process.env.PW_BUNDLE || '';

packages/browser-integration-tests/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"private": true,
1010
"scripts": {
11-
"clean": "rimraf -g suites/**/dist loader-suites/**/dist",
11+
"clean": "rimraf -g suites/**/dist loader-suites/**/dist tmp",
1212
"install-browsers": "playwright install --with-deps",
1313
"lint": "run-s lint:prettier lint:eslint",
1414
"lint:eslint": "eslint . --format stylish",
@@ -58,6 +58,7 @@
5858
},
5959
"devDependencies": {
6060
"@types/glob": "8.0.0",
61+
"@types/node": "^14.6.4",
6162
"glob": "8.0.3"
6263
},
6364
"volta": {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ const config: PlaywrightTestConfig = {
77
// Use 3 workers on CI, else use defaults (based on available CPU cores)
88
// Note that 3 is a random number selected to work well with our CI setup
99
workers: process.env.CI ? 3 : undefined,
10+
11+
globalSetup: require.resolve('./playwright.setup.ts'),
1012
};
13+
1114
export default config;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import setupStaticAssets from './utils/staticAssets';
2+
3+
export default function globalSetup(): Promise<void> {
4+
return setupStaticAssets();
5+
}

packages/browser-integration-tests/utils/fixtures.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { test as base } from '@playwright/test';
33
import fs from 'fs';
44
import path from 'path';
55

6-
import { generateLoader, generatePage } from './generatePage';
6+
import { generatePage } from './generatePage';
77

88
export const TEST_HOST = 'http://sentry-test.io';
99

@@ -53,7 +53,6 @@ const sentryTest = base.extend<TestFixtures>({
5353
const pagePath = `${TEST_HOST}/index.html`;
5454

5555
await build(testDir);
56-
generateLoader(testDir);
5756

5857
// Serve all assets under
5958
if (!skipRouteHandler) {

packages/browser-integration-tests/utils/generatePage.ts

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,10 @@
1-
import { existsSync, mkdirSync, readFileSync, symlinkSync, unlinkSync, writeFileSync } from 'fs';
1+
import { existsSync, mkdirSync } from 'fs';
22
import HtmlWebpackPlugin from 'html-webpack-plugin';
3-
import path from 'path';
43
import webpack from 'webpack';
54

65
import webpackConfig from '../webpack.config';
7-
import { TEST_HOST } from './fixtures';
86
import SentryScenarioGenerationPlugin from './generatePlugin';
97

10-
const LOADER_TEMPLATE = readFileSync(path.join(__dirname, '../fixtures/loader.js'), 'utf-8');
11-
12-
export const LOADER_CONFIGS: Record<string, { bundle: string; options: Record<string, unknown>; lazy: boolean }> = {
13-
loader_base: {
14-
bundle: 'browser/build/bundles/bundle.es5.min.js',
15-
options: {},
16-
lazy: true,
17-
},
18-
loader_eager: {
19-
bundle: 'browser/build/bundles/bundle.es5.min.js',
20-
options: {},
21-
lazy: false,
22-
},
23-
loader_debug: {
24-
bundle: 'browser/build/bundles/bundle.es5.debug.min.js',
25-
options: { debug: true },
26-
lazy: true,
27-
},
28-
loader_tracing: {
29-
bundle: 'browser/build/bundles/bundle.tracing.es5.min.js',
30-
options: { tracesSampleRate: 1 },
31-
lazy: false,
32-
},
33-
loader_replay: {
34-
bundle: 'browser/build/bundles/bundle.replay.min.js',
35-
options: { replaysSessionSampleRate: 1, replaysOnErrorSampleRate: 1 },
36-
lazy: false,
37-
},
38-
loader_tracing_replay: {
39-
bundle: 'browser/build/bundles/bundle.tracing.replay.debug.min.js',
40-
options: { tracesSampleRate: 1, replaysSessionSampleRate: 1, replaysOnErrorSampleRate: 1, debug: true },
41-
lazy: false,
42-
},
43-
};
44-
45-
const bundleKey = process.env.PW_BUNDLE || '';
46-
47-
export function generateLoader(outPath: string): void {
48-
const localPath = `${outPath}/dist`;
49-
50-
if (!existsSync(localPath)) {
51-
return;
52-
}
53-
54-
// Generate loader files
55-
const loaderConfig = LOADER_CONFIGS[bundleKey];
56-
57-
if (!loaderConfig) {
58-
throw new Error(`Unknown loader bundle key: ${bundleKey}`);
59-
}
60-
61-
const localCdnBundlePath = path.join(localPath, 'cdn.bundle.js');
62-
63-
try {
64-
unlinkSync(localCdnBundlePath);
65-
} catch {
66-
// ignore if this didn't exist
67-
}
68-
69-
const cdnSourcePath = path.resolve(__dirname, `../../${loaderConfig.bundle}`);
70-
symlinkSync(cdnSourcePath, localCdnBundlePath);
71-
72-
const loaderPath = path.join(localPath, 'loader.js');
73-
const loaderContent = LOADER_TEMPLATE.replace('__LOADER_BUNDLE__', `'${TEST_HOST}/cdn.bundle.js'`)
74-
.replace(
75-
'__LOADER_OPTIONS__',
76-
JSON.stringify({
77-
dsn: 'https://[email protected]/1337',
78-
...loaderConfig.options,
79-
}),
80-
)
81-
.replace('__LOADER_LAZY__', loaderConfig.lazy ? 'true' : 'false');
82-
83-
writeFileSync(loaderPath, loaderContent, 'utf-8');
84-
}
85-
868
export async function generatePage(
879
initPath: string,
8810
subjectPath: string,
@@ -110,7 +32,7 @@ export async function generatePage(
11032
filename: '[name].bundle.js',
11133
},
11234
plugins: [
113-
new SentryScenarioGenerationPlugin(),
35+
new SentryScenarioGenerationPlugin(localPath),
11436
new HtmlWebpackPlugin({
11537
filename: outPageName,
11638
template: templatePath,

0 commit comments

Comments
 (0)