Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Issues
  • #2996
Closed
Open
Issue created Aug 23, 2017 by Administrator@rootContributor

test --watch always exits when a promise is unhandled

Created by: jackielii

Is this a bug report?

No.

In case of a complicated flow control, the yarn test simply exists with:

.../node_modules/react-scripts/scripts/test.js:22
  throw err;
  ^
[object Object]

This is not very helpful.

E.g. my test:

  it('should connect dispatch not authenticated', done => {
    mockFetch(null, 401); // mocks global.fetch
    const Component = props => {
      const { callGraphQL } = props;
      const params = { query: '{hello}' };
      const result = callGraphQL(params)
        .then(response => {
          expect(`shouldn't execute catch block`).toBe('not executed');
        })
        .catch(error => {
          expect(error.errors).toHaveLength(1);
        });
      Promise.all([result, resultIgnoreError]).then(done);
      return null;

    const dispatch = jest.fn();
    const ConnectedComponent = connectGraphQL()(Component);
    const wrapper = mount(<ConnectedComponent />, createOption(dispatch));
    expect(wrapper.find(Component)).toHaveLength(1);
  };

In the test above, I thought I caught all the promise rejection, but it still failed and the error yarn test gave me is not very useful.

Now the error is within the catch block. It throw because access error.errors. My fault. But react-script shouldn't exit without useful information.

It should print a helpful message, fail the test instead of exit with code 1 and print [object Object]

Can you also reproduce the problem with npm 4.x?

(Write your answer here.)YES

Which terms did you search for in User Guide?

unhandledPromise

(Write your answer here if relevant.)

Environment

  1. node -v: v7.7.1
  2. npm -v:4.1.2
  3. yarn --version (if you use Yarn):0.27.5
  4. npm ls react-scripts (if you haven’t ejected): react-scripts@1.0.7

Then, specify:

  1. Operating system:Xubuntu 1604
  2. Browser and version (if relevant):
Assignee
Assign to
Time tracking