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

Segmentation Fault when rendering 'react-player/lazy' with Jest & React Testing Library #1391

Open
pjaws opened this issue Jan 31, 2022 · 5 comments

Comments

@pjaws
Copy link

pjaws commented Jan 31, 2022

Be sure to search for your issue before opening a new one.

Current Behavior

Importing ReactPlayer from react-player/lazy causes a segmentation fault when rendered with @testing-library/react inside a Jest test.

Importing from react-player/vimeo does not produce the same issue.

Expected Behavior

:)

Steps to Reproduce

video.js

import PropTypes from 'prop-types';
// switching this to 'react-player/vimeo' will work
import ReactPlayer from 'react-player/lazy';

import { track } from 'utils/analytics';

const Video = ({ title, url, width, height }) => {
  const handleStart = () =>
    track('video_started', {
      video_title: title,
      video_url: url,
    });

  const handlePause = () =>
    track('video_paused', {
      video_title: title,
      video_url: url,
    });

  const handlePlay = () =>
    track('video_played', {
      video_title: title,
      video_url: url,
    });

  const handleProgress = ({ played, playedSeconds }) =>
    track('video_progress', {
      video_title: title,
      video_url: url,
      video_played: played,
      video_played_seconds: playedSeconds,
    });

  const handleEnded = () =>
    track('video_ended', {
      video_title: title,
      video_url: url,
    });

  return (
    <ReactPlayer
      className="react-player"
      url={url}
      config={{ vimeo: { title } }}
      onStart={handleStart}
      onPause={handlePause}
      onPlay={handlePlay}
      onProgress={handleProgress}
      onEnded={handleEnded}
      width={width}
      height={height}
      controls
    />
  );
};

export default Video;

video.spec.js

import { render } from '@testing-library/react';

import Video from 'components/video';

describe('Video', () => {
  it('matches the snapshot', () => {
    const { container } = render(
      <Video
        url="https://player.vimeo.com/video/457872455"
        title="example"
        width={970}
        height={546}
      />
    );

    expect(container).toMatchSnapshot();
  });
});

results in:

 RUNS  src/__tests__/pages/video-example.spec.js
[1]    2860 segmentation fault  node --expose-gc --trace-warnings ./node_modules/.bin/jest video-example

Environment

@seisenreich
Copy link

Same problem here.
As soon as I use "react-player/lazy" instead of "react-player/youtube" or "react-player" jest tests using react-testing-library fail with segmentation fault.

@babipal
Copy link

babipal commented Mar 3, 2022

Same here.

@yashwant-dangi
Copy link

Is anyone able to find the solution to this?

@F3n67u
Copy link

F3n67u commented Oct 8, 2022

Same here.

My solution is to replace react-player/lazy module with react-player in your jest setup file:

// Replace react-player/lazy with react-player
// Fix Segmentation Fault when using 'react-player/lazy' in tests
// Learn more: https://github.com/cookpete/react-player/issues/1391
jest.mock('react-player/lazy', () => {
  return jest.requireActual('react-player');
});

@AgustinJuarezN
Copy link

Having the same issue.
I fixed it for now with @F3n67u solution but I was wondering if it will be fixed officially.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants