Skip to content

Commit 6cc1e51

Browse files
authored
test(node): Handle some jest & axios issues (#10736)
Sometimes I ran into issues when running node-integration tests locally, something along the lines of: ``` Test suite failed to run Jest encountered an unexpected token Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax. Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration. By default "node_modules" folder is ignored by transformers. Here's what you can do: • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it. • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config. • If you need a custom transformation specify a "transform" option in your config. • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option. You'll find more details and examples of these config options in the docs: https://jestjs.io/docs/configuration For information about custom transformations, see: https://jestjs.io/docs/code-transformation Details: /sentry-javascript/node_modules/axios/index.js:1 ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import axios from './lib/axios.js'; ``` After some investigation, it seems adding a custom module mapping for axios in jest config fixes this... not sure why this happened sometimes and other times not. While at it, I also bumped axios to latest, and ensured we clean watchman on `yarn clean` (that also cluttered logs sometimes).
1 parent c002d8f commit 6cc1e51

File tree

6 files changed

+28
-37
lines changed

6 files changed

+28
-37
lines changed

dev-packages/browser-integration-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@sentry-internal/rrweb": "2.11.0",
5050
"@sentry/browser": "7.100.0",
5151
"@sentry/tracing": "7.100.0",
52-
"axios": "1.6.0",
52+
"axios": "1.6.7",
5353
"babel-loader": "^8.2.2",
5454
"html-webpack-plugin": "^5.5.0",
5555
"pako": "^2.1.0",

dev-packages/node-integration-tests/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"build:dev": "yarn build",
1515
"build:transpile": "rollup -c rollup.npm.config.mjs",
1616
"build:types": "tsc -p tsconfig.types.json",
17-
"clean": "rimraf -g **/node_modules && run-p clean:docker",
18-
"clean:docker": "node scripts/clean.js",
17+
"clean": "rimraf -g **/node_modules && run-p clean:script",
18+
"clean:script": "node scripts/clean.js",
1919
"prisma:init": "(cd suites/tracing/prisma-orm && ts-node ./setup.ts)",
2020
"prisma:init:new": "(cd suites/tracing-new/prisma-orm && ts-node ./setup.ts)",
2121
"lint": "eslint . --format stylish",
@@ -36,7 +36,7 @@
3636
"@types/mysql": "^2.15.21",
3737
"@types/pg": "^8.6.5",
3838
"apollo-server": "^3.11.1",
39-
"axios": "^0.27.2",
39+
"axios": "^1.6.7",
4040
"cors": "^2.8.5",
4141
"cron": "^3.1.6",
4242
"express": "^4.17.3",

dev-packages/node-integration-tests/scripts/clean.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,12 @@ for (const path of paths) {
1717
//
1818
}
1919
}
20+
21+
// eslint-disable-next-line no-console
22+
console.log('Cleaning up watchman...');
23+
24+
try {
25+
execSync('watchman watch-del "./../.."; watchman watch-project "./../.."', { stdio: 'inherit' });
26+
} catch (_) {
27+
//
28+
}

dev-packages/overhead-metrics/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"dependencies": {
2020
"@octokit/rest": "^19.0.5",
2121
"@types/node": "^18.11.17",
22-
"axios": "^1.2.2",
22+
"axios": "^1.6.7",
2323
"extract-zip": "^2.0.1",
2424
"filesize": "^10.0.6",
2525
"fs-extra": "^11.1.0",

jest/jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ module.exports = {
99
coverageDirectory: '<rootDir>/coverage',
1010
moduleFileExtensions: ['js', 'ts', 'tsx'],
1111
testMatch: ['<rootDir>/**/*.test.ts', '<rootDir>/**/*.test.tsx'],
12+
moduleNameMapper: {
13+
'^axios$': require.resolve('axios'),
14+
},
1215
globals: {
1316
'ts-jest': {
1417
tsconfig: '<rootDir>/tsconfig.test.json',

yarn.lock

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8992,38 +8992,12 @@ aws4@^1.8.0:
89928992
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
89938993
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==
89948994

8995-
8996-
version "1.6.0"
8997-
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.0.tgz#f1e5292f26b2fd5c2e66876adc5b06cdbd7d2102"
8998-
integrity sha512-EZ1DYihju9pwVB+jg67ogm+Tmqc6JmhamRN6I4Zt8DfZu5lbcQGw3ozH9lFejSJgs/ibaef3A9PMXPLeefFGJg==
8995+
[email protected].7, axios@^1.0.0, axios@^1.6.7:
8996+
version "1.6.7"
8997+
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.7.tgz#7b48c2e27c96f9c68a2f8f31e2ab19f59b06b0a7"
8998+
integrity sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==
89998999
dependencies:
9000-
follow-redirects "^1.15.0"
9001-
form-data "^4.0.0"
9002-
proxy-from-env "^1.1.0"
9003-
9004-
axios@^0.27.2:
9005-
version "0.27.2"
9006-
resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972"
9007-
integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==
9008-
dependencies:
9009-
follow-redirects "^1.14.9"
9010-
form-data "^4.0.0"
9011-
9012-
axios@^1.0.0:
9013-
version "1.2.0"
9014-
resolved "https://registry.yarnpkg.com/axios/-/axios-1.2.0.tgz#1cb65bd75162c70e9f8d118a905126c4a201d383"
9015-
integrity sha512-zT7wZyNYu3N5Bu0wuZ6QccIf93Qk1eV8LOewxgjOZFd2DenOs98cJ7+Y6703d0wkaXGY6/nZd4EweJaHz9uzQw==
9016-
dependencies:
9017-
follow-redirects "^1.15.0"
9018-
form-data "^4.0.0"
9019-
proxy-from-env "^1.1.0"
9020-
9021-
axios@^1.2.2:
9022-
version "1.3.4"
9023-
resolved "https://registry.yarnpkg.com/axios/-/axios-1.3.4.tgz#f5760cefd9cfb51fd2481acf88c05f67c4523024"
9024-
integrity sha512-toYm+Bsyl6VC5wSkfkbbNB6ROv7KY93PEBBL6xyDczaIHasAiv4wPqQ/c4RjoQzipxRD2W5g21cOqQulZ7rHwQ==
9025-
dependencies:
9026-
follow-redirects "^1.15.0"
9000+
follow-redirects "^1.15.4"
90279001
form-data "^4.0.0"
90289002
proxy-from-env "^1.1.0"
90299003

@@ -16256,11 +16230,16 @@ [email protected]:
1625616230
resolved "https://registry.yarnpkg.com/fn.name/-/fn.name-1.1.0.tgz#26cad8017967aea8731bc42961d04a3d5988accc"
1625716231
integrity sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==
1625816232

16259-
follow-redirects@^1.0.0, follow-redirects@^1.14.9, follow-redirects@^1.15.0:
16233+
follow-redirects@^1.0.0:
1626016234
version "1.15.2"
1626116235
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
1626216236
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
1626316237

16238+
follow-redirects@^1.15.4:
16239+
version "1.15.5"
16240+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.5.tgz#54d4d6d062c0fa7d9d17feb008461550e3ba8020"
16241+
integrity sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==
16242+
1626416243
for-each@^0.3.3:
1626516244
version "0.3.3"
1626616245
resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.3.tgz#69b447e88a0a5d32c3e7084f3f1710034b21376e"

0 commit comments

Comments
 (0)