[vitest-plugin] `toMatchInlineSnapshot` updates are written into a later test's snapshot (source positions not mapped in workerd)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 30/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- node.js, typescript, wasm
- Lĩnh vực
- testing-qa, tooling
Hướng nghiên cứu
Start from the vitest-plugin integration that services loopback snapshot requests and compare its positions with Vitest's saveInlineSnapshots/replaceInlineSnap path. Reproduce with the provided wrangler.jsonc, vitest.config.ts and test/repro.test.ts, then run npx vitest run -u and inspect the reported line/column against the source. Done means stack-trace positions inside workerd are mapped through source maps so the intended inline snapshot is rewritten and failure frames point at the source.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What versions & operating system are you using?
@cloudflare/vitest-plugin1.9.2vitest5.1.1wrangler4.168.0- Node 22.23, Linux x64
Please provide a link to a minimal reproduction
See below
Describe the Bug
What happened?
Running vitest run -u on a test file in the Workers project, where one inline snapshot is out of date:
- Vitest reports
Snapshots 1 updated, and every test passes. - The new value is written into the
toMatchInlineSnapshot(...)call of a later, unrelated test in the same file. The outdated snapshot is left as it was. - If no inline snapshot follows the outdated one, nothing is written at all, and the next run fails again.
- A new, empty
toMatchInlineSnapshot()is reported aswritten, but it is never written.
Failure frames are also misplaced: the line is wrong whenever the file has imports, and the column is always wrong.
The same test files run in a plain Node Vitest project behave correctly. File snapshots (toMatchSnapshot, toMatchFileSnapshot) work correctly in the Workers project.
Cause, as far as I can tell
I logged the loopback snapshot requests and Vitest's saveInlineSnapshots. The line and column Vitest receives for each inline snapshot are positions in the transformed module, not the source. For example, calls on lines 15 and 20 of the source were reported at lines 28 and 36. So source maps don't seem to be applied to stack traces inside workerd. replaceInlineSnap then searches forward from that offset and rewrites the first toMatchInlineSnapshot( it finds after it.
Reproduction
wrangler.jsonc:
{ "name": "repro", "main": "src/index.ts", "compatibility_date": "2026-11-01" }
src/index.ts:
export default {
async fetch(): Promise<Response> {
return new Response('ok', { headers: { 'cache-control': 'no-store' } });
},
};
vitest.config.ts:
import { defineConfig } from 'vitest/config';
import { cloudflareTest } from '@cloudflare/vitest-plugin';
export default defineConfig({ plugins: [cloudflareTest({ wrangler: { configPath: './wrangler.jsonc' } })] });
test/repro.test.ts:
import { SELF } from 'cloudflare:test';
import { expect, it } from 'vitest';
it('the expectation that should change', async () => {
const res = await SELF.fetch('https://example.com/');
expect(res.headers.get('cache-control')).toMatchInlineSnapshot(`"stale value"`);
});
it('padding 1', () => {});
it('padding 2', () => {});
it('padding 3', () => {});
it('padding 4', () => {});
it('padding 5', () => {});
it('an unrelated expectation', () => {
expect('untouched').toMatchInlineSnapshot(`"untouched"`);
});
Then (package.json has "type": "module"):
npx vitest run -u
Expected: the first test's snapshot becomes "no-store".
Actual: the output says Snapshots 1 updated, and all tests pass. The first test still says "stale value", and the last test now reads toMatchInlineSnapshot("no-store").
Related
#7288 reported wrong inline snapshot positions on Windows with vitest-pool-workers. It was closed by #11632 in March 2026. This report is on Linux with @cloudflare/vitest-plugin.
Please provide any relevant error logs
No response
- Ngôn ngữ chính
- TypeScript
- Star
- 4.7k
- Fork
- 1.7k
- Merge trung bình
- 1 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 282
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của cloudflare/workers-sdk
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
cloudflare/workers-sdk#17215 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
cloudflare/workers-sdk#17189 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
cloudflare/workers-sdk#17187 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
cloudflare/workers-sdk#17175 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
cloudflare/workers-sdk#17174 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của cloudflare/workers-sdk
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
earendil-works/pi#12615 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
My Caps shows "Shared" on private Caps that were never sharedCó thể đã có người làm @AksharP5 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
CapSoftware/Cap#4569 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
OHDSI/Data2Evidence#3749 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
PWA: Unique Page TitlesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Flagsmith/flagsmith-nodejs-client#332 ·
Maintainer thường phản hồi trong vòng 2 ngày