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

prefer-wait-for: Cannot read property 'arguments' of null #272

Closed
AriPerkkio opened this issue Dec 15, 2020 · 18 comments
Closed

prefer-wait-for: Cannot read property 'arguments' of null #272

AriPerkkio opened this issue Dec 15, 2020 · 18 comments
Milestone

Comments

@AriPerkkio
Copy link
Contributor

Hello, prefer-wait-for rule seems to crash in certain cases. This issue was spotted by automated CI run - it is not blocking my development or anything. ESlint rules should not crash in any condition since this makes all valid linting problems disappear. If this is a false flag please let me know.

https://github.com/AriPerkkio/eslint-remote-tester/runs/1551964310?check_suite_focus=true

Complete list of dependencies and .eslintrc is available at CI runs logs, steps Run yarn list | grep eslint and Run yarn log --config ./plugin-configs/eslint-plugin-testing-library.config.js.

eslint-plugin-testing-library@3.10.1
rules: {
    'testing-library/prefer-wait-for': 'error',
}

Minimal repro:

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

global.waitForElement = waitForElement;
TypeError: Cannot read property 'arguments' of null Occurred while linting <text>:2
    at Object.fix (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:61:50)
Crash reports from real projects

Rule: prefer-wait-for

  • Message: Cannot read property 'arguments' of null Occurred while linting <text>:2
  • Path: diondirza/rexr/test/test-utils.js
  • Link
import React from 'react';
import { fireEvent, render, waitForElement } from '@testing-library/react';
import { HelmetProvider } from 'react-helmet-async';
import { Router } from 'react-router-dom';
import { createBrowserHistory } from 'history';

import { GlobalProvider } from '@context';
TypeError: Cannot read property 'arguments' of null Occurred while linting <text>:2
    at Object.fix (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:61:50)
    at normalizeFixes (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/report-translator.js:178:28)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/report-translator.js:347:49
    at Object.report (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/linter.js:920:41)
    at reportWait (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:53:21)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:97:36
    at Array.forEach (<anonymous>)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:96:52
    at Array.forEach (<anonymous>)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:95:26

Rule: prefer-wait-for

  • Message: Cannot read property 'arguments' of null Occurred while linting <text>:18
  • Path: gravitational/webapps/packages/design/src/utils/testing.tsx
  • Link
 * limitations under the License.
 */

import React from 'react';
import {
  render as testingRender,
  act,
  fireEvent,
  waitForElement,
} from '@testing-library/react';
TypeError: Cannot read property 'arguments' of null Occurred while linting <text>:18
    at Object.fix (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:61:50)
    at normalizeFixes (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/report-translator.js:178:28)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/report-translator.js:347:49
    at Object.report (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/linter.js:920:41)
    at reportWait (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:53:21)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:97:36
    at Array.forEach (<anonymous>)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:96:52
    at Array.forEach (<anonymous>)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:95:26

Rule: prefer-wait-for

  • Message: Cannot read property 'arguments' of null Occurred while linting <text>:2
  • Path: faultable/wardex/src/setupTests.js
  • Link
import React from 'react'
import {
  afterEach,
  render,
  cleanup,
  fireEvent,
  wait,
TypeError: Cannot read property 'arguments' of null Occurred while linting <text>:2
    at Object.fix (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:61:50)
    at normalizeFixes (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/report-translator.js:178:28)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/report-translator.js:347:49
    at Object.report (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/linter.js:920:41)
    at reportWait (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:53:21)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:97:36
    at Array.forEach (<anonymous>)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:96:52
    at Array.forEach (<anonymous>)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:95:26

Rule: prefer-wait-for

  • Message: Cannot read property 'arguments' of null Occurred while linting <text>:2
  • Path: activewidgets/react/test/adapter/react.js
  • Link
import {render, fireEvent, wait, waitForElement} from '@testing-library/react';
import {h} from '@activewidgets/components';


export function mount(component, props){
    return render(h(component, props));
TypeError: Cannot read property 'arguments' of null Occurred while linting <text>:2
    at Object.fix (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:61:50)
    at normalizeFixes (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/report-translator.js:178:28)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/report-translator.js:347:49
    at Object.report (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/linter.js:920:41)
    at reportWait (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:53:21)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:97:36
    at Array.forEach (<anonymous>)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:96:52
    at Array.forEach (<anonymous>)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:95:26

Rule: prefer-wait-for

  • Message: Cannot read property 'arguments' of null Occurred while linting <text>:3
  • Path: w-sr/React-Storybook-Game/src/setupTests.js
  • Link
import React from 'react';
import '@testing-library/jest-dom/extend-expect';
import { render, fireEvent, waitForElement } from '@testing-library/react';
import renderer from 'react-test-renderer';
import sinon from 'sinon';
import { act } from 'react-dom/test-utils';
import 'jest-styled-components';
TypeError: Cannot read property 'arguments' of null Occurred while linting <text>:3
    at Object.fix (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:61:50)
    at normalizeFixes (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/report-translator.js:178:28)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/report-translator.js:347:49
    at Object.report (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/linter.js:920:41)
    at reportWait (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:53:21)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:97:36
    at Array.forEach (<anonymous>)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:96:52
    at Array.forEach (<anonymous>)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:95:26

Rule: prefer-wait-for

  • Message: Cannot read property 'arguments' of null Occurred while linting <text>:20
  • Path: sumup-oss/circuit-ui/src/util/test-utils.tsx
  • Link
import React, { FunctionComponent } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import '@testing-library/jest-dom/extend-expect';
import { configureAxe } from 'jest-axe';
import {
  render as renderTest,
  wait,
  act,
  RenderResult,
} from '@testing-library/react';
TypeError: Cannot read property 'arguments' of null Occurred while linting <text>:20
    at Object.fix (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:61:50)
    at normalizeFixes (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/report-translator.js:178:28)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/report-translator.js:347:49
    at Object.report (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint/lib/linter/linter.js:920:41)
    at reportWait (/home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:53:21)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:97:36
    at Array.forEach (<anonymous>)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:96:52
    at Array.forEach (<anonymous>)
    at /home/runner/work/eslint-remote-tester/eslint-remote-tester/ci/node_modules/eslint-plugin-testing-library/rules/prefer-wait-for.js:95:26
@gndelia
Copy link
Collaborator

gndelia commented Dec 15, 2020

Hi AriPerkkio , thanks for posting. How would the test usage look like? Just a regular

waitForElement(() => getByText('foo')) 

?

I wouldn't recommend storing the queries in the global space. You can always import screen and use them from there. In addition to that, you might want to use waitFor instead of waitForElement as waitForElement is deprecated.

Either way, we could try to fix this scenario to prevent the suite from crashing

@gndelia gndelia added the question Further information is requested label Dec 15, 2020
@AriPerkkio
Copy link
Contributor Author

I should have mentioned that the use case causing the crash might not be valid or recommended. I'm just testing stability of various community ESLint plugins and reporting the issues to plugin developers. This same issue could come up in completely valid case too.

This is also crashing:

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

const renamedWaitForElement = waitForElement;

@Belco90
Copy link
Member

Belco90 commented Dec 15, 2020

Hello Ari. Thanks for opening this issue. You are right: this scenario shouldn't cause any error. However, we are close to finish v4 of the plugin, which includes a huge refactor of all rules almost from the ground. I can confirm this case has been fixed on v4 as you can see here:
image
So I would suggest to wait for this version if it is an extreme edge case to catch errors in the plugin.

@AriPerkkio
Copy link
Contributor Author

Thanks for the verification @Belco90. Feel free to close this issue.

Once v4 is available in npm I'll include it to my weekly scheduled CI runs on eslint-remote-tester.

@Belco90
Copy link
Member

Belco90 commented Dec 15, 2020

Awesome! I think I'm gonna leave it open as I did with other issues solved on v4 until it gets released.

@Belco90 Belco90 removed the question Further information is requested label Dec 15, 2020
@Belco90
Copy link
Member

Belco90 commented Apr 11, 2021

This should be fixed on v4.0.0

The release is available on:

@Belco90 Belco90 closed this as completed Apr 11, 2021
@Belco90
Copy link
Member

Belco90 commented Apr 14, 2021

Hey @AriPerkkio! I saw after releasing v4 of the plugin the badge for this ESLint plugin is green in your eslint-remote-tester! 🎉

Would be fine to include such a badge in our README?

@AriPerkkio
Copy link
Contributor Author

Congratulations about v4! 🎉

I was excited to see how it stands against heavy 6 hour tests - and it was perfect score with 0 crashes.
It was so fast that I'm even suspecting I've misconfigured the eslintrc 😄.
[eslint-plugin-testing-library]: Repositories (14024/14496)

Here are some comparisons from other plugins. The results are not 100% comparable but it provides some useful feedback about plugin's performance.

6 hour time limit, maximum of 14K repositories to test:
[eslint-plugin-unicorn]: Repositories (6101/14496)
[eslint-plugin-react]: Repositories (5823/14496)
[eslint-plugin-import]: Repositories (7830/14496)
[eslint-plugin-mocha]: Repositories (3198/14496) 😢 
[eslint-plugin-jest]: Repositories (12910/14496)

Would be fine to include such a badge in our README?

Definitely!

If you are interested in keeping master branch of this repository stable I could help by setting up PR where eslint-remote-tester would be run in this repository. Some ESLint plugins are already doing this. See https://github.com/marketplace/actions/eslint-remote-tester-runner.

@MichaelDeBoey
Copy link
Member

@AriPerkkio Would it also be possible to have your workflows report automatically in our repo somehow? 🤔
Maybe with a restriction that it would only be possible from a certain bot (with permissions on this repo), so that it's not flagged as spam or something.

You're already running all tests, so CI would run a second time on this repo for no other reason than to report possible bugs to us.

Can you also provide us with the list of the other ESLint plugins that already use your action themselves please?

@AriPerkkio
Copy link
Contributor Author

Would it also be possible to have your workflows report automatically in our repo somehow?

I'm not sure whether Github provides functionality for this. The workflow is currently utilizing octokit client for creating the issues. I'll need to look into octokit's documentation - PRs to eslint-remote-tester-run-action are also welcome. 👍

so CI would run a second time on this repo for no other reason than to report possible bugs to us.

Note that eslint-remote-tester is running against the latest published release. It would be ideal if plugins would caught these issues even before publishing their release. Running against latest master is easiest from the plugin repositories themselves.

So far eslint-plugin-unicorn, eslint-plugin-jest-dom and eslint-plugin-knex(?) are running tests in their repositories. There is an open PR for eslint-plugin-react too. I haven't really advertised this tool much.

@MichaelDeBoey
Copy link
Member

MichaelDeBoey commented Apr 14, 2021

Note that eslint-remote-tester is running against the latest published release. It would be ideal if plugins would caught these issues even before publishing their release. Running against latest master is easiest from the plugin repositories themselves.

@AriPerkkio Since this package is using semantic-release, everything that's pushed to main will also be released.

Running these smoke tests in this repo will also result in a 6 hour run for each push to main.

We would also have to update/maintain the repositories.json & eslint-remote-tester.config.js files ourselves, which will become outdated really quickly with what you have in your repo.
Since you're already doing all this hard work, I think we could all benefit (not only this repo, but all the other ESLint plugins too) from that work without doing it twice.

@Belco90
Copy link
Member

Belco90 commented Apr 14, 2021

It would be interesting to run this check to have some insights about the plugin, but we shouldn't block any package release because of this check.

@MichaelDeBoey
Copy link
Member

That's why I think it would be better to have this run in the original eslint-remote-tester repo and create an issue in this repository whenever there will be an error found.

Having this as a bot would be the way to go I think, as that way we can give/revoke permissions.

@AriPerkkio
Copy link
Contributor Author

Good points @MichaelDeBoey. Let's keep running the tests in eslint-remote-tester repository and check if the bot could post results in this project.

I would imagine something like repository-for-results: testing-library/eslint-plugin-testing-library option for eslint-remote-tester-run-action setup. And possibly some other fields for selecting/authenticating the bot.

@Belco90
Copy link
Member

Belco90 commented Apr 14, 2021

Thanks for your help @AriPerkkio! I'll include the badge in the following days. Probably we can move the reporting from eslint-remote-tester to a new discussion.

@Belco90
Copy link
Member

Belco90 commented Apr 14, 2021

@AriPerkkio I forgot to mention: another possibility would be running eslint-remote-tester-runner within this project without blocking the CI at all, that's up to us 😄 . So every time we release a new version, we trigger the remote tester runner in parallel and leave it doing its thing to get the report when gets finished. Is that possible? I guess so right?

@AriPerkkio
Copy link
Contributor Author

That's definitely possible and even better option than waiting for my weekly scheduled tests to trigger. You wouldn't have to wait 7 days for getting the latest results.

There is of course this:

We would also have to update/maintain the repositories.json & eslint-remote-tester.config.js files ourselves

... but it is not really that much of a work. I haven't updated my repositories.json in a long time: https://github.com/AriPerkkio/eslint-remote-tester/commits/master/configs/repositories.json

eslint-remote-tester will simply skip a repository in case it cannot clone it, e.g. when it encounters a repository which has been made private. Even the current repositories.json contains some private repositories.

Also consider the case where you make a breaking change or add new rule. This change would have to be made into eslint-remote-tester's eslintrc too. It would be easier if the configuration lived in same repository as the plugin.

But as said both options are possible, it is up to you to decide which way to go.

@MichaelDeBoey
Copy link
Member

@AriPerkkio We can start with the weekly triggered tests on your repo for now and maybe manually putting all errors in an issue here I think.

We can discuss this maybe even further in an issue/discussion on your repo so we don't hijack this issue any further?

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

4 participants