From bd55aa8c6df5447cf1aecf8fa9e2e61818b48387 Mon Sep 17 00:00:00 2001 From: rozetko Date: Tue, 20 Dec 2022 19:27:58 +0300 Subject: [PATCH] revert jest config --- .config/jest-setup.js | 17 +++++++++------ .config/jest.config.js | 48 ++++++++++++++++++++++++------------------ 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/.config/jest-setup.js b/.config/jest-setup.js index 0dc7419..276ae17 100644 --- a/.config/jest-setup.js +++ b/.config/jest-setup.js @@ -1,21 +1,24 @@ -/** - * globally import this, avoids needing to import it in each file - * https://stackoverflow.com/a/65871118 +/* + * ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️ + * + * In order to extend the configuration follow the steps in .config/README.md */ + import '@testing-library/jest-dom'; -// https://stackoverflow.com/a/66055672 // https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom -Object.defineProperty(window, 'matchMedia', { +Object.defineProperty(global, 'matchMedia', { writable: true, value: jest.fn().mockImplementation((query) => ({ matches: false, media: query, onchange: null, - addListener: jest.fn(), // Deprecated - removeListener: jest.fn(), // Deprecated + addListener: jest.fn(), // deprecated + removeListener: jest.fn(), // deprecated addEventListener: jest.fn(), removeEventListener: jest.fn(), dispatchEvent: jest.fn(), })), }); + +HTMLCanvasElement.prototype.getContext = () => {}; diff --git a/.config/jest.config.js b/.config/jest.config.js index 1e40057..82a6e3f 100644 --- a/.config/jest.config.js +++ b/.config/jest.config.js @@ -1,25 +1,31 @@ -const esModules = ['react-colorful', 'uuid', 'ol'].join('|'); +/* + * ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️ + * + * In order to extend the configuration follow the steps in .config/README.md + */ module.exports = { - testEnvironment: 'jsdom', - - moduleDirectories: ['node_modules', 'src'], - moduleFileExtensions: ['ts', 'tsx', 'js'], - - transformIgnorePatterns: [`/node_modules/(?!${esModules})`], - - moduleNameMapper: { - 'grafana/app/(.*)': '/src/jest/grafanaMock.ts', - 'jest/matchMedia': '/src/jest/matchMedia.ts', - 'jest/outgoingWebhooksStub': '/src/jest/outgoingWebhooksStub.ts', - '^jest$': '/src/jest', - '^.+\\.(css|scss)$': '/src/jest/styleMock.ts', - '^lodash-es$': 'lodash', - '^.+\\.svg$': '/src/jest/svgTransform.ts', - '^.+\\.png$': '/src/jest/grafanaMock.ts', + testEnvironment: 'jest-environment-jsdom', + testMatch: [ + '/src/**/__tests__/**/*.{js,jsx,ts,tsx}', + '/src/**/*.{spec,test,jest}.{js,jsx,ts,tsx}', + '/src/**/*.{spec,test,jest}.{js,jsx,ts,tsx}', + ], + transform: { + '^.+\\.(t|j)sx?$': [ + '@swc/jest', + { + sourceMaps: true, + jsc: { + parser: { + syntax: 'typescript', + tsx: true, + decorators: false, + dynamicImport: true, + }, + }, + }, + ], }, - - setupFilesAfterEnv: ['/.config/jest.setup.ts'], - - testTimeout: 10000, + setupFilesAfterEnv: ['/jest-setup.js'], };