Skip to content

One unit test fails with pnpm, works with npm #7368

Closed
@rmunn

Description

@rmunn

Describe the bug

The test/sourcemaps/samples/compile-option-dev/test.js unit test somehow produces different results when you've installed Svelte dependencies with pnpm vs with npm. Since I prefer to use pnpm (which can deduplicate packages across node_modules folders from multiple projects, saving a lot of disk space), this means that every time I want to create a Svelte PR, I have to edit that test file and change the expected values in it, then make sure those edits don't make it into my PR.

Reproduction

  1. Rename test/sourcemaps/samples/compile-option-dev/ to test/sourcemaps/samples/compile-option-dev.solo/ to run only this test. (This doesn't change the results, just the speed of running the tests)
  2. Run npm i, then npm run test.
  3. Test passes.
  4. Run pnpm import to convert package-lock.json to a pnpm-lock.yaml file with the same package version numbers in it.
  5. Run rm -rf node_modules, then pnpm i to ensure that PNPM is the one that has created the node_modules folder
  6. Run pnpm run test (or npm run test, both will produce the same result)
  7. Test fails: see below.

The test failure is caused by the column numbers produced by SourceMapConsumer.originalPositionFor from the source-map package. When that package is installed via npm, the two column numbers checked for in that test are 5. When the package is installed via pnpm, the two column numbers are 4 instead of 5. (The logs only show one test failure, on the --done-replace-once check, but if you edit its column number to expect 4, the --done-replace-twice check will also fail with actual=4 and expected=5). Logs from a failed test run (running pnpm run test) are below.

Logs

sourcemaps
    1) compile-option-dev.solo


  0 passing (66ms)
  1 failing

  1) sourcemaps
       compile-option-dev.solo:

      AssertionError [ERR_ASSERTION]: failed to locate "--done-replace-once" from "input.svelte"
      + expected - actual

       {
      -  "column": 4
      +  "column": 5
         "line": 6
         "name": [null]
         "source": "input.svelte"
       }
      
      at /.../svelte/test/sourcemaps/samples/compile-option-dev.solo/test.js:27:10
      at Array.forEach (<anonymous>)
      at test (test/sourcemaps/samples/compile-option-dev.solo/test.js:26:3)
      at Context.<anonymous> (test/sourcemaps/index.ts:117:4)



 ELIFECYCLE  Test failed. See above for more details.

System Info

System:
    OS: Linux 5.4 Linux Mint 19.1 (Tessa)
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 8.33 GB / 62.58 GB
    Container: Yes
    Shell: 4.4.20 - /bin/bash
  Binaries:
    Node: 16.14.0 - /usr/local/bin/node
    Yarn: 1.22.17 - /usr/bin/yarn
    npm: 7.23.0 - ~/.local/bin/npm
  Browsers:
    Chrome: 74.0.3729.169
    Firefox: 96.0.3
  npmPackages:
    rollup: ^1.27.14 => 1.32.1

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions