Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: matchMedia is not defined #36624

Closed
simPod opened this issue Jul 10, 2021 · 2 comments · Fixed by #37643
Closed

ReferenceError: matchMedia is not defined #36624

simPod opened this issue Jul 10, 2021 · 2 comments · Fixed by #37643
Labels
area/grafana/toolkit needs investigation for unconfirmed bugs. use type/bug for confirmed bugs, even if they "need" more investigating prio/high Must be staffed and worked on either currently, or very soon, ideally in time for the next release. type/bug

Comments

@simPod
Copy link
Contributor

simPod commented Jul 10, 2021

What happened:

Upgraded @grafana/* package from v8.0.2 to anything 8.0.3+.

Got error while running tests:

    ReferenceError: matchMedia is not defined

      1 | import { isDataFrame } from '@grafana/data';
      2 | import { DateTime } from '@grafana/data/datetime/moment_wrapper';
    > 3 | import { BackendSrv, getBackendSrv, getTemplateSrv, setBackendSrv, setTemplateSrv } from '@grafana/runtime';
        | ^
      4 | import { DataSource } from '../src/DataSource';
      5 | import { Format } from '../src/format';
      6 | import { QueryRequest } from '../src/types';

      at setPxRatio (node_modules/@grafana/ui/index.development.js:109545:2)
      at Object.<anonymous> (node_modules/@grafana/ui/index.development.js:109603:1)
      at Object.<anonymous> (node_modules/@grafana/ui/index.js:6:20)
      at Object.<anonymous> (node_modules/@grafana/aws-sdk/dist/index.development.js:13:10)
      at Object.<anonymous> (node_modules/@grafana/aws-sdk/index.js:6:20)
      at Object.<anonymous> (node_modules/@grafana/runtime/node_modules/@grafana/ui/index.development.js:11:14)
      at Object.<anonymous> (node_modules/@grafana/runtime/node_modules/@grafana/ui/index.js:6:20)
      at Object.<anonymous> (node_modules/@grafana/runtime/index.development.js:9:10)
      at Object.<anonymous> (node_modules/@grafana/runtime/index.js:6:20)
      at Object.<anonymous> (spec/DataSource.jest.ts:3:1)

What you expected to happen:

Ok

How to reproduce it (as minimally and precisely as possible):

See this commit simPod/GrafanaJsonDatasource@880cd57, there's also CI

@torkelo torkelo added the needs investigation for unconfirmed bugs. use type/bug for confirmed bugs, even if they "need" more investigating label Jul 11, 2021
@torkelo torkelo added this to Todo in Plugins Platform (DEPRECATED) via automation Jul 11, 2021
@rvdwijngaard
Copy link

+1 having the same issue

rvdwijngaard pushed a commit to innius/grafana-video-panel that referenced this issue Jul 12, 2021
@zoltanbedi
Copy link
Member

Until this is fixed. As a workaround you can create a file inside a config folder called jest-setup so config/jest-setup.ts with this content:

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
    addEventListener: jest.fn(),
    removeEventListener: jest.fn(),
    dispatchEvent: jest.fn(),
  })),
});

That should resolve this issue.

@zoltanbedi zoltanbedi added area/grafana/toolkit prio/high Must be staffed and worked on either currently, or very soon, ideally in time for the next release. type/bug labels Aug 6, 2021
Plugins Platform (DEPRECATED) automation moved this from Todo to Done Aug 10, 2021
fetzerch added a commit to fetzerch/grafana-sunandmoon-datasource that referenced this issue Aug 13, 2021
@grafana/* is pinned to 8.0.2 due to
grafana/grafana#36624

@emotion/css is pinned to ^10.1.0 due to
grafana/grafana#35878
fetzerch added a commit to fetzerch/grafana-sunandmoon-datasource that referenced this issue Aug 14, 2021
@grafana/* is pinned to 8.0.2 due to
grafana/grafana#36624

@emotion/css is pinned to ^10.1.0 due to
grafana/grafana#35878
fetzerch added a commit to fetzerch/grafana-sunandmoon-datasource that referenced this issue Aug 14, 2021
@grafana/* is pinned to 8.0.2 due to
grafana/grafana#36624

@emotion/css is pinned to ^10.1.0 due to
grafana/grafana#35878
lahabana added a commit to kumahq/kuma-grafana-datasource that referenced this issue Aug 20, 2021
Caused by: grafana/grafana#36624

Signed-off-by: Charly Molter <charly.molter@konghq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/grafana/toolkit needs investigation for unconfirmed bugs. use type/bug for confirmed bugs, even if they "need" more investigating prio/high Must be staffed and worked on either currently, or very soon, ideally in time for the next release. type/bug
Development

Successfully merging a pull request may close this issue.

4 participants