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

bug: Unable to run Jest spec files from subdirectory or absolute path #3785

Closed
3 tasks done
sean-perkins opened this issue Nov 1, 2022 · 6 comments
Closed
3 tasks done
Assignees
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil

Comments

@sean-perkins
Copy link
Contributor

Prerequisites

Stencil Version

v2.19.2

Current Behavior

When running stencil test --spec in Ionic Framework (main), we are only able to run tests for the entire src/utils directory with the following command:

stencil test --spec --max-workers=2 src/utils/

If we provide an additional sub directory or absolute path to our spec file, we receive the following error:

  ● Test suite failed to run

    TypeError: virtualMocks.get is not a function

      at Resolver._getVirtualMockPath (node_modules/@jest/core/node_modules/jest-resolve/build/resolver.js:468:25)

This occurs with any of the following:

stencil test --spec --max-workers=2 src/utils/keyboard/

stencil test --spec --max-workers=2 src/utils/keyboard/test/keyboard.spec.ts

The test runs and passes correctly if we run from src/utils.

Expected Behavior

Developers should be able to run the stencil test --spec command with any valid directory or absolute path and the spec files should execute consistently; regardless of if ran exclusively or as part of a larger directory.

Steps to Reproduce

  1. Clone Ionic Framework
  2. Checkout main branch
  3. Run npm run test.spec src/utils
  4. Observe: Tests run successfully
  5. Run npm run test.spec src/utils/keyboard
  6. Observe: Tests fail with the error mentioned above

Code Reproduction URL

https://github.com/ionic-team/ionic-framework

Additional Information

No response

@ionitron-bot ionitron-bot bot added the triage label Nov 1, 2022
@rwaskiewicz rwaskiewicz added the Bug: Validated This PR or Issue is verified to be a bug within Stencil label Nov 1, 2022
@ionitron-bot ionitron-bot bot removed the triage label Nov 1, 2022
@rwaskiewicz
Copy link
Member

npx stencil test --spec --max-workers=2 src/utils/keyboard works, but npm run test.spec -- src/utils/keyboard and npm run test.spec src/utils/keyboard do not 🤔

@alicewriteswrongs
Copy link
Member

found a few issues which might be related: playwright-community/jest-playwright#665 and jestjs/jest#11267 (comment)

Unfortunately upgrading Jest in framework doesn't fix it :/

@alicewriteswrongs
Copy link
Member

alicewriteswrongs commented Nov 18, 2022

also I've found that in addition to the commands @rwaskiewicz mentioned above, the following works:

npx stencil test --spec --max-workers=2 src/utils/keyboard/test/

while the following does not

npx stencil test --spec --max-workers=2 src/utils/keyboard/test

the only difference being the trailing slash. So something odd is going on here!

@alicewriteswrongs
Copy link
Member

Ok so this is actually some sort of caching thing, I think on Jest’s side of things but I’m not sure.

Basically if you run a command like this one multiple times in a row:

npx stencil test --spec --max-workers=2 src/utils/keyboard

it will alternate between running correctly and failing. The same applies for doing npm run tsc.spec , passing other sub-directories, etc.

@alicewriteswrongs
Copy link
Member

Aaaallright so the issue was caused by having different versions of @jest/core, on the one hand, and jest and jest-cli on the other. I updated jest and jest-cli in a branch in Framework to match the version of @jest/core (27.5.1) and can no longer reproduce the issue.

alicewriteswrongs added a commit to ionic-team/ionic-framework that referenced this issue Nov 18, 2022
This harmonizes the versions of Jest installed in Framework to address
an issue reported in Stencil here:
ionic-team/stencil#3785

The issue is essentially that certain test commands, such as this one:

```
npx stencil test --spec --max-workers=2 src/utils/keyboard/test/
```

will, at present, alternate between running the tests as expected and
failing. Not good!

The issue is caused by having different @jest/core, on the one hand, and
jest and jest-cli on the other. After updating jest and jest-cli in a to
match the version of @jest/core (27.5.1) and the issue can no longer be
reproduced.
alicewriteswrongs added a commit to ionic-team/ionic-framework that referenced this issue Nov 18, 2022
…ching

This harmonizes the versions of Jest installed in Framework to address
an issue reported in Stencil here:
ionic-team/stencil#3785

The issue is essentially that certain test commands, such as this one:

```
npx stencil test --spec --max-workers=2 src/utils/keyboard/test/
```

will, at present, alternate between running the tests as expected and
failing. Not good!

The issue is caused by having different @jest/core, on the one hand, and
jest and jest-cli on the other. After updating jest and jest-cli in a to
match the version of @jest/core (27.5.1) and the issue can no longer be
reproduced.
alicewriteswrongs added a commit to ionic-team/ionic-framework that referenced this issue Nov 18, 2022
…ching

This harmonizes the versions of Jest installed in Framework to address
an issue reported in Stencil here:
ionic-team/stencil#3785

The issue is essentially that certain test commands, such as this one:

```
npx stencil test --spec --max-workers=2 src/utils/keyboard/test/
```

will, at present, alternate between running the tests as expected and
failing. Not good!

The issue is caused by having different versions of `@jest/core`, on the
one hand, and `jest` and `jest-cli` on the other. After updating `jest`
and `jest-cli` to match the version of `@jest/core` (`27.5.1`) and the
issue can no longer be reproduced.
alicewriteswrongs added a commit to ionic-team/ionic-framework that referenced this issue Nov 18, 2022
…ching (#26320)

This harmonizes the versions of Jest installed in Framework to address
an issue reported in Stencil here:
ionic-team/stencil#3785

The issue is essentially that certain test commands, such as this one:

```
npx stencil test --spec --max-workers=2 src/utils/keyboard/test/
```

will, at present, alternate between running the tests as expected and
failing. Not good!

The issue is caused by having different versions of `@jest/core`, on the
one hand, and `jest` and `jest-cli` on the other. After updating `jest`
and `jest-cli` to match the version of `@jest/core` (`27.5.1`) and the
issue can no longer be reproduced.
@rwaskiewicz
Copy link
Member

Closing, as we received feedback from the Framework team that ionic-team/ionic-framework#26320 resolved the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil
Projects
None yet
Development

No branches or pull requests

3 participants