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

fix: add root node_modules to import commands when running pnpm #1482

Closed
wants to merge 1 commit into from

Conversation

felipeplets
Copy link
Contributor

fixes 1481

@felipeplets
Copy link
Contributor Author

@ninadbstack @shantanuk-browserstack This is an important fix for my company. Is there anything I can do to get it reviewed/merged?

I tried running the Unit Tests locally to improve the test coverage but I wasn't able to. I receive multiple errors.

Copy link

This PR is stale because it has been open for more than 14 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the 🍞 stale Closed due to inactivity label Jan 23, 2024
@ninadbstack
Copy link
Contributor

@felipeplets thanks for raising the PR for fix [ and thanks for raising a support ticket, we had missed this pr ]

As spec coverage has reduced post this, we are thinking if we can fix it [ it depends on the env setup so might be slightly harder. Give us some time and we would look into same.

@felipeplets
Copy link
Contributor Author

@ninadbstack thank you. Is there any setup or steps I should take to run the unit tests locally? I tried doing it so that I could add the necessary coverage but haven't had success.

@ninadbstack
Copy link
Contributor

@felipeplets ideally most of the test cases should run locally without issues. Its just yarn followed by yarn test. As you are making change in a single package. You can also target tests for a single package with yarn workspace @percy/<package> test

Its just that looking at the implementation that you have, you are basically looking at .pnpm folder in root path, if true, its adding the @percy folder inside .pnpm dir to search paths.

To test this, we need a mock fs as percy cli test agents do not have .pnpm setup, you can mock it with mockModuleCommands, you can see usage in tests.
The harder part here is to mock the root as its coming from import.meta.url, maybe you can try mocking path.resolve to get coverage on the same.

@github-actions github-actions bot removed the 🍞 stale Closed due to inactivity label Feb 6, 2024
Copy link

This PR is stale because it has been open for more than 14 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the 🍞 stale Closed due to inactivity label Feb 27, 2024
@felipeplets
Copy link
Contributor Author

@ninadbstack I tried a couple of things but I still can't run the tests locally.

Here are the versions I am using:

  • Yarn 1.22.21
  • NodeJS 20.11.1 (I also tried with 18.16.0)

The commands I ran:

yarn <-- success
yarn build <-- success
yarn test <-- failed
yarn workspace @percy/cli test <-- failed

The yarn test fails in @percy/dom the error is:

@percy/dom: 29 02 2024 22:09:01.818:ERROR [launcher]: No binary for FirefoxHeadless browser on your platform.
@percy/dom:   Please, set "FIREFOX_BIN" env variable.
@percy/dom: 29 02 2024 22:09:01.819:ERROR [karma-server]: UncaughtException: TypeError: Cannot read properties of undefined (reading 'stderr')
@percy/dom:     at FirefoxBrowser._start (/Users/u/percy-cli/node_modules/karma-firefox-launcher/index.js:273:19)
@percy/dom:     at Object.<anonymous> (/Users/u/percy-cli/node_modules/karma/lib/launchers/process.js:19:10)
@percy/dom:     at Object.emit (node:events:530:35)
@percy/dom:     at BaseLauncher.start (/Users/u/percy-cli/node_modules/karma/lib/launchers/base.js:52:10)
@percy/dom:     at Object.j (/Users/u/percy-cli/node_modules/karma/lib/launcher.js:108:17)
@percy/dom:     at setTimeout.bind.j (/Users/u/percy-cli/node_modules/qjobs/qjobs.js:143:18)
@percy/dom:     at listOnTimeout (node:internal/timers:573:17)
@percy/dom:     at process.processTimers (node:internal/timers:514:7)
@percy/dom: 29 02 2024 22:09:01.819:ERROR [karma-server]: TypeError: Cannot read properties of undefined (reading 'stderr')
@percy/dom:     at FirefoxBrowser._start (/Users/u/percy-cli/node_modules/karma-firefox-launcher/index.js:273:19)
@percy/dom:     at Object.<anonymous> (/Users/u/percy-cli/node_modules/karma/lib/launchers/process.js:19:10)
@percy/dom:     at Object.emit (node:events:530:35)
@percy/dom:     at BaseLauncher.start (/Users/u/percy-cli/node_modules/karma/lib/launchers/base.js:52:10)
@percy/dom:     at Object.j (/Users/u/percy-cli/node_modules/karma/lib/launcher.js:108:17)
@percy/dom:     at setTimeout.bind.j (/Users/u/percy-cli/node_modules/qjobs/qjobs.js:143:18)
@percy/dom:     at listOnTimeout (node:internal/timers:573:17)
@percy/dom:     at process.processTimers (node:internal/timers:514:7)
error Command failed with exit code 1.

For testing only the CLI I used yarn workspace @percy/cli test and all tests failed. So I isolated a single test to debug and this is the error:

yarn workspace @percy/cli test
yarn workspace v1.22.21
yarn run v1.22.21
$ node ../../scripts/test
(node:77108) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("file%3A///Users/u/percy-cli/scripts/loader.js", pathToFileURL("./"));'
(Use `node --trace-warnings ...` to show where the warning was created)
Running node tests...

Jasmine started

  CLI commands

    from a project
      ✗ imports the project command
        - Expected a promise to be resolved to [ <jasmine.objectContaining(Object({ name: 'foobar' }))> ] but it was rejected with Error: Cannot find module '/Users/u/percy-cli/packages/cli/command.js' imported from /Users/u/percy-cli/packages/cli/src/commands.js.

**************************************************
*                    Failures                    *
**************************************************

1) CLI commands from a project imports the project command
  - Expected a promise to be resolved to [ <jasmine.objectContaining(Object({ name: 'foobar' }))> ] but it was rejected with Error: Cannot find module '/Users/u/percy-cli/packages/cli/command.js' imported from /Users/u/percy-cli/packages/cli/src/commands.js.

  file:///Users/u/percy-cli/packages/cli/test/commands.test.js:17:43
  jasmine-spec-reporter: unable to open 'file:///Users/u/percy-cli/packages/cli/test/commands.test.js'
  Error: ENOENT: no such file or directory, open 'file:///Users/u/percy-cli/packages/cli/test/commands.test.js'


Executed 1 of 24 specs (1 FAILED) (23 SKIPPED) in 0.018 sec.
error Command failed with exit code 3.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 3
Command: /Users/plets/.nvm/versions/node/v20.11.1/bin/node
Arguments: /Users/plets/.cache/node/corepack/yarn/1.22.21/lib/cli.js test
Directory: /Users/u/percy-cli/packages/cli
Output:

info Visit https://yarnpkg.com/en/docs/cli/workspace for documentation about this command.

@felipeplets
Copy link
Contributor Author

I got it. The errors were due to me using newer node versions. Using the same that runs in the repository GitHub workflows (14.21.3) the tests run.

@github-actions github-actions bot removed the 🍞 stale Closed due to inactivity label Mar 5, 2024
Copy link

This PR is stale because it has been open for more than 14 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the 🍞 stale Closed due to inactivity label Mar 19, 2024
Copy link

github-actions bot commented Apr 9, 2024

This PR was closed because it has been stalled for 28 days with no activity.

@github-actions github-actions bot closed this Apr 9, 2024
@EWhite613
Copy link

Any chance this can be reopened? Also seeing this issue

@ninadbstack
Copy link
Contributor

@EWhite613 we can reopen this, the PR was auto closed due to no activity and missing tests.

That said if you want percy team to prioritize this please raise a support ticket for the same. [ Or feel free to send a PR with tests so that we can verify and get it merged ]

@felipeplets
Copy link
Contributor Author

@ninadbstack I opened a new PR including the Unit Tests #1643

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

Successfully merging this pull request may close these issues.

[percy] ParseError: Unexpected argument 'storybook'
3 participants