From d70182e2a5250a4a1f7eef99dab82825d58d8bd5 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Wed, 17 Jul 2024 16:13:45 -0400 Subject: [PATCH] test(replay-canvas): Switch to using vitest (#12964) Before: `Time: 2.026 s` After: `Duration 960ms (transform 291ms, setup 0ms, collect 446ms, tests 5ms, environment 283ms, prepare 65ms)` Also: - removes unused `@babel/core` dev dep - removes unused eslintrc logic --- packages/replay-canvas/.eslintrc.js | 14 -------------- packages/replay-canvas/jest.config.js | 6 ------ packages/replay-canvas/package.json | 5 ++--- packages/replay-canvas/test/canvas.test.ts | 10 ++++++++-- packages/replay-canvas/tsconfig.test.json | 4 ++-- packages/replay-canvas/vite.config.ts | 5 +++++ 6 files changed, 17 insertions(+), 27 deletions(-) delete mode 100644 packages/replay-canvas/jest.config.js create mode 100644 packages/replay-canvas/vite.config.ts diff --git a/packages/replay-canvas/.eslintrc.js b/packages/replay-canvas/.eslintrc.js index 216184b75e47..0c83f7d0ff9d 100644 --- a/packages/replay-canvas/.eslintrc.js +++ b/packages/replay-canvas/.eslintrc.js @@ -5,18 +5,4 @@ module.exports = { extends: ['../../.eslintrc.js'], - overrides: [ - { - files: ['src/**/*.ts'], - }, - { - files: ['jest.setup.ts', 'jest.config.ts'], - parserOptions: { - project: ['tsconfig.test.json'], - }, - rules: { - 'no-console': 'off', - }, - }, - ], }; diff --git a/packages/replay-canvas/jest.config.js b/packages/replay-canvas/jest.config.js deleted file mode 100644 index cd02790794a7..000000000000 --- a/packages/replay-canvas/jest.config.js +++ /dev/null @@ -1,6 +0,0 @@ -const baseConfig = require('../../jest/jest.config.js'); - -module.exports = { - ...baseConfig, - testEnvironment: 'jsdom', -}; diff --git a/packages/replay-canvas/package.json b/packages/replay-canvas/package.json index cc0c3d589847..014342ac2482 100644 --- a/packages/replay-canvas/package.json +++ b/packages/replay-canvas/package.json @@ -47,8 +47,8 @@ "clean": "rimraf build sentry-replay-*.tgz", "fix": "eslint . --format stylish --fix", "lint": "eslint . --format stylish", - "test": "jest", - "test:watch": "jest --watch", + "test": "vitest run", + "test:watch": "vitest --watch", "yalc:publish": "yalc publish --push --sig" }, "publishConfig": { @@ -65,7 +65,6 @@ }, "homepage": "https://docs.sentry.io/platforms/javascript/session-replay/", "devDependencies": { - "@babel/core": "^7.17.5", "@sentry-internal/rrweb": "2.25.0" }, "dependencies": { diff --git a/packages/replay-canvas/test/canvas.test.ts b/packages/replay-canvas/test/canvas.test.ts index a7de3b6a28a3..6f75321a5ab5 100644 --- a/packages/replay-canvas/test/canvas.test.ts +++ b/packages/replay-canvas/test/canvas.test.ts @@ -1,10 +1,16 @@ +/** + * @vitest-environment jsdom + */ + +import { beforeEach, expect, it, vi } from 'vitest'; + import { CanvasManager } from '@sentry-internal/rrweb'; import { _replayCanvasIntegration, replayCanvasIntegration } from '../src/canvas'; -jest.mock('@sentry-internal/rrweb'); +vi.mock('@sentry-internal/rrweb'); beforeEach(() => { - jest.clearAllMocks(); + vi.clearAllMocks(); }); it('initializes with default options', () => { diff --git a/packages/replay-canvas/tsconfig.test.json b/packages/replay-canvas/tsconfig.test.json index 3995d3e18e59..f4e8a1624f08 100644 --- a/packages/replay-canvas/tsconfig.test.json +++ b/packages/replay-canvas/tsconfig.test.json @@ -1,11 +1,11 @@ { "extends": "./tsconfig.json", - "include": ["test/**/*.ts", "jest.config.ts", "jest.setup.ts"], + "include": ["test/**/*.ts", "vite.config.ts"], "compilerOptions": { "lib": ["DOM", "ES2018"], - "types": ["node", "jest"], + "types": ["node"], "esModuleInterop": true, "allowJs": true, "noImplicitAny": true, diff --git a/packages/replay-canvas/vite.config.ts b/packages/replay-canvas/vite.config.ts new file mode 100644 index 000000000000..0582a58f479a --- /dev/null +++ b/packages/replay-canvas/vite.config.ts @@ -0,0 +1,5 @@ +import baseConfig from '../../vite/vite.config'; + +export default { + ...baseConfig, +};