Skip to content

Commit

Permalink
feat!(snapshot): don't escape quotes in snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Aug 15, 2023
1 parent 5a07cff commit 1e21bab
Show file tree
Hide file tree
Showing 20 changed files with 521 additions and 520 deletions.
2 changes: 1 addition & 1 deletion examples/basic/test/__snapshots__/suite.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`suite name > snapshot 1`] = `
{
Expand Down
2 changes: 1 addition & 1 deletion examples/mocks/test/error-mock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ vi.mock('../src/default', () => {

test('when using top level variable, gives helpful message', async () => {
await expect(() => import('../src/default').then(m => m.default)).rejects
.toThrowErrorMatchingInlineSnapshot('"[vitest] There was an error when mocking a module. If you are using \\"vi.mock\\" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. Read more: https://vitest.dev/api/vi.html#vi-mock"')
.toThrowErrorMatchingInlineSnapshot('"[vitest] There was an error when mocking a module. If you are using "vi.mock" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. Read more: https://vitest.dev/api/vi.html#vi-mock"')
})
2 changes: 1 addition & 1 deletion examples/react/test/__snapshots__/basic.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Link changes the class when hovered 1`] = `
<a
Expand Down
2 changes: 1 addition & 1 deletion examples/vitesse/test/__snapshots__/basic.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`mount component 1`] = `
<div
Expand Down
4 changes: 2 additions & 2 deletions examples/vue-jsx/test/__snapshots__/case.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`mount component 1`] = `"<a-select-stub value=\\"test\\"></a-select-stub>"`;
exports[`mount component 1`] = `"<a-select-stub value="test"></a-select-stub>"`;
2 changes: 1 addition & 1 deletion examples/vue2/test/__snapshots__/basic.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`mount component 1`] = `
"<div>
Expand Down
2 changes: 1 addition & 1 deletion examples/vue2/test/__snapshots__/script-setup.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`mount component 1`] = `
"<div>
Expand Down
1 change: 1 addition & 0 deletions packages/snapshot/src/port/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default class SnapshotState {
this.updated = 0
this._snapshotFormat = {
printBasicPrototype: false,
escapeString: false,
...options.snapshotFormat,
}
this._environment = options.snapshotEnvironment
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions test/core/test/__snapshots__/mocked.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`mocked function which fails on toReturnWith > just one call 1`] = `
"expected \\"spy\\" to return with: 2 at least once
"expected "spy" to return with: 2 at least once
Received:
Expand All @@ -16,7 +16,7 @@ Number of calls: 1
`;

exports[`mocked function which fails on toReturnWith > multi calls 1`] = `
"expected \\"spy\\" to return with: 2 at least once
"expected "spy" to return with: 2 at least once
Received:
Expand All @@ -41,29 +41,29 @@ Number of calls: 3
`;

exports[`mocked function which fails on toReturnWith > oject type 1`] = `
"expected \\"spy\\" to return with: { a: '4' } at least once
"expected "spy" to return with: { a: '4' } at least once
Received:
1st spy call return:
Object {
- \\"a\\": \\"4\\",
+ \\"a\\": \\"1\\",
- "a": "4",
+ "a": "1",
}
2nd spy call return:
Object {
- \\"a\\": \\"4\\",
+ \\"a\\": \\"1\\",
- "a": "4",
+ "a": "1",
}
3rd spy call return:
Object {
- \\"a\\": \\"4\\",
+ \\"a\\": \\"1\\",
- "a": "4",
+ "a": "1",
}
Expand All @@ -72,7 +72,7 @@ Number of calls: 3
`;

exports[`mocked function which fails on toReturnWith > zero call 1`] = `
"expected \\"spy\\" to return with: 2 at least once
"expected "spy" to return with: 2 at least once
Received:
Expand Down
6 changes: 3 additions & 3 deletions test/core/test/diff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ test('displays object diff', () => {
+ Received
Object {
\\"a\\": 1,
- \\"b\\": 2,
+ \\"b\\": 3,
"a": 1,
- "b": 2,
+ "b": 3,
}
"
`)
Expand Down
86 changes: 43 additions & 43 deletions test/core/test/injector-esm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,30 @@ test('namespace import', async () => {
test('export function declaration', async () => {
expect(injectSimpleCode('export function foo() {}'))
.toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
function foo() {}
Object.defineProperty(__vi_inject__, \\"foo\\", { enumerable: true, configurable: true, get(){ return foo }});
Object.defineProperty(__vi_inject__, "foo", { enumerable: true, configurable: true, get(){ return foo }});
export { __vi_inject__ }"
`)
})

test('export class declaration', async () => {
expect(await injectSimpleCode('export class foo {}'))
.toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
class foo {}
Object.defineProperty(__vi_inject__, \\"foo\\", { enumerable: true, configurable: true, get(){ return foo }});
Object.defineProperty(__vi_inject__, "foo", { enumerable: true, configurable: true, get(){ return foo }});
export { __vi_inject__ }"
`)
})

test('export var declaration', async () => {
expect(await injectSimpleCode('export const a = 1, b = 2'))
.toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
const a = 1, b = 2
Object.defineProperty(__vi_inject__, \\"a\\", { enumerable: true, configurable: true, get(){ return a }});
Object.defineProperty(__vi_inject__, \\"b\\", { enumerable: true, configurable: true, get(){ return b }});
Object.defineProperty(__vi_inject__, "a", { enumerable: true, configurable: true, get(){ return a }});
Object.defineProperty(__vi_inject__, "b", { enumerable: true, configurable: true, get(){ return b }});
export { __vi_inject__ }"
`)
})
Expand All @@ -77,10 +77,10 @@ test('export named', async () => {
expect(
injectSimpleCode('const a = 1, b = 2; export { a, b as c }'),
).toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
const a = 1, b = 2;
Object.defineProperty(__vi_inject__, \\"a\\", { enumerable: true, configurable: true, get(){ return a }});
Object.defineProperty(__vi_inject__, \\"c\\", { enumerable: true, configurable: true, get(){ return b }});
Object.defineProperty(__vi_inject__, "a", { enumerable: true, configurable: true, get(){ return a }});
Object.defineProperty(__vi_inject__, "c", { enumerable: true, configurable: true, get(){ return b }});
export { __vi_inject__ }"
`)
})
Expand All @@ -89,11 +89,11 @@ test('export named from', async () => {
expect(
injectSimpleCode('export { ref, computed as c } from \'vue\''),
).toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
const { __vi_inject__: __vi_esm_0__ } = await import(\\"vue\\");
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
const { __vi_inject__: __vi_esm_0__ } = await import("vue");
Object.defineProperty(__vi_inject__, \\"ref\\", { enumerable: true, configurable: true, get(){ return __vi_esm_0__.ref }});
Object.defineProperty(__vi_inject__, \\"c\\", { enumerable: true, configurable: true, get(){ return __vi_esm_0__.computed }});
Object.defineProperty(__vi_inject__, "ref", { enumerable: true, configurable: true, get(){ return __vi_esm_0__.ref }});
Object.defineProperty(__vi_inject__, "c", { enumerable: true, configurable: true, get(){ return __vi_esm_0__.computed }});
export { __vi_inject__ }"
`)
})
Expand All @@ -104,10 +104,10 @@ test('named exports of imported binding', async () => {
'import {createApp} from \'vue\';export {createApp}',
),
).toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
import { __vi_inject__ as __vi_esm_0__ } from 'vue'
Object.defineProperty(__vi_inject__, \\"createApp\\", { enumerable: true, configurable: true, get(){ return __vi_esm_0__.createApp }});
Object.defineProperty(__vi_inject__, "createApp", { enumerable: true, configurable: true, get(){ return __vi_esm_0__.createApp }});
export { __vi_inject__ }"
`)
})
Expand All @@ -118,10 +118,10 @@ test('export * from', async () => {
'export * from \'vue\'\n' + 'export * from \'react\'',
),
).toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
const { __vi_inject__: __vi_esm_0__ } = await import(\\"vue\\");
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
const { __vi_inject__: __vi_esm_0__ } = await import("vue");
__vi_export_all__(__vi_inject__, __vi_esm_0__);
const { __vi_inject__: __vi_esm_1__ } = await import(\\"react\\");
const { __vi_inject__: __vi_esm_1__ } = await import("react");
__vi_export_all__(__vi_inject__, __vi_esm_1__);
Expand All @@ -132,10 +132,10 @@ test('export * from', async () => {
test('export * as from', async () => {
expect(injectSimpleCode('export * as foo from \'vue\''))
.toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
const { __vi_inject__: __vi_esm_0__ } = await import(\\"vue\\");
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
const { __vi_inject__: __vi_esm_0__ } = await import("vue");
Object.defineProperty(__vi_inject__, \\"foo\\", { enumerable: true, configurable: true, get(){ return __vi_esm_0__ }});
Object.defineProperty(__vi_inject__, "foo", { enumerable: true, configurable: true, get(){ return __vi_esm_0__ }});
export { __vi_inject__ }"
`)
})
Expand All @@ -144,7 +144,7 @@ test('export default', async () => {
expect(
injectSimpleCode('export default {}'),
).toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
__vi_inject__.default = {}
export default { __vi_inject__: __vi_inject__.default };
Expand All @@ -158,9 +158,9 @@ test('export then import minified', async () => {
'export * from \'vue\';import {createApp} from \'vue\';',
),
).toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
import { __vi_inject__ as __vi_esm_0__ } from 'vue'
const { __vi_inject__: __vi_esm_1__ } = await import(\\"vue\\");
const { __vi_inject__: __vi_esm_1__ } = await import("vue");
__vi_export_all__(__vi_inject__, __vi_esm_1__);
export { __vi_inject__ }"
Expand Down Expand Up @@ -189,7 +189,7 @@ test('dynamic import', async () => {
'export const i = () => import(\'./foo\')',
)
expect(result).toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
const i = () => __vi_wrap_module__(import('./foo'))
export { __vi_inject__ }"
`)
Expand Down Expand Up @@ -301,13 +301,13 @@ test('should declare variable for imported super class', async () => {
+ 'export class B extends Foo {}',
),
).toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
import { __vi_inject__ as __vi_esm_0__ } from './dependency'
const Foo = __vi_esm_0__.Foo;
class A extends Foo {}
class B extends Foo {}
Object.defineProperty(__vi_inject__, \\"B\\", { enumerable: true, configurable: true, get(){ return B }});
Object.defineProperty(__vi_inject__, \\"default\\", { enumerable: true, configurable: true, value: A });
Object.defineProperty(__vi_inject__, "B", { enumerable: true, configurable: true, get(){ return B }});
Object.defineProperty(__vi_inject__, "default", { enumerable: true, configurable: true, value: A });
export { __vi_inject__ }"
`)
})
Expand All @@ -317,7 +317,7 @@ test('should handle default export variants', async () => {
// default anonymous functions
expect(injectSimpleCode('export default function() {}\n'))
.toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
__vi_inject__.default = function() {}
export default { __vi_inject__: __vi_inject__.default };
Expand All @@ -327,7 +327,7 @@ test('should handle default export variants', async () => {
// default anonymous class
expect(injectSimpleCode('export default class {}\n'))
.toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
__vi_inject__.default = class {}
export default { __vi_inject__: __vi_inject__.default };
Expand All @@ -341,10 +341,10 @@ test('should handle default export variants', async () => {
+ 'foo.prototype = Object.prototype;',
),
).toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
function foo() {}
foo.prototype = Object.prototype;
Object.defineProperty(__vi_inject__, \\"default\\", { enumerable: true, configurable: true, value: foo });
Object.defineProperty(__vi_inject__, "default", { enumerable: true, configurable: true, value: foo });
export { __vi_inject__ }"
`)
// default named classes
Expand All @@ -353,11 +353,11 @@ test('should handle default export variants', async () => {
'export default class A {}\n' + 'export class B extends A {}',
),
).toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
class A {}
class B extends A {}
Object.defineProperty(__vi_inject__, \\"B\\", { enumerable: true, configurable: true, get(){ return B }});
Object.defineProperty(__vi_inject__, \\"default\\", { enumerable: true, configurable: true, value: A });
Object.defineProperty(__vi_inject__, "B", { enumerable: true, configurable: true, get(){ return B }});
Object.defineProperty(__vi_inject__, "default", { enumerable: true, configurable: true, value: A });
export { __vi_inject__ }"
`)
})
Expand Down Expand Up @@ -718,13 +718,13 @@ export function fn1() {
`,
),
).toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
function fn1() {
}
Object.defineProperty(__vi_inject__, \\"fn1\\", { enumerable: true, configurable: true, get(){ return fn1 }});function fn2() {
Object.defineProperty(__vi_inject__, "fn1", { enumerable: true, configurable: true, get(){ return fn1 }});function fn2() {
}
Object.defineProperty(__vi_inject__, \\"fn2\\", { enumerable: true, configurable: true, get(){ return fn2 }});
Object.defineProperty(__vi_inject__, "fn2", { enumerable: true, configurable: true, get(){ return fn2 }});
export { __vi_inject__ }"
`)
Expand All @@ -743,7 +743,7 @@ export default (function getRandom() {
`.trim()

expect(injectSimpleCode(code)).toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
__vi_inject__.default = (function getRandom() {
return Math.random();
});
Expand All @@ -755,7 +755,7 @@ export default (function getRandom() {
expect(
injectSimpleCode('export default (class A {});'),
).toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
__vi_inject__.default = (class A {});
export default { __vi_inject__: __vi_inject__.default };
Expand Down Expand Up @@ -848,7 +848,7 @@ export class Test {
};`.trim()

expect(injectSimpleCode(code)).toMatchInlineSnapshot(`
"const __vi_inject__ = { [Symbol.toStringTag]: \\"Module\\" };
"const __vi_inject__ = { [Symbol.toStringTag]: "Module" };
import { __vi_inject__ as __vi_esm_0__ } from 'foobar'
if (false) {
Expand All @@ -875,7 +875,7 @@ export class Test {
}
}
}
Object.defineProperty(__vi_inject__, \\"Test\\", { enumerable: true, configurable: true, get(){ return Test }});;
Object.defineProperty(__vi_inject__, "Test", { enumerable: true, configurable: true, get(){ return Test }});;
export { __vi_inject__ }"
`)
})
Expand Down
Loading

0 comments on commit 1e21bab

Please sign in to comment.