Skip to content

Incorrect path resolve when other VS Code extensions run firebase related command #7471

@jin-qin

Description

@jin-qin

[REQUIRED] Environment info

firebase-tools: 13.13.3

Platform: macOS Sonoma 14.5

[REQUIRED] Test case

Use Orta.vscode-jest extension, configure firebase emulators:exec "jest" as its command, run jest unit test.

[REQUIRED] Steps to reproduce

  1. Install Orta.vscode-jest extension through VS Code extension marketplace.
  2. Create a bash file say test.sh, and put the following content into it:
    #!/bin/bash
    
    PARAMS="$@"
    yarn firebase emulators:exec "jest ${PARAMS}"
    
  3. In VS Code settings.json, add "jest.jestCommandLine": "./test.sh" or put ./test.sh into Jest: Jest Command Line in Jest extension settings.
  4. Configure a jest unit test
  5. Run jest unit test through CodeLens (i.e. clicking the run test button in the unit test file)

[REQUIRED] Expected behavior

Unit test is passed.

[REQUIRED] Actual behavior

Received error, test aborted:

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

Workaround

In fact, if I remove the following extension check insrc/templates.ts:

if (isVSCodeExtension()) {
    // In the VSCE, the /templates directory is copied into dist, which makes it
    // right next to the compiled files (from various sources including this
    // TS file). See CopyPlugin in `../firebase-vscode/webpack.common.js`.
    return resolve(__dirname, "templates", relPath);
}

the issue will be suppressed and the unit test is passed.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions