Skip to content

Commit

Permalink
chore(dev): Update jest and friends (#4897)
Browse files Browse the repository at this point in the history
This updates `jest`, `ts-jest`, and `jest-environment-node` to the latest versions, in order to facilitate code transformations during `ts-jest`'s on-the-fly compilation that will become necessary once we move to ES6. (More detail on this to come in the PR which actually introduces said transformation, but TL;DR the way we use and extend `global` is fine if it's a `var` (which it is in ES5 Land) but less fine if it's a `const` (which it becomes under ES6), and we need to fix that for tests to run.)

It also updates `jsdom`. Together these updates meant that a larger number of packages needed to be downgraded in order for tests to run in node 8 and 10. This therefore also reworks the test script a bit to account for those changes. Finally, this removes the test environment from our main jest config, as its value has become the default in latest version of jest.
  • Loading branch information
lobsterkatie authored and Lms24 committed Apr 26, 2022
1 parent c6f5cc0 commit eaaed30
Show file tree
Hide file tree
Showing 10 changed files with 1,304 additions and 718 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ jobs:
uses: actions/checkout@v2
- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: '16'
- name: Check dependency cache
uses: actions/cache@v2
with:
Expand Down
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module.exports = {
},
coverageDirectory: '<rootDir>/coverage',
moduleFileExtensions: ['js', 'ts', 'tsx'],
testEnvironment: 'node',
testMatch: ['<rootDir>/**/*.test.ts', '<rootDir>/**/*.test.tsx'],
globals: {
'ts-jest': {
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,17 @@
"@strictsoftware/typedoc-plugin-monorepo": "^0.3.1",
"@types/chai": "^4.1.3",
"@types/jest": "^24.0.11",
"@types/jsdom": "^16.2.3",
"@types/mocha": "^5.2.0",
"@types/node": "~10.17.0",
"@types/sinon": "^7.0.11",
"chai": "^4.1.2",
"codecov": "^3.6.5",
"deepmerge": "^4.2.2",
"eslint": "7.32.0",
"jest": "^24.9.0",
"jest": "^27.5.1",
"jest-environment-node": "^27.5.1",
"jsdom": "^19.0.0",
"karma-browserstack-launcher": "^1.5.1",
"karma-firefox-launcher": "^1.1.0",
"lerna": "3.13.4",
Expand All @@ -85,15 +88,14 @@
"rollup-plugin-typescript2": "^0.31.2",
"sinon": "^7.3.2",
"size-limit": "^4.5.5",
"ts-jest": "^24.3.0",
"ts-jest": "^27.1.4",
"ts-node": "^8.10.2",
"tslib": "^2.3.1",
"typedoc": "^0.18.0",
"typescript": "3.8.3"
},
"resolutions": {
"**/agent-base": "5",
"**/jest-environment-node": "24"
"**/agent-base": "5"
},
"version": "0.0.0",
"dependencies": {}
Expand Down
1 change: 0 additions & 1 deletion packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"btoa": "^1.2.1",
"chai": "^4.1.2",
"chokidar": "^3.0.2",
"jsdom": "^15.0.0",
"karma": "^6.3.16",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.2.0",
Expand Down
1 change: 0 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"eslint-plugin-react-hooks": "^4.0.8",
"history-4": "npm:history@4.6.0",
"history-5": "npm:history@4.9.0",
"jsdom": "^16.2.2",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-router-3": "npm:react-router@3.2.0",
Expand Down
4 changes: 1 addition & 3 deletions packages/tracing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
},
"devDependencies": {
"@sentry/browser": "7.0.0-alpha.0",
"@types/express": "^4.17.1",
"@types/jsdom": "^16.2.3",
"jsdom": "^16.2.2"
"@types/express": "^4.17.1"
},
"scripts": {
"build": "run-p build:cjs build:esm build:types build:bundle && ts-node ../../scripts/prepack.ts --bundles #necessary for integration tests",
Expand Down
3 changes: 1 addition & 2 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"tslib": "^1.9.3"
},
"devDependencies": {
"chai": "^4.1.2",
"jsdom": "^16.2.2"
"chai": "^4.1.2"
},
"scripts": {
"build": "run-p build:cjs build:esm build:types",
Expand Down
3 changes: 0 additions & 3 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
"peerDependencies": {
"vue": "2.x || 3.x"
},
"devDependencies": {
"jsdom": "^16.2.2"
},
"scripts": {
"build": "run-p build:cjs build:esm build:types",
"build:bundle": "rollup --config",
Expand Down
69 changes: 48 additions & 21 deletions scripts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,55 @@ function run(cmd: string, cwd: string = '') {

const nodeMajorVersion = parseInt(process.version.split('.')[0].replace('v', ''), 10);

if (nodeMajorVersion <= 8) {
// install legacy versions of packages whose current versions don't support node 8
// Ember tests require dependency changes for each set of tests, making them quite slow. To compensate for this, in CI
// we run them in a separate, parallel job.
let ignorePackages = ['@sentry/ember'];

// install legacy versions of third-party packages whose current versions don't support node 8 or 10, and skip testing
// our own packages which don't support node 8 for various syntax or dependency reasons
if (nodeMajorVersion <= 10) {
let legacyDependencies;

if (nodeMajorVersion === 8) {
legacyDependencies = [
'jsdom@15.x',
'jest@25.x',
'jest-environment-jsdom@25.x',
'jest-environment-node@25.x',
'ts-jest@25.x',
];

ignorePackages = [
...ignorePackages,
'@sentry-internal/eslint-plugin-sdk',
'@sentry/react',
'@sentry/wasm',
'@sentry/gatsby',
'@sentry/serverless',
'@sentry/nextjs',
];

// This is a hack, to deal the fact that the browser-based tests fail under Node 8, because of a conflict buried
// somewhere in the interaction between our current overall set of dependencies and the older versions of a small
// subset we're about to install below. Since they're browser-based, these tests are never going to be running in a
// node 8 environment in any case, so it's fine to skip them here. (In the long run, we should only run such tests
// against a single version of node, but in the short run, this at least allows us to not be blocked by the
// failures.)
run('rm -rf packages/tracing/test/browser');
}
// Node 10
else {
legacyDependencies = ['jsdom@16.x'];
}

const legacyDepStr = legacyDependencies.join(' ');

// ignoring engines and scripts lets us get away with having incompatible things installed for packages we're not testing
run('yarn add --dev --ignore-engines --ignore-scripts jsdom@15.x', 'packages/tracing');
run('yarn add --dev --ignore-engines --ignore-scripts jsdom@15.x', 'packages/utils');

// ember tests happen separately, and the rest fail on node 8 for various syntax or dependency reasons
const ignore = [
'@sentry/ember',
'@sentry-internal/eslint-plugin-sdk',
'@sentry/react',
'@sentry/wasm',
'@sentry/gatsby',
'@sentry/serverless',
'@sentry/nextjs',
]
.map(dep => `--ignore="${dep}"`)
.join(' ');

run(`yarn test ${ignore}`);
} else {
run('yarn test --ignore="@sentry/ember"');
run(`yarn add --dev --ignore-engines --ignore-scripts --ignore-workspace-root-check ${legacyDepStr}`);
}

const ignoreFlags = ignorePackages.map(dep => `--ignore="${dep}"`).join(' ');

run(`yarn test ${ignoreFlags}`);

process.exit(0);
Loading

0 comments on commit eaaed30

Please sign in to comment.