Skip to content

Commit 34de27d

Browse files
committed
feat(test): Run Playwright tests using bundles.
1 parent ebba343 commit 34de27d

File tree

4 files changed

+72
-9
lines changed

4 files changed

+72
-9
lines changed

.github/workflows/build.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,18 @@ jobs:
276276
${{ github.workspace }}/packages/serverless/dist-awslambda-layer/*.zip
277277
278278
job_browser_playwright_tests:
279-
name: Browser Playwright Tests
279+
name: Browser Playwright Tests (Bundle ${{ matrix.bundle }})
280280
needs: job_build
281281
runs-on: ubuntu-latest
282+
strategy:
283+
matrix:
284+
bundle:
285+
- esm
286+
- dist
287+
- bundle
288+
- bundle_min
289+
- bundle_es6
290+
- bundle_es6_min
282291
steps:
283292
- name: Check out current commit (${{ github.sha }})
284293
uses: actions/checkout@v2
@@ -297,6 +306,8 @@ jobs:
297306
path: ${{ env.CACHED_BUILD_PATHS }}
298307
key: ${{ env.BUILD_CACHE_KEY }}
299308
- name: Run Playwright tests
309+
env:
310+
PW_BUNDLE: ${{ matrix.bundle }}
300311
run: |
301312
cd packages/integration-tests
302313
yarn run playwright install-deps webkit

packages/integration-tests/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@
1313
"lint": "run-s lint:prettier lint:eslint",
1414
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
1515
"lint:prettier": "prettier --check \"{suites,utils}/**/*.ts\"",
16-
"test:ci": "playwright test ./suites --browser='all' --reporter='line'",
1716
"type-check": "tsc",
1817
"pretest": "yarn clean && yarn type-check",
19-
"test": "playwright test ./suites"
18+
"test": "playwright test ./suites",
19+
"test:bundle": "PW_BUNDLE=bundle yarn test",
20+
"test:bundle:min": "PW_BUNDLE=bundle_min yarn test",
21+
"test:bundle:es6": "PW_BUNDLE=bundle_es6 yarn test",
22+
"test:bundle:es6:min": "PW_BUNDLE=bundle_es6_min yarn test",
23+
"test:dist": "PW_BUNDLE=dist yarn test",
24+
"test:esm": "PW_BUNDLE=esm yarn test",
25+
"test:ci": "playwright test ./suites --browser='all' --reporter='line'"
2026
},
2127
"dependencies": {
2228
"@babel/preset-typescript": "^7.16.7",

packages/integration-tests/utils/generatePage.ts

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
import { Package } from '@sentry/types';
23
import { existsSync, mkdirSync, promises } from 'fs';
34
import HtmlWebpackPlugin from 'html-webpack-plugin';
@@ -8,6 +9,29 @@ import webpackConfig from '../webpack.config';
89

910
const PACKAGE_PATH = '../../packages';
1011

12+
const bundleKey = process.env.PW_BUNDLE || '';
13+
const useCompiledModule = (bundleKey && bundleKey === 'esm') || bundleKey === 'dist';
14+
const useBundle = bundleKey && !useCompiledModule;
15+
16+
const TEST_PATHS: Record<string, Record<string, string>> = {
17+
browser: {
18+
dist: 'dist/index.js',
19+
esm: 'esm/index.js',
20+
bundle: 'build/bundle.js',
21+
bundle_min: 'build/bundle.min.js',
22+
bundle_es6: 'build/bundle.es6.js',
23+
bundle_es6_min: 'build/bundle.es6.min.js',
24+
},
25+
tracing: {
26+
dist: 'dist/index.js',
27+
esm: 'esm/index.js',
28+
bundle: 'build/bundle.tracing.js',
29+
bundle_min: 'build/bundle.tracing.min.js',
30+
bundle_es6: 'build/bundle.tracing.js',
31+
bundle_es6_min: 'build/bundle.tracing.min.js',
32+
},
33+
};
34+
1135
/**
1236
* Generate webpack aliases based on packages in monorepo
1337
* Example of an alias: '@sentry/serverless': 'path/to/sentry-javascript/packages/serverless',
@@ -19,11 +43,26 @@ async function generateSentryAlias(): Promise<Record<string, string>> {
1943

2044
return Object.fromEntries(
2145
await Promise.all(
22-
dirents.map(async d => {
46+
dirents.map(async packageName => {
2347
const packageJSON: Package = JSON.parse(
24-
(await promises.readFile(path.resolve(PACKAGE_PATH, d, 'package.json'), { encoding: 'utf-8' })).toString(),
48+
(
49+
await promises.readFile(path.resolve(PACKAGE_PATH, packageName, 'package.json'), { encoding: 'utf-8' })
50+
).toString(),
2551
);
26-
return [packageJSON['name'], path.resolve(PACKAGE_PATH, d)];
52+
53+
const packagePath = path.resolve(PACKAGE_PATH, packageName);
54+
55+
if (useCompiledModule && TEST_PATHS[packageName]) {
56+
const bundlePath = path.resolve(packagePath, TEST_PATHS[packageName][bundleKey]);
57+
58+
if (!existsSync(bundlePath)) {
59+
console.warn(`${bundlePath} is not found. Try building the package before running tests.`);
60+
}
61+
62+
return [packageJSON['name'], bundlePath];
63+
}
64+
65+
return [packageJSON['name'], packagePath];
2766
}),
2867
),
2968
);
@@ -44,6 +83,14 @@ export async function generatePage(
4483
mkdirSync(localPath, { recursive: true });
4584
}
4685

86+
const bundlesToInject = useBundle
87+
? ['browser', 'tracing'].map(sentryPackage =>
88+
path.resolve(PACKAGE_PATH, sentryPackage, TEST_PATHS[sentryPackage][bundleKey]),
89+
)
90+
: [];
91+
92+
const initializationEntry = bundlesToInject.concat(initializationPath);
93+
4794
if (!existsSync(bundlePath)) {
4895
await new Promise<void>((resolve, reject) => {
4996
const compiler = webpack(
@@ -52,7 +99,7 @@ export async function generatePage(
5299
alias,
53100
},
54101
entry: {
55-
initialization: initializationPath,
102+
initialization: initializationEntry,
56103
subject: subjectPath,
57104
},
58105
output: {
@@ -65,7 +112,6 @@ export async function generatePage(
65112
template: templatePath,
66113
initialization: 'initialization.bundle.js',
67114
subject: `subject.bundle.js`,
68-
inject: false,
69115
}),
70116
],
71117
}),

packages/integration-tests/webpack.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Configuration } from 'webpack';
22

3-
const config = function(userConfig: Record<string, unknown>): Configuration {
3+
const config = function (userConfig: Record<string, unknown>): Configuration {
44
return {
55
...userConfig,
66
mode: 'none',

0 commit comments

Comments
 (0)