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][cli] --load-env-files cannot be used in conjunction with yarn rw test #11884

Open
1 task done
Philzen opened this issue Jan 7, 2025 · 0 comments · May be fixed by #11887
Open
1 task done

[Bug][cli] --load-env-files cannot be used in conjunction with yarn rw test #11884

Philzen opened this issue Jan 7, 2025 · 0 comments · May be fixed by #11887
Labels
bug/needs-info More information is needed for reproduction

Comments

@Philzen
Copy link
Contributor

Philzen commented Jan 7, 2025

What's not working?

#9961 introduced a flag into the CLI to load additional .env files which is currently named --load-env-files:

.option('load-env-files', {
describe:
'Load additional .env files. Values defined in files specified later override earlier ones.',
array: true,
})
.example(
'yarn rw exec migrateUsers --load-env-files stripe nakama',
"Run a script, also loading env vars from '.env.stripe' and '.env.nakama'",
)

Trying to use this feature for testing fails (Outcome 1):

$ yarn rw test api --load-env-files test

● Unrecognized CLI Parameter:

  Unrecognized option "loadEnvFiles".

  CLI Options Documentation:
  https://jestjs.io/docs/cli

This is presumably because everything after the first input following test is forwarded to jest.

const forwardJestFlags = Object.keys(others).flatMap((flagName) => {
if (
['watch', 'collect-coverage', 'db-push', '$0', '_'].includes(flagName)
) {
// filter out flags meant for the rw test command only
return []
} else {
// and forward on the other flags

However the same outcome happens for yarn rw test --load-env-files test.

As far as i understand it, the option assumes all space-separated input to be .env.*-files to load until the next option, which is why the following doesn't work either (Outcome 2):

$ yarn rw test --load-env-files test api

~/my-project/node_modules/@redwoodjs/cli/dist/lib/loadEnvFiles.js:85
      throw new Error(
            ^

Error: Couldn't find an .env file at '~/my-project/.env.api' as specified by '--load-env-files'

Current known workarounds

  • (set -a && source .env.test && set +a && yarn rw test api)
  • (export $(cat .env.test | xargs) && yarn rw test api) (will fail if .env.test contains # comments)

What's your environment? (If it applies)

System:
    OS: Linux 6.12 Manjaro Linux
    Shell: 5.2.37 - /bin/bash
  Binaries:
    Node: 20.16.0 - /tmp/xfs-2dc24661/node
    Yarn: 4.4.0 - /tmp/xfs-2dc24661/yarn
  Databases:
    SQLite: 3.47.2 - /usr/bin/sqlite3
  npmPackages:
    @redwoodjs/auth-azure-active-directory-setup: 8.4.2 => 8.4.2 
    @redwoodjs/cli-storybook-vite: 8.4.2 => 8.4.2 
    @redwoodjs/core: 8.4.2 => 8.4.2 
    @redwoodjs/project-config: 8.4.2 => 8.4.2

Are you interested in working on this?

  • I'm interested in working on this
@Philzen Philzen added the bug/needs-info More information is needed for reproduction label Jan 7, 2025
Philzen added a commit to Philzen/redwood that referenced this issue Jan 7, 2025
Not sure why this passed as 'loadEnvFiles' into the testHandler,
however this fixes the issue at hand – resolves redwoodjs#11884
Philzen added a commit to Philzen/redwood that referenced this issue Jan 7, 2025
Not sure why this passed as 'loadEnvFiles' into the testHandler,
however this fixes the issue at hand – resolves redwoodjs#11884
@Philzen Philzen linked a pull request Jan 7, 2025 that will close this issue
Philzen added a commit to Philzen/redwood that referenced this issue Jan 8, 2025
Not sure why this passed as 'loadEnvFiles' into the testHandler,
however this fixes the issue at hand – resolves redwoodjs#11884
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/needs-info More information is needed for reproduction
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant