QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.84k stars 1.31k forks source link

[🐞] Vitest coverage error when importing manifest #5810

Closed alexismch closed 4 months ago

alexismch commented 9 months ago

Which component is affected?

Qwik Optimizer (rust)

Describe the bug

Hi!

When running Vitest with coverage on the Qwik project, the tests go well but once the coverage report is being processed, this error occurs.

TypeError: The "paths[0]" argument must be of type string. Received undefined
 ❯ new NodeError ../../../node:internal/errors:405:5
 ❯ validateString ../../../node:internal/validators:162:11
 ❯ Object.resolve ../../../node:path:1097:7
 ❯ Object.resolveId ../../../node_modules/@builder.io/qwik/optimizer.cjs:1934:39
 ❯ Context.resolveId ../../../node_modules/@builder.io/qwik/optimizer.cjs:3285:27
 ❯ Object.resolveId ../../../node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:63984:64
 ❯ TransformContext.resolve ../../../node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:63689:23
 ❯ normalizeUrl ../../../node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:62026:34
 ❯ ../../../async file:/Users/{user}/Documents/rosa/node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:62188:47
 ❯ TransformContext.transform ../../../node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:62109:13
 ❯ Object.transform ../../../node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:64060:30
 ❯ loadAndTransform ../../../node_modules/vite/dist/node/chunks/dep-V3BH7oO1.js:49741:29
 ❯ ViteNodeServer._transformRequest ../../../node_modules/vite-node/dist/server.mjs:393:16
 ❯ IstanbulCoverageProvider.getCoverageMapForUncoveredFiles ../../../node_modules/@vitest/coverage-istanbul/dist/provider.js:281:7
 ❯ IstanbulCoverageProvider.reportCoverage ../../../node_modules/@vitest/coverage-istanbul/dist/provider.js:228:33
 ❯ Vitest.reportCoverage ../../../node_modules/vitest/dist/vendor/node.wTZytysZ.js:8388:7
 ❯ Vitest.start ../../../node_modules/vitest/dist/vendor/node.wTZytysZ.js:8076:5
 ❯ startVitest ../../../node_modules/vitest/dist/vendor/node.wTZytysZ.js:15085:5
 ❯ start ../../../node_modules/vitest/dist/cli.js:143:17

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { code: 'ERR_INVALID_ARG_TYPE', plugin: 'vite:import-analysis', id: '/Users/{user}/Documents/rosa/apps/hospital/hospital-registry/src/entry.ssr.tsx', pluginCode: 'function cov_xnca7z5v3() {\n  var path = "/Users/{user}/Documents/rosa/apps/hospital/hospital-registry/src/entry.ssr.tsx";\n  var hash = "8c39ad3305651794032d118ce12187d966b5eb93";\n  var global = globalThis;\n  var gcv = "__VITEST_COVERAGE__";\n  var coverageData = {\n    path: "/Users/{user}/Documents/rosa/apps/hospital/hospital-registry/src/entry.ssr.tsx",\n    statementMap: {\n      "0": {\n        start: {\n          line: 19,\n          column: 28\n        },\n        end: {\n          line: 19,\n          column: 80\n        }\n      },\n      "1": {\n        start: {\n          line: 20,\n          column: 19\n        },\n        end: {\n          line: 24,\n          column: 56\n        }\n      },\n      "2": {\n        start: {\n          line: 25,\n          column: 4\n        },\n        end: {\n          line: 49,\n          column: 7\n        }\n      }\n    },\n    fnMap: {\n      "0": {\n        name: "(anonymous_0)",\n        decl: {\n          start: {\n            line: 18,\n            column: 15\n          },\n          end: {\n            line: 18,\n            column: 16\n          }\n        },\n        loc: {\n          start: {\n            line: 18,\n            column: 30\n          },\n          end: {\n            line: 50,\n            column: 1\n          }\n        },\n        line: 18\n      }\n    },\n    branchMap: {\n      "0": {\n        loc: {\n          start: {\n            line: 19,\n            column: 28\n          },\n          end: {\n            line: 19,\n            column: 80\n          }\n        },\n        type: "binary-expr",\n        locations: [{\n          start: {\n            line: 19,\n            column: 28\n          },\n          end: {\n            line: 19,\n            column: 72\n          }\n        }, {\n          start: {\n            line: 19,\n            column: 76\n          },\n          end: {\n            line: 19,\n            column: 80\n          }\n        }],\n        line: 19\n      },\n      "1": {\n        loc: {\n          start: {\n            line: 20,\n            column: 19\n          },\n          end: {\n            line: 24,\n            column: 56\n          }\n        },\n        type: "cond-expr",\n        locations: [{\n          start: {\n            line: 24,\n            column: 34\n          },\n          end: {\n            line: 24,\n            column: 49\n          }\n        }, {\n          start: {\n            line: 24,\n            column: 52\n          },\n          end: {\n            line: 24,\n            column: 56\n          }\n        }],\n        line: 20\n      },\n      "2": {\n        loc: {\n          start: {\n            line: 47,\n            column: 18\n          },\n          end: {\n            line: 47,\n            column: 70\n          }\n        },\n        type: "binary-expr",\n        locations: [{\n          start: {\n            line: 47,\n            column: 18\n          },\n          end: {\n            line: 47,\n            column: 62\n          }\n        }, {\n          start: {\n            line: 47,\n            column: 66\n          },\n          end: {\n            line: 47,\n            column: 70\n          }\n        }],\n        line: 47\n      }\n    },\n    s: {\n      "0": 0,\n      "1": 0,\n      "2": 0\n    },\n    f: {\n      "0": 0\n    },\n    b: {\n      "0": [0, 0],\n      "1": [0, 0],\n      "2": [0, 0]\n    },\n    inputSourceMap: {\n      version: 3,\n      sources: ["src/entry.ssr.tsx"],\n      sourceRoot: "/Users/{user}/Documents/rosa/apps/hospital/hospital-registry",\n      names: [],\n      mappings: "AAAA;;;;;;;;;;;CAWC;AACD,SAAS,cAAc,QAA+B,0BAA0B;AAChF,SAAS,QAAQ,QAAQ,wBAAwB;AAEjD,SAAS,WAAW,QAAQ,uCAAuC;AACnE,SAAS,cAAc,EAAE,aAAa,QAAQ,yBAAyB;AAEvE,OAAO,UAAU,SAAS;AAE1B,eAAe,SAAU,IAA2B,EAAE;IACpD,MAAM,kBAAkB,MAAM,YAAY,UAAU,QAAQ,YAAY;IACxE,MAAM,SAAS;QAAC;QAAM;QAAM;KAAK,CAAC,QAAQ,CAAC,mBAAmB,kBAAkB,IAAI;IAEpF,OAAO,6BAAe,MAAC;;;;QAAS;QAC9B;QACA,GAAG,IAAI;QACP,YAAY;YACV,GAAG,KAAK,UAAU;YAClB;YACA,CAAC,cAAc,EAAE;QACnB;QACA,MAAM;QACN,kBAAkB;YAChB,gBAAgB;gBACd,YAAY,IAAI;gBAChB,mBAAmB,IAAI;gBACvB,eAAe;YACjB;QACF;QACA,qBAAqB;YACnB,GAAG,KAAK,mBAAmB;YAC3B,MAAM,MAAM,YAAY,UAAU,QAAQ,YAAY;QACxD;IACF;AACF,CAAC"\n    },\n    _coverageSchema: "1a1c01bbd47fc00a2c39e90264f33305004495a9",\n    hash: "8c39ad3305651794032d118ce12187d966b5eb93"\n  };\n  var coverage = global[gcv] || (global[gcv] = {});\n  if (!coverage[path] || coverage[path].hash !== hash) {\n    coverage[path] = coverageData;\n  }\n  var actualCoverage = coverage[path];\n  {\n    // @ts-ignore\n    cov_xnca7z5v3 = function () {\n      return actualCoverage;\n    };\n  }\n  return actualCoverage;\n}\ncov_xnca7z5v3();\n/**\n * WHAT IS THIS FILE?\n *\n * SSR entry point, in all cases the application is render outside the browser, this\n * entry point will be the common one.\n *\n * - Server (express, cloudflare...)\n * - npm run start\n * - npm run preview\n * - npm run build\n *\n */\nimport { _jsxC } from "@builder.io/qwik";\nimport { renderToStream } from \'@builder.io/qwik/server\';\nimport { manifest } from \'@qwik-client-manifest\';\nimport { extractBase } from \'@rosa/shared-qwik/util/util-language\';\nimport { getRosaEnvData, ROSA_ENV_DATA } from \'@rosa/shared-util-qwik\';\nimport Root from \'./root\';\nexport default function (opts) {\n  cov_xnca7z5v3().f[0]++;\n  const languageFromUrl = (cov_xnca7z5v3().s[0]++, (cov_xnca7z5v3().b[0][0]++, opts?.serverData?.qwikcity?.params?.language) ?? (cov_xnca7z5v3().b[0][1]++, \'en\'));\n  const locale = (cov_xnca7z5v3().s[1]++, [\'fr\', \'nl\', \'en\'].includes(languageFromUrl) ? (cov_xnca7z5v3().b[1][0]++, languageFromUrl) : (cov_xnca7z5v3().b[1][1]++, \'en\'));\n  cov_xnca7z5v3().s[2]++;\n  return renderToStream( /*#__PURE__*/_jsxC(Root, null, 3, "QQ_0", {\n    fileName: "entry.ssr.tsx",\n    lineNumber: 25,\n    columnNumber: 25\n  }), {\n    manifest,\n    ...opts,\n    serverData: {\n      ...opts.serverData,\n      locale,\n      [ROSA_ENV_DATA]: getRosaEnvData()\n    },\n    base: extractBase,\n    prefetchStrategy: {\n      implementation: {\n        linkInsert: null,\n        workerFetchInsert: null,\n        prefetchEvent: \'always\'\n      }\n    },\n    containerAttributes: {\n      ...opts.containerAttributes,\n      lang: (cov_xnca7z5v3().b[2][0]++, opts?.serverData?.qwikcity?.params?.language) ?? (cov_xnca7z5v3().b[2][1]++, \'en\')\n    }\n  });\n}' }

Further investigations lead to the assumption that this is due to the import & use of manifest from '@qwik-client-manifest' (once the usage commented, the coverage reporting runs well).

One idea about the reason : the way the the optimizer is imported but not sure at all :

const manifest: import('./optimizer').QwikManifest;

Reproduction

https://github.com/search?q=repo%3ABuilderIO%2Fqwik+QwikManifest&type=code&p=1

Steps to reproduce

No response

System Info

System:
    OS: macOS 14.3
    CPU: (12) arm64 Apple M3 Pro
    Memory: 5.73 GB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.18.2 - ~/.nvm/versions/node/v18.18.2/bin/node
    Yarn: 1.22.21 - ~/Documents/rosa/node_modules/.bin/yarn
    npm: 10.2.3 - ~/Documents/rosa/node_modules/.bin/npm
    pnpm: 8.14.3 - ~/.nvm/versions/node/v18.18.2/bin/pnpm
  Browsers:
    Chrome: 121.0.6167.85
    Safari: 17.3
  npmPackages:
    @builder.io/angular: 3.0.1 => 3.0.1 
    @builder.io/qwik: 1.3.2 => 1.3.2 
    @builder.io/qwik-city: 1.3.2 => 1.3.2 
    @builder.io/qwik-labs: github:BuilderIo/qwik-labs-build#36582dc0503bf665daff9686d2a27d742145795d => 0.0.1 
    @builder.io/sdk-qwik: 0.7.1-0 => 0.7.1-0 
    vite: 5.0.11 => 5.0.11

Additional Information

No response

JerryWu1234 commented 8 months ago

https://github.com/search?q=repo%3ABuilderIO%2Fqwik+QwikManifest&type=code&p=1 this is not a minimal replicated repository. Could you offer a replicated ?

github-actions[bot] commented 5 months ago

Hello @alexismch. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with STATUS-2: needs reproduction will be automatically closed if they have no activity within 14 days. Thanks πŸ™

maiieul commented 2 months ago

@alexismch const manifest: import('./optimizer').QwikManifest; seems to have been removed for V2. Hopefully this will be fixed in V2.