jest-community / vscode-jest

The optimal flow for Jest based testing in VS Code
MIT License
2.84k stars 295 forks source link

[FEATURE] Support ability to interpolate extension arguments in `jest.jestCommandLine` instead of appending #1156

Closed djohnson-aperture closed 3 months ago

djohnson-aperture commented 5 months ago

Is your feature request related to a problem? Please describe. It would be convenient to offer a way to specify a spot within the test command to indicate where the extension args should be placed. I have a weird case where my jest command is actually provided to another command, but appending the arguments to the end fails to put the in the right context. Example Command: npx firebase emulators:exec 'jest'

Unfortunate Extension Command: npx firebase emulators:exec 'jest' --testNamePattern StudentPortalService --testPathPattern /Users/user/.../src/example\.spec\.ts

Describe the solution you'd like Detect a $JEST_EXTENSION_ARGS variable in the configured jest.jestCommandLine. If present, expand the arguments in its place. Otherwise, append arguments to end, as they're done now.

In my example, I would set jest.jestCommandLine to: npx firebase emulators:exec 'jest $JEST_EXTENSION_ARGS' which would expand to: npx firebase emulators:exec 'jest --testNamePattern StudentPortalService --testPathPattern /Users/user/.../src/example\.spec\.ts' and properly pass the args to the secondary command. To be clear, note that the arguments are now within the single quoted jest command, instead of trailing it.

Describe alternatives you've considered I've tried to find a solution using npm script variables, but there doesn't seem to be one that equates to "all trailing arguments".

connectdotz commented 5 months ago

hmmm... will a shell-script like the following work? Let's call this my-jest.sh:

# !/bin/sh
npx firebase emulators:exec 'jest $@'

then set "jest.jestCommandLine": ./my-jest.sh

jin-qin commented 4 months ago

@connectdotz I tried but still not working, error like below:

TestRun "my-app:runTest: orta.vscode-jest:TestProvider:my-app:32 (0)" started
node:fs:448
    return binding.readFileUtf8(path, stringToFlags(options.flag));
                   ^

Error: ENOENT: no such file or directory, open '/Users/user/Projects/my-app/node_modules/firebase-tools/lib/templates/hosting/init.js'
    at readFileSync (node:fs:448:20)
    at readTemplateSync (/Users/user/Projects/my-app/node_modules/firebase-tools/lib/templates.js:17:34)
    at Object.<anonymous> (/Users/user/Projects/my-app/node_modules/firebase-tools/lib/hosting/implicitInit.js:12:56)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/Users/user/Projects/my-app/node_modules/firebase-tools/lib/frameworks/index.js:25:24) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Users/user/Projects/my-app/node_modules/firebase-tools/lib/templates/hosting/init.js'
}

Node.js v20.14.0
jin-qin commented 4 months ago

I think this is an issue related to firebase-tools, they have conditional check for VS Code extensions here which makes the path wrong, it should be firebase-tools/templates/hosting/init.js instead of firebase-tools/lib/templates/hosting/init.js

Raised https://github.com/firebase/firebase-tools/issues/7471

georgecartridge commented 4 months ago

I think this is an issue related to firebase-tools, they have conditional check for VS Code extensions here which makes the path wrong, it should be firebase-tools/templates/hosting/init.js instead of firebase-tools/lib/templates/hosting/init.js

Raised firebase/firebase-tools#7471

Also seeing this. Is there any workaround in the meantime?

connectdotz commented 3 months ago

looks like filebase has provided a workaround: see comment

I will close this issue as it should be addressed on the firebase side.