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: broken support for yarn executing tests #3482

Closed
3 tasks done
jeripeierSBB opened this issue Jul 20, 2022 · 11 comments
Closed
3 tasks done

bug: broken support for yarn executing tests #3482

jeripeierSBB opened this issue Jul 20, 2022 · 11 comments
Assignees
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil

Comments

@jeripeierSBB
Copy link

Prerequisites

Stencil Version

2.17.1

Current Behavior

Executing yarn test with another script name as test fails.

Consider the following example specified in package.json scripts section:

...
 "scripts": {
    "test:dev": "stencil test --spec --e2e --coverage",
  },
...

if executing yarn test:dev it fails and the following output is generated:

jest args: test:dev --e2e --spec --coverage --max-workers=8
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /Users/*/Desktop/test-fail-repro
  79 files checked.
  testMatch:  - 0 matches
  testPathIgnorePatterns: /Users/*/Desktop/test-fail-repro/.vscode, /Users/*/Desktop/test-fail-repro/.stencil, /Users/*/Desktop/test-fail-repro/node_modules, /Users/*/Desktop/test-fail-repro/www, /Users/*/Desktop/test-fail-repro/dist - 22 matches
  testRegex: (/__tests__/.*|(\.|/)(test|spec|e2e))\.[jt]sx?$ - 3 matches
Pattern: test:dev - 0 matches
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Expected Behavior

Tests should be executed as before version 2.17.1

Steps to Reproduce

  1. npm init stencil
  2. move to your directory
  3. execute yarn
  4. rename test to test:dev in package.json
  5. executeyarn test:dev
  6. See error

Code Reproduction URL

https://github.com/jeripeierSBB/stencil-yarn-fail-repro

Additional Information

No response

@alicewriteswrongs
Copy link
Contributor

Hello @jeripeierSBB, thanks for filing this issue! I was just able to validate that this is occurring. It look to be an issue specific to yarn, since in your reproduction case I am able to run the test:dev script with no problems w/ npm (i.e. npm run test:dev).

In any case, I'm going to add this to the backlog and hopefully we'll have a fix soon for running scripts like these w/ yarn!

@alicewriteswrongs alicewriteswrongs added the Bug: Validated This PR or Issue is verified to be a bug within Stencil label Jul 20, 2022
@ionitron-bot ionitron-bot bot removed the triage label Jul 20, 2022
@jeripeierSBB
Copy link
Author

@alicewriteswrongs thanks for getting into this. I have to mention that with version 2.17.0 it worked, so this problem was newly introduced with version 2.17.1

@alicewriteswrongs
Copy link
Contributor

That makes sense, this recent pr #3444 was included in the 2.17.1 release, so it makes sense that the behavior changed then.

@alicewriteswrongs
Copy link
Contributor

alicewriteswrongs commented Jul 20, 2022

edit: disregard this! commented on the wrong PR 🤦‍♀️

@alicewriteswrongs
Copy link
Contributor

@jeripeierSBB would you mind providing some information about the version of yarn you're using, and how you had this working before upgrading to @stencil/core@2.17.1? I ask because in the reproduction repo that you provided I'm able to reproduce the issue with an earlier version of Stencil installed (2.13.0 to be specific). I'm using yarn 1.22.18 for testing locally.

Screen Shot 2022-07-20 at 3 16 41 PM

@manojreddymettu-pro
Copy link

Hi, This issue is happening with NPM as well.

Worked fine till stencil/core:2.17.0 and after upgrading to 2.17.1 I see the below issue.

Note: The tests runs fine when you don't use explicit directory paths like --coverage-directory and --outputFile

Issue:

[19:08.9]  @stencil/core
[19:09.1]  v2.17.1 😊
[19:09.3]  testing spec files
[19:09.5]  jest args: --spec --coverage --json --coverage-directory=./dist-coverage/jest-test-coverage
           ./dist-coverage/jest-test-coverage --outputFile=.jest-test-results.json .jest-test-results.json
           --max-workers=8
No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In /Users/mettuman/IdeaProjects/proj-fork
  211 files checked.
  testMatch:  - 0 matches
  testPathIgnorePatterns: /Users/mettuman/IdeaProjects/proj-fork/.vscode,
  /Users/mettuman/IdeaProjects/proj-fork/.stencil, /Users/mettuman/IdeaProjects/proj-fork/node_modules, /Users/mettuman/IdeaProjects/proj-fork/www, /Users/mettuman/IdeaProjects/proj-fork/dist - 71 matches
  testRegex: (/__tests__/.*|(\.|/)(test|spec|e2e))\.[jt]sx?$ - 2 matches
Pattern: ./dist-coverage/jest-test-coverage|.jest-test-results.json - 0 matches

@alicewriteswrongs
Copy link
Contributor

@manojreddymettu-pro I believe that is a separate issue, see #3481 and #3471

alicewriteswrongs added a commit that referenced this issue Jul 22, 2022
This removes some code from our argument parsing implementation which
would look for an environment variable (`npm_config_argv`) set by npm
and, if present, merge CLI flags found their into the ones already
present on `process.argv`.

We want to remove this for two reasons:

- `npm_config_argv` is deprecated in `npm`, so in newer versions of the
  package manager it is no longer set and our code referencing it is
  effectively doing nothing
- `yarn` v1.x still sets it (presumably for compatibility with `npm`
  that hasn't been removed yet, which causes an inconsistency between
  `npm` and `yarn` where certain `package.json` scripts will run without
  issue in `npm` but fail in `yarn` (see #3482)

Accordingly, this commit deletes the offending function from
`src/cli/parse-flags.ts` and makes a few related changes at call sites,
etc which are necessary due to that change.

This commit also refactors the spec file for `parse-flags.ts` to remove
redundant tests. Because all of the supported CLI arguments (i.e. those
added to `knownArgs`) are defined in `ReadonlyArray<string>` variables
we can do a lot of exhaustive testing of all the arguments, set in the
various possible permutations, etc, so we don't need to define a bunch
of individual tests. Accordingly, the test file is refactored to remove
redundant tests, add a few more test cases for the exhaustive tests,
organize things a bit more with `describe` blocks, and ensure that we
have good tests around all off the 'edge-case-ey' things.
alicewriteswrongs added a commit that referenced this issue Jul 22, 2022
This removes some code from our argument parsing implementation which
would look for an environment variable (`npm_config_argv`) set by npm
and, if present, merge CLI flags found their into the ones already
present on `process.argv`.

We want to remove this for two reasons:

- `npm_config_argv` is deprecated in `npm`, so in newer versions of the
  package manager it is no longer set and our code referencing it is
  effectively doing nothing
- `yarn` v1.x still sets it (presumably for compatibility with `npm`
  that hasn't been removed yet, which causes an inconsistency between
  `npm` and `yarn` where certain `package.json` scripts will run without
  issue in `npm` but fail in `yarn` (see #3482)

Accordingly, this commit deletes the offending function from
`src/cli/parse-flags.ts` and makes a few related changes at call sites,
etc which are necessary due to that change.

This commit also refactors the spec file for `parse-flags.ts` to remove
redundant tests. Because all of the supported CLI arguments (i.e. those
added to `knownArgs`) are defined in `ReadonlyArray<string>` variables
we can do a lot of exhaustive testing of all the arguments, set in the
various possible permutations, etc, so we don't need to define a bunch
of individual tests. Accordingly, the test file is refactored to remove
redundant tests, add a few more test cases for the exhaustive tests,
organize things a bit more with `describe` blocks, and ensure that we
have good tests around all off the 'edge-case-ey' things.
alicewriteswrongs added a commit that referenced this issue Jul 22, 2022
This removes some code from our argument parsing implementation which
would look for an environment variable (`npm_config_argv`) set by npm
and, if present, merge CLI flags found their into the ones already
present on `process.argv`.

We want to remove this for two reasons:

- `npm_config_argv` is deprecated in `npm`, so in newer versions of the
  package manager it is no longer set and our code referencing it is
  effectively doing nothing
- `yarn` v1.x still sets it (presumably for compatibility with `npm`
  that hasn't been removed yet, which causes an inconsistency between
  `npm` and `yarn` where certain `package.json` scripts will run without
  issue in `npm` but fail in `yarn` (see #3482)

Accordingly, this commit deletes the offending function from
`src/cli/parse-flags.ts` and makes a few related changes at call sites,
etc which are necessary due to that change.

This commit also refactors the spec file for `parse-flags.ts` to remove
redundant tests. Because all of the supported CLI arguments (i.e. those
added to `knownArgs`) are defined in `ReadonlyArray<string>` variables
we can do a lot of exhaustive testing of all the arguments, set in the
various possible permutations, etc, so we don't need to define a bunch
of individual tests. Accordingly, the test file is refactored to remove
redundant tests, add a few more test cases for the exhaustive tests,
organize things a bit more with `describe` blocks, and ensure that we
have good tests around all off the 'edge-case-ey' things.
rwaskiewicz pushed a commit that referenced this issue Jul 22, 2022
This removes some code from our argument parsing implementation which
would look for an environment variable (`npm_config_argv`) set by npm
and, if present, merge CLI flags found their into the ones already
present on `process.argv`.

We want to remove this for two reasons:

- `npm_config_argv` is deprecated in `npm` v7+, so in newer versions of the
  package manager it is no longer set and our code referencing it is
  effectively doing nothing
- `yarn` v1.x still sets it (presumably for compatibility with `npm`
  that hasn't been removed yet, which causes an inconsistency between
  `npm` and `yarn` where certain `package.json` scripts will run without
  issue in `npm` but fail in `yarn` (see #3482)

Accordingly, this commit deletes the offending function from
`src/cli/parse-flags.ts` and makes a few related changes at call sites,
etc which are necessary due to that change.

This commit also refactors the spec file for `parse-flags.ts` to remove
redundant tests. Because all of the supported CLI arguments (i.e. those
added to `knownArgs`) are defined in `ReadonlyArray<string>` variables
we can do a lot of exhaustive testing of all the arguments, set in the
various possible permutations, etc, so we don't need to define a bunch
of individual tests. Accordingly, the test file is refactored to remove
redundant tests, add a few more test cases for the exhaustive tests,
organize things a bit more with `describe` blocks, and ensure that we
have good tests around all off the 'edge-case-ey' things.
@alicewriteswrongs
Copy link
Contributor

@jeripeierSBB to update you, we merged a PR today (#3486) which I believe fixes the underlying issue you're running in to here.

If you want to test it out to make sure it fixes your issue you could:

  • clone the repo locally
  • do npm install, npm run build and npm pack
  • try installing the resulting .tgz file in our project by doing npm install ./path/to/stencil.tgz

If you'd rather wait for a pre-release or release build to try that out no worries, we will be doing one soon.

Thanks again for reporting this issue!

@jeripeierSBB
Copy link
Author

providing some information about the version of yarn you're using, and how yo

@alicewriteswrongs Thanks for all your work on it and sorry for my late response. I'm using yarn v1.22.19, and in my project it really worked with stencil 2.17.0.

I tested your fix and it works with yarn, thank you! Should I close the issue myself?

@alicewriteswrongs
Copy link
Contributor

alicewriteswrongs commented Jul 25, 2022 via email

@rwaskiewicz
Copy link
Member

The fix for this issue has been officially released as a part of Stencil v2.17.2. As a result, I'm going to close this issue and mark it as completed. If the bug re-appears, please feel free to open a new 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

4 participants