Skip to content

Error: offset is longer than source length! is thrown when I try to update inline snapshot #626

@capaj

Description

@capaj

Describe the bug

node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

Error: offset is longer than source length! offset 947 > length 278
    at Object.numberToPos (/home/capaj/work-repos/mindmed/node-comparison/node_modules/vitest/dist/source-map-f7a4da05.js:3390:11)
    at prepareSnapString (/home/capaj/work-repos/mindmed/node-comparison/node_modules/vitest/dist/entry.js:700:44)
    at replaceObjectSnap (/home/capaj/work-repos/mindmed/node-comparison/node_modules/vitest/dist/entry.js:696:59)
    at replaceInlineSnap (/home/capaj/work-repos/mindmed/node-comparison/node_modules/vitest/dist/entry.js:715:12)
    at /home/capaj/work-repos/mindmed/node-comparison/node_modules/vitest/dist/entry.js:679:7
    at async Promise.all (index 0)
    at async saveInlineSnapshots (/home/capaj/work-repos/mindmed/node-comparison/node_modules/vitest/dist/entry.js:671:3)
    at async SnapshotState.save (/home/capaj/work-repos/mindmed/node-comparison/node_modules/vitest/dist/entry.js:839:9)
    at async packSnapshotState (/home/capaj/work-repos/mindmed/node-comparison/node_modules/vitest/dist/entry.js:1007:18)
    at async SnapshotClient.saveSnap (/home/capaj/work-repos/mindmed/node-comparison/node_modules/vitest/dist/entry.js:986:20)

Reproduction

I have this spec file

import { beforeAll, describe, expect, it } from 'vitest'
import { request } from 'undici'
import prismaClient from '../prisma/prismaClient'

describe('suite', () => {
  beforeAll(async () => {
    await prismaClient.questionnaire.deleteMany()
    await (
      await import('../server')
    ).listenPromise
  })

  describe('questionnares', () => {
    it('should GET', async () => {
      const res = await request('http://localhost:9090/questionnaires')

      expect(await res.body.json()).toMatchInlineSnapshot('[]')
    })

    it('should POST', async () => {
      const res = await request('http://localhost:9090/questionnaires', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          accept: 'application/json'
        },
        body: JSON.stringify({
          name: 'test',
          description: 'test',
          questionnaire: []
        })
      })

      expect(await res.body.json()).toMatchInlineSnapshot(
        {
          id: expect.any(Number)
        },
        `
          Object {
            "description": "test",
            "id": Any<Number>,
            "name": "test",
            "questionnaire": [],
          }
        `
      )
    })
  })
})

when I run the tests, I get this:

AssertionError: Snapshot `suite > questionnares > should POST 1` mismatched
 ❯ api/apiRoutes.spec.ts:34:36
     32|       })
     33| 
     34|       expect(await res.body.json()).toMatchInlineSnapshot(
       |                                    ^
     35|         {
     36|           id: expect.any(Number)

  - Expected  - 1
  + Received  + 1
  
  - Object {
  + {
      "description": "test",
      "id": Any<Number>,
      "name": "test",
      "questionnaire": [],

then I just hit u on the keyboard, error is thrown.

System Info

System:
    OS: Linux 5.13 Ubuntu 21.10 21.10 (Impish Indri)
    CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor
    Memory: 7.60 GB / 62.75 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
    Yarn: 1.22.17 - ~/.yarn/bin/yarn
    npm: 8.3.0 - ~/.nvm/versions/node/v16.13.1/bin/npm
  Browsers:
    Brave Browser: 97.1.34.80
    Chrome: 97.0.4692.99
    Firefox: 96.0
  npmPackages:
    vitest: ^0.2.1 => 0.2.1

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions