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

Create-react-app test debug not stopping at breakpoint #5846

Open
tusharchutani opened this issue Nov 17, 2018 · 9 comments

Comments

@tusharchutani
Copy link

commented Nov 17, 2018

I am really not sure what I am doing wrong here. I am trying to write unit tests and am using Enzyme and Jest (obviously). Here is what my package.json looks like

{
  "name": "balena-io-test",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
....
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "test:debug": "react-scripts --inspect-brk test --runInBand",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "enzyme": "^3.7.0",
    "enzyme-adapter-react-16": "^1.7.0",
    "jest": "^23.6.0",
    "jest-mock": "^23.2.0",
    "react-scripts": "^2.1.1",
    "redux-mock-store": "^1.5.3"
  }
}

Now test are running just fine with npm test and I am trying to debug with npm run test:debug.

Initially the react-script breaks at the first line which is what I would be expect but after that jest just runs without stopping at any debugger break points. I also cannot see any of the .test files in chrome. I am not sure if it is my environment which is to blame or something to do with create-react-app.

Here is a test I am trying to debug

describe('<LightingDevices>', ()=> {
  let wrapper;
  beforeAll(()=>{
    debugger;  <------ should stop here
    const updateDevice = jest.fn();
    const setUpAllLights = jest.fn();
    wrapper = shallow(<LightingDevices updateDevice={updateDevice} setUpAllLights={setUpAllLights}/>);

  });
....
@miraage

This comment has been minimized.

Copy link
Contributor

commented Nov 19, 2018

Npm runner "test:debug": "react-scripts --inspect-brk test --runInBand" does not work as you expected. As far as I know the CRA codebase, all flags/arguments before the actual command are ignored. Plus, --runInBand isn't actually passed to the jest runner, but to the react-scripts binary.

I, personally, would like to have an option to debug tests, despite the fact that I need it in very rare cases.

@heyimalex

This comment has been minimized.

Copy link
Collaborator

commented Nov 20, 2018

@rsuk

This comment has been minimized.

Copy link

commented Nov 20, 2018

@heyimalex That is what is being described as not working in the previous comments I think, i.e.

react-scripts --inspect-brk test --runInBand

then attach chrome via chrome:inspect (or about:inspect). The attach works, but no breakpoints are hit and debugger; statements don't break.

@heyimalex

This comment has been minimized.

Copy link
Collaborator

commented Nov 20, 2018

Yeah, I was agreeing with the issue creator; it sounds like they're doing everything right. Also I can replicate this. With a stock cra install the breakpoint works about half of the time. Really strange.

@bmihelac

This comment has been minimized.

Copy link

commented Dec 17, 2018

Adding --no-cache parameter seems to help (at least for me).

    "test:debug": "react-scripts  --inspect-brk test --no-cache --verbose=false --runInBand",

This parameter is also used in Debugging Tests in Visual Studio Code config, so I guess that can have something with jest cache.

@stale

This comment has been minimized.

Copy link

commented Jan 18, 2019

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Jan 18, 2019

@stale

This comment has been minimized.

Copy link

commented Jan 26, 2019

This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue.

@stale stale bot closed this Jan 26, 2019

@lock lock bot locked and limited conversation to collaborators Jan 31, 2019

@gaearon gaearon reopened this Feb 15, 2019

@stale stale bot removed the stale label Feb 15, 2019

@gaearon

This comment has been minimized.

Copy link
Member

commented Feb 15, 2019

This is still an issue.

@gaearon gaearon added the issue: bug label Feb 15, 2019

@gaearon gaearon added this to the 2.1.x milestone Feb 15, 2019

@gaearon

This comment has been minimized.

Copy link
Member

commented Feb 15, 2019

--no-cache helps although this fix makes no sense to me.

@iansu iansu modified the milestones: 2.1.x, 3.x Mar 10, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
7 participants
You can’t perform that action at this time.