Skip to content

Commit 8867bb2

Browse files
committed
wip(vitest-migration): reactivity tests passing
1 parent ab45f6f commit 8867bb2

File tree

83 files changed

+1122
-545
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1122
-545
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"tslib": "^2.4.0",
103103
"typescript": "^4.8.0",
104104
"vite": "^4.0.4",
105+
"vitest": "^0.28.2",
105106
"vue": "workspace:*"
106107
}
107108
}

packages/compiler-core/__tests__/parse.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { vi } from 'vitest'
12
import { ParserOptions } from '../src/options'
23
import { baseParse, TextModes } from '../src/parse'
34
import { ErrorCodes } from '../src/errors'
@@ -31,7 +32,7 @@ describe('compiler: parse', () => {
3132
})
3233

3334
test('simple text with invalid end tag', () => {
34-
const onError = jest.fn()
35+
const onError = vi.fn()
3536
const ast = baseParse('some text</div>', {
3637
onError
3738
})
@@ -1844,7 +1845,7 @@ describe('compiler: parse', () => {
18441845
baseParse(`<div>\n<span>\n</div>\n</span>`)
18451846
}).toThrow('Element is missing end tag.')
18461847

1847-
const spy = jest.fn()
1848+
const spy = vi.fn()
18481849
const ast = baseParse(`<div>\n<span>\n</div>\n</span>`, {
18491850
onError: spy
18501851
})
@@ -3034,7 +3035,7 @@ foo
30343035
c => `\\x0${c.codePointAt(0)!.toString(16)};`
30353036
),
30363037
() => {
3037-
const spy = jest.fn()
3038+
const spy = vi.fn()
30383039
const ast = baseParse(code, {
30393040
getNamespace: (tag, parent) => {
30403041
const ns = parent ? parent.ns : Namespaces.HTML

packages/compiler-core/__tests__/transform.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { vi } from 'vitest'
12
import { baseParse } from '../src/parse'
23
import { transform, NodeTransform } from '../src/transform'
34
import {
@@ -88,7 +89,7 @@ describe('compiler: transform', () => {
8889
)
8990
}
9091
}
91-
const spy = jest.fn(plugin)
92+
const spy = vi.fn(plugin)
9293
transform(ast, {
9394
nodeTransforms: [spy]
9495
})
@@ -113,7 +114,7 @@ describe('compiler: transform', () => {
113114
context.removeNode()
114115
}
115116
}
116-
const spy = jest.fn(plugin)
117+
const spy = vi.fn(plugin)
117118
transform(ast, {
118119
nodeTransforms: [spy]
119120
})
@@ -141,7 +142,7 @@ describe('compiler: transform', () => {
141142
context.removeNode(context.parent!.children[0])
142143
}
143144
}
144-
const spy = jest.fn(plugin)
145+
const spy = vi.fn(plugin)
145146
transform(ast, {
146147
nodeTransforms: [spy]
147148
})
@@ -168,7 +169,7 @@ describe('compiler: transform', () => {
168169
context.removeNode(context.parent!.children[1])
169170
}
170171
}
171-
const spy = jest.fn(plugin)
172+
const spy = vi.fn(plugin)
172173
transform(ast, {
173174
nodeTransforms: [spy]
174175
})
@@ -209,7 +210,7 @@ describe('compiler: transform', () => {
209210
createCompilerError(ErrorCodes.X_INVALID_END_TAG, node.loc)
210211
)
211212
}
212-
const spy = jest.fn()
213+
const spy = vi.fn()
213214
transform(ast, {
214215
nodeTransforms: [plugin],
215216
onError: spy

packages/compiler-core/__tests__/transforms/transformElement.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { vi } from 'vitest'
12
import {
23
CompilerOptions,
34
baseParse as parse,
@@ -531,7 +532,7 @@ describe('compiler: element transform', () => {
531532
})
532533

533534
test('error on v-bind with no argument', () => {
534-
const onError = jest.fn()
535+
const onError = vi.fn()
535536
parseWithElementTransform(`<div v-bind/>`, { onError })
536537
expect(onError.mock.calls[0]).toMatchObject([
537538
{

packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { vi } from 'vitest'
12
import {
23
baseParse as parse,
34
transform,
@@ -395,7 +396,7 @@ describe('compiler: expression transform', () => {
395396
})
396397

397398
test('should handle parse error', () => {
398-
const onError = jest.fn()
399+
const onError = vi.fn()
399400
parseWithExpressionTransform(`{{ a( }}`, { onError })
400401
expect(onError.mock.calls[0][0].message).toMatch(
401402
`Error parsing JavaScript expression: Unexpected token`

packages/compiler-core/__tests__/transforms/transformSlotOutlet.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { vi } from 'vitest'
12
import {
23
CompilerOptions,
34
baseParse as parse,
@@ -369,7 +370,7 @@ describe('compiler: transform <slot> outlets', () => {
369370
})
370371

371372
test(`error on unexpected custom directive on <slot>`, () => {
372-
const onError = jest.fn()
373+
const onError = vi.fn()
373374
const source = `<slot v-foo />`
374375
parseWithSlots(source, { onError })
375376
const index = source.indexOf('v-foo')

packages/compiler-core/__tests__/transforms/vBind.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { vi } from 'vitest'
12
import {
23
baseParse as parse,
34
transform,
@@ -99,7 +100,7 @@ describe('compiler: transform v-bind', () => {
99100
})
100101

101102
test('should error if no expression', () => {
102-
const onError = jest.fn()
103+
const onError = vi.fn()
103104
const node = parseWithVBind(`<div v-bind:arg />`, { onError })
104105
const props = (node.codegenNode as VNodeCall).props as ObjectExpression
105106
expect(onError.mock.calls[0][0]).toMatchObject({

packages/compiler-core/__tests__/transforms/vFor.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { vi } from 'vitest'
12
import { baseParse as parse } from '../../src/parse'
23
import { transform } from '../../src/transform'
34
import { transformIf } from '../../src/transforms/vIf'
@@ -206,7 +207,7 @@ describe('compiler: v-for', () => {
206207

207208
describe('errors', () => {
208209
test('missing expression', () => {
209-
const onError = jest.fn()
210+
const onError = vi.fn()
210211
parseWithForTransform('<span v-for />', { onError })
211212

212213
expect(onError).toHaveBeenCalledTimes(1)
@@ -218,7 +219,7 @@ describe('compiler: v-for', () => {
218219
})
219220

220221
test('empty expression', () => {
221-
const onError = jest.fn()
222+
const onError = vi.fn()
222223
parseWithForTransform('<span v-for="" />', { onError })
223224

224225
expect(onError).toHaveBeenCalledTimes(1)
@@ -230,7 +231,7 @@ describe('compiler: v-for', () => {
230231
})
231232

232233
test('invalid expression', () => {
233-
const onError = jest.fn()
234+
const onError = vi.fn()
234235
parseWithForTransform('<span v-for="items" />', { onError })
235236

236237
expect(onError).toHaveBeenCalledTimes(1)
@@ -242,7 +243,7 @@ describe('compiler: v-for', () => {
242243
})
243244

244245
test('missing source', () => {
245-
const onError = jest.fn()
246+
const onError = vi.fn()
246247
parseWithForTransform('<span v-for="item in" />', { onError })
247248

248249
expect(onError).toHaveBeenCalledTimes(1)
@@ -254,7 +255,7 @@ describe('compiler: v-for', () => {
254255
})
255256

256257
test('missing value', () => {
257-
const onError = jest.fn()
258+
const onError = vi.fn()
258259
parseWithForTransform('<span v-for="in items" />', { onError })
259260

260261
expect(onError).toHaveBeenCalledTimes(1)
@@ -266,7 +267,7 @@ describe('compiler: v-for', () => {
266267
})
267268

268269
test('<template v-for> key placement', () => {
269-
const onError = jest.fn()
270+
const onError = vi.fn()
270271
parseWithForTransform(
271272
`
272273
<template v-for="item in items">

packages/compiler-core/__tests__/transforms/vIf.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { vi } from 'vitest'
12
import { baseParse as parse } from '../../src/parse'
23
import { transform } from '../../src/transform'
34
import { transformIf } from '../../src/transforms/vIf'
@@ -213,7 +214,7 @@ describe('compiler: v-if', () => {
213214

214215
describe('errors', () => {
215216
test('error on v-else missing adjacent v-if', () => {
216-
const onError = jest.fn()
217+
const onError = vi.fn()
217218

218219
const { node: node1 } = parseWithIfTransform(`<div v-else/>`, { onError })
219220
expect(onError.mock.calls[0]).toMatchObject([
@@ -249,7 +250,7 @@ describe('compiler: v-if', () => {
249250
})
250251

251252
test('error on v-else-if missing adjacent v-if or v-else-if', () => {
252-
const onError = jest.fn()
253+
const onError = vi.fn()
253254

254255
const { node: node1 } = parseWithIfTransform(`<div v-else-if="foo"/>`, {
255256
onError
@@ -302,7 +303,7 @@ describe('compiler: v-if', () => {
302303
})
303304

304305
test('error on user key', () => {
305-
const onError = jest.fn()
306+
const onError = vi.fn()
306307
// dynamic
307308
parseWithIfTransform(
308309
`<div v-if="ok" :key="a + 1" /><div v-else :key="a + 1" />`,

packages/compiler-core/__tests__/transforms/vModel.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { vi } from 'vitest'
12
import {
23
baseParse as parse,
34
transform,
@@ -506,7 +507,7 @@ describe('compiler: transform v-model', () => {
506507

507508
describe('errors', () => {
508509
test('missing expression', () => {
509-
const onError = jest.fn()
510+
const onError = vi.fn()
510511
parseWithVModel('<span v-model />', { onError })
511512

512513
expect(onError).toHaveBeenCalledTimes(1)
@@ -518,7 +519,7 @@ describe('compiler: transform v-model', () => {
518519
})
519520

520521
test('empty expression', () => {
521-
const onError = jest.fn()
522+
const onError = vi.fn()
522523
parseWithVModel('<span v-model="" />', { onError })
523524

524525
expect(onError).toHaveBeenCalledTimes(1)
@@ -530,7 +531,7 @@ describe('compiler: transform v-model', () => {
530531
})
531532

532533
test('mal-formed expression', () => {
533-
const onError = jest.fn()
534+
const onError = vi.fn()
534535
parseWithVModel('<span v-model="a + b" />', { onError })
535536

536537
expect(onError).toHaveBeenCalledTimes(1)
@@ -542,14 +543,14 @@ describe('compiler: transform v-model', () => {
542543
})
543544

544545
test('allow unicode', () => {
545-
const onError = jest.fn()
546+
const onError = vi.fn()
546547
parseWithVModel('<span v-model="变.量" />', { onError })
547548

548549
expect(onError).toHaveBeenCalledTimes(0)
549550
})
550551

551552
test('used on scope variable', () => {
552-
const onError = jest.fn()
553+
const onError = vi.fn()
553554
parseWithVModel('<span v-for="i in list" v-model="i" />', {
554555
onError,
555556
prefixIdentifiers: true
@@ -564,7 +565,7 @@ describe('compiler: transform v-model', () => {
564565
})
565566

566567
test('used on props', () => {
567-
const onError = jest.fn()
568+
const onError = vi.fn()
568569
parseWithVModel('<div v-model="p" />', {
569570
onError,
570571
bindingMetadata: {

packages/compiler-core/__tests__/transforms/vOn.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { vi } from 'vitest'
12
import {
23
baseParse as parse,
34
CompilerOptions,
@@ -398,7 +399,7 @@ describe('compiler: transform v-on', () => {
398399
})
399400

400401
test('should error if no expression AND no modifier', () => {
401-
const onError = jest.fn()
402+
const onError = vi.fn()
402403
parseWithVOn(`<div v-on:click />`, { onError })
403404
expect(onError.mock.calls[0][0]).toMatchObject({
404405
code: ErrorCodes.X_V_ON_NO_EXPRESSION,
@@ -416,7 +417,7 @@ describe('compiler: transform v-on', () => {
416417
})
417418

418419
test('should NOT error if no expression but has modifier', () => {
419-
const onError = jest.fn()
420+
const onError = vi.fn()
420421
parseWithVOn(`<div v-on:click.prevent />`, { onError })
421422
expect(onError).not.toHaveBeenCalled()
422423
})

packages/compiler-core/__tests__/transforms/vSlot.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { vi } from 'vitest'
12
import {
23
CompilerOptions,
34
baseParse as parse,
@@ -843,7 +844,7 @@ describe('compiler: transform component slots', () => {
843844

844845
describe('errors', () => {
845846
test('error on extraneous children w/ named default slot', () => {
846-
const onError = jest.fn()
847+
const onError = vi.fn()
847848
const source = `<Comp><template #default>foo</template>bar</Comp>`
848849
parseWithSlots(source, { onError })
849850
const index = source.indexOf('bar')
@@ -866,7 +867,7 @@ describe('compiler: transform component slots', () => {
866867
})
867868

868869
test('error on duplicated slot names', () => {
869-
const onError = jest.fn()
870+
const onError = vi.fn()
870871
const source = `<Comp><template #foo></template><template #foo></template></Comp>`
871872
parseWithSlots(source, { onError })
872873
const index = source.lastIndexOf('#foo')
@@ -889,7 +890,7 @@ describe('compiler: transform component slots', () => {
889890
})
890891

891892
test('error on invalid mixed slot usage', () => {
892-
const onError = jest.fn()
893+
const onError = vi.fn()
893894
const source = `<Comp v-slot="foo"><template #foo></template></Comp>`
894895
parseWithSlots(source, { onError })
895896
const index = source.lastIndexOf('#foo')
@@ -912,7 +913,7 @@ describe('compiler: transform component slots', () => {
912913
})
913914

914915
test('error on v-slot usage on plain elements', () => {
915-
const onError = jest.fn()
916+
const onError = vi.fn()
916917
const source = `<div v-slot/>`
917918
parseWithSlots(source, { onError })
918919
const index = source.indexOf('v-slot')

packages/compiler-dom/__tests__/transforms/Transition.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { vi } from 'vitest'
12
import { compile } from '../../src'
23

34
describe('Transition multi children warnings', () => {
@@ -6,7 +7,7 @@ describe('Transition multi children warnings', () => {
67
shouldWarn: boolean,
78
message = `<Transition> expects exactly one child element or component.`
89
) {
9-
const spy = jest.fn()
10+
const spy = vi.fn()
1011
compile(template.trim(), {
1112
hoistStatic: true,
1213
transformHoist: null,

packages/compiler-dom/__tests__/transforms/vHtml.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { vi } from 'vitest'
12
import {
23
baseParse as parse,
34
transform,
@@ -40,7 +41,7 @@ describe('compiler: v-html transform', () => {
4041
})
4142

4243
it('should raise error and ignore children when v-html is present', () => {
43-
const onError = jest.fn()
44+
const onError = vi.fn()
4445
const ast = transformWithVHtml(`<div v-html="test">hello</div>`, {
4546
onError
4647
})
@@ -59,7 +60,7 @@ describe('compiler: v-html transform', () => {
5960
})
6061

6162
it('should raise error if has no expression', () => {
62-
const onError = jest.fn()
63+
const onError = vi.fn()
6364
transformWithVHtml(`<div v-html></div>`, {
6465
onError
6566
})

0 commit comments

Comments
 (0)