Inline snapshots are re-indented whenever another inline snapshot in the same file is saved/updated.
Worked up to version: 24.5
Stopped working in version: 24.6
Steps to reproduce the behavior:
Given this test file and we're running in watch mode:
describe('broken', () => {
test('1', () => {
expect(11111).toMatchInlineSnapshot();
});
test('2', () => {
expect([[1]]).toMatchInlineSnapshot();
});
});
Upon save, both snapshots are written:
describe('broken', () => {
test('1', () => {
expect(11111).toMatchInlineSnapshot(`11111`);
});
test('2', () => {
expect([[1]]).toMatchInlineSnapshot(`
Array [
Array [
1,
],
]
`);
});
});
Now I update the first test (expect(10000).toMatchInlineSnapshot()
) and save. The snapshots get rewritten:
describe('broken', () => {
test('1', () => {
expect(10000).toMatchInlineSnapshot(`10000`);
});
test('2', () => {
expect([[1]]).toMatchInlineSnapshot(`
Array [
Array [
1,
],
]
`);
});
});
Now I add another test (expect(3).toMatchInlineSnapshot()
) and save:
describe('broken', () => {
test('1', () => {
expect(10000).toMatchInlineSnapshot(`10000`);
});
test('2', () => {
expect([[1]]).toMatchInlineSnapshot(`
Array [
Array [
1,
],
]
`);
});
test('3', () => {
expect(3).toMatchInlineSnapshot(`3`);
});
});
Notice how the snapshot for test 2
slowly drifts to the right. This can get super annoying after many test-update-save cycles.
Inline snapshots should stay put.
Repl.it only has Jest 22.1.2. I didn't find a way to upgrade it.
npx envinfo --preset jest
Paste the results here:
System:
OS: macOS Mojave 10.14.4
CPU: (4) x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
Binaries:
Node: 10.15.0 - ~/.nvm/versions/node/v10.15.0/bin/node
Yarn: 1.15.2 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.15.0/bin/npm
npmPackages:
jest: ^24.6.0 => 24.7.1
Thanks for the report. I'll take a look at it very soon. Do you know if it happens outside of watch mode?
Yep, just tested and confirmed same thing happens with jest -u
.
I recommend removing the snapshot and regenerating it - that should stop the diff. Still a bug, of course, but should fix your issue 馃檪
@SimenB that's what I ended up doing.
I have a video
Is there a way to tell yarn generate everything from scratch?
FYI I see this happen with [email protected] as well. [email protected] also has the same bug. I'm not sure that it's a recent regression.
I also wonder if it could be somewhat linked to Prettier and its integration into Visual Studio Code on save (could there be a race condition?).
Not related to VSCode, I don't use it but still see this happen frequently using latest Jest. Didn't have time to investigate yet though :/
It may be regression introduced by this: https://github.com/facebook/jest/pull/8198
Yeah definitely
@petternordhold,
Until your pr get merged, you can downgrade jest-snapshots using yarn resolutions to 24.5
Any chance to see the fix released before jest 25?
@Bnaya yes, we haven't landed breaking changes yet, there will we another minor before 25
(Seems this fix was released in jest 24.0.18?)
24.9.0 has it 馃檪
Most helpful comment
24.9.0 has it 馃檪