Skip to content

Commit

Permalink
fix(wasm): Ensure browser bundle exists before running tests (#4389)
Browse files Browse the repository at this point in the history
The tests in our `wasm` package use the browser bundle, and therefore won't run if the bundle hasn't been built. #4074 added a warning for this situation. This improves that by actually building the missing bundles, ensuring the tests will always run.
  • Loading branch information
lobsterkatie authored Jan 12, 2022
1 parent e52faa4 commit d53ed78
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
"lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
"pack": "npm pack",
"test": "cross-env PORT=1337 jest",
"test": "node test/scripts/ensure-browser-bundle.js && cross-env PORT=1337 jest",
"test:watch": "jest --watch"
},
"volta": {
Expand Down
8 changes: 0 additions & 8 deletions packages/wasm/test/integration.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
/* global page, window */
const fs = require('fs');
const path = require('path');

const HOST = `http://localhost:${process.env.PORT}`;

if (!fs.existsSync(path.resolve(__dirname, '../../browser/build/bundle.js'))) {
throw new Error(
'ERROR: No browser bundle found in `packages/browser/build/`. Please run `yarn build` in the browser package before running wasm tests.',
);
}

describe('Wasm', () => {
it('captured exception should include modified frames and debug_meta attribute', async () => {
await page.goto(HOST);
Expand Down
14 changes: 14 additions & 0 deletions packages/wasm/test/scripts/ensure-browser-bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

function ensureBrowserBundle() {
const browserPackageDir = path.resolve(__dirname, '../../../browser');
if (!fs.existsSync(path.resolve(browserPackageDir, 'build/bundle.js'))) {
// eslint-disable-next-line no-console
console.warn('\nWARNING: Missing browser bundle. Bundle will be created before running wasm integration tests.');
execSync(`pushd ${browserPackageDir} && yarn build:bundle && popd`);
}
}

ensureBrowserBundle();

0 comments on commit d53ed78

Please sign in to comment.