Skip to content

Commit 08bb075

Browse files
committed
LITE-29964 migrate to use vitest
1 parent a57629d commit 08bb075

32 files changed

+5944
-8250
lines changed

.eslintrc.cjs

+9-14
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
'plugin:storybook/recommended',
1818
'prettier',
1919
'@vue/eslint-config-prettier/skip-formatting',
20+
'plugin:vitest-globals/recommended',
2021
],
2122

2223
plugins: ['vue'],
@@ -34,21 +35,15 @@ module.exports = {
3435
'vue/attribute-hyphenation': ['error', 'never'],
3536
},
3637

37-
overrides: [
38-
// Config for unit tests
39-
{
40-
files: ['*.spec.js'],
41-
plugins: ['jest'],
42-
extends: ['plugin:jest/recommended', 'plugin:jest-formatting/strict'],
43-
env: {
44-
jest: true,
45-
'jest/globals': true,
46-
},
47-
globals: {
48-
global: 'writable',
49-
},
50-
},
38+
env: {
39+
'vitest-globals': true,
40+
},
5141

42+
parserOptions: {
43+
ecmaVersion: 'latest',
44+
},
45+
46+
overrides: [
5247
// Config for files that run in node env (config files, etc)
5348
{
5449
files: ['*.config.js', '.eslintrc.js'],

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ dist-ssr
1313
coverage
1414
*.local
1515

16+
/test/report.json
17+
1618
/cypress/videos/
1719
/cypress/screenshots/
1820

components/jest.config.js

-47
This file was deleted.

components/src/core/injector/core/Core.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('Core', () => {
2424
[{ test: 123 }, null],
2525
[null, { test: 123 }],
2626
])('should do nothing while $state is %j and data is %j', (state, data) => {
27-
global.Object.keys = jest.fn(Object.keys);
27+
global.Object.keys = vi.fn(Object.keys);
2828
core.state = state;
2929
core.assign(data);
3030

@@ -53,7 +53,7 @@ describe('Core', () => {
5353
};
5454

5555
core.watchers = {
56-
test: [jest.fn()],
56+
test: [vi.fn()],
5757
};
5858

5959
core.assign({
@@ -71,7 +71,7 @@ describe('Core', () => {
7171
};
7272

7373
core.watchers = {
74-
'*': [jest.fn()],
74+
'*': [vi.fn()],
7575
};
7676

7777
core.assign({

components/src/core/injector/core/injectorFactory.spec.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import injectorFactory from './injectorFactory';
22
import { processRoute } from '~core/router';
33

4-
jest.mock('~core/router', () => ({
5-
processRoute: jest.fn().mockReturnValue('processRouteMockedReturnValue'),
4+
vi.mock('~core/router', () => ({
5+
processRoute: vi.fn().mockReturnValue('processRouteMockedReturnValue'),
66
}));
77

88
describe('injectorFactory', () => {
99
describe('#watch()', () => {
1010
it('should add callback as new watcher for passed property', () => {
1111
const core = { watchers: {}, state: { foo: 'bar' } };
1212
const injector = injectorFactory(core);
13-
const cb = jest.fn();
13+
const cb = vi.fn();
1414

1515
injector.watch('foo', cb);
1616
core.watchers.foo[0]();
@@ -21,7 +21,7 @@ describe('injectorFactory', () => {
2121
it('should add immediate callback call', () => {
2222
const core = { watchers: {}, state: { foo: 'bar' } };
2323
const injector = injectorFactory(core);
24-
const cb = jest.fn();
24+
const cb = vi.fn();
2525

2626
injector.watch('foo', cb, { immediate: true });
2727

@@ -31,7 +31,7 @@ describe('injectorFactory', () => {
3131
it('should add immediate callback call with "*" key', () => {
3232
const core = { watchers: {}, state: { foo: 'bar' } };
3333
const injector = injectorFactory(core);
34-
const cb = jest.fn();
34+
const cb = vi.fn();
3535

3636
injector.watch('*', cb, { immediate: true });
3737

@@ -45,7 +45,7 @@ describe('injectorFactory', () => {
4545
};
4646

4747
const injector = injectorFactory(core);
48-
const cb = jest.fn();
48+
const cb = vi.fn();
4949

5050
injector.watch('foo', cb);
5151
core.watchers.foo[1]();
@@ -60,7 +60,7 @@ describe('injectorFactory', () => {
6060
};
6161

6262
const injector = injectorFactory(core);
63-
const cb = jest.fn();
63+
const cb = vi.fn();
6464

6565
injector.watch(cb);
6666
core.watchers['*'][0]();
@@ -74,10 +74,10 @@ describe('injectorFactory', () => {
7474
let commit;
7575

7676
beforeEach(() => {
77-
global.window.top.postMessage = jest.fn();
77+
global.window.top.postMessage = vi.fn();
7878

7979
core = {
80-
assign: jest.fn(),
80+
assign: vi.fn(),
8181
id: 'XXX',
8282
state: {
8383
foo: 'bar',
@@ -124,7 +124,7 @@ describe('injectorFactory', () => {
124124

125125
describe('#emit()', () => {
126126
beforeEach(() => {
127-
global.window.top.postMessage = jest.fn();
127+
global.window.top.postMessage = vi.fn();
128128
});
129129

130130
it('should emit proper event', () => {
@@ -173,7 +173,7 @@ describe('injectorFactory', () => {
173173
describe('#listen()', () => {
174174
it('should put provided callback to proper listeners', () => {
175175
const core = { listeners: {} };
176-
const cb = jest.fn();
176+
const cb = vi.fn();
177177
injectorFactory(core).listen('foo', cb);
178178
core.listeners.foo();
179179

@@ -187,7 +187,7 @@ describe('injectorFactory', () => {
187187

188188
beforeEach(() => {
189189
injector = injectorFactory({});
190-
injectorEmitSpy = jest.spyOn(injector, 'emit');
190+
injectorEmitSpy = vi.spyOn(injector, 'emit');
191191
});
192192

193193
it('calls processRoute with the given arguments', () => {

components/src/core/injector/core/launcher.spec.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import launch from './launcher';
22

3-
const resizeObserverCtorSpy = jest.fn();
4-
const resizeObserverObserveSpy = jest.fn();
3+
const resizeObserverCtorSpy = vi.fn();
4+
const resizeObserverObserveSpy = vi.fn();
55
const resizeObserverEntriesStub = [
66
{
77
contentRect: {
@@ -30,20 +30,18 @@ describe('$init', () => {
3030
let init;
3131

3232
beforeEach(() => {
33-
global.window.addEventListener = jest.fn();
33+
global.window.addEventListener = vi.fn();
3434
global.window.name = 'XXX';
35-
global.crypto = {
36-
getRandomValues: jest.fn(() => ['abc']),
37-
};
35+
global.crypto.getRandomValues = vi.fn(() => ['abc']);
3836

3937
injector = {
40-
listen: jest.fn(),
41-
emit: jest.fn(),
38+
listen: vi.fn(),
39+
emit: vi.fn(),
4240
};
4341

4442
core = {
45-
size: jest.fn(() => 'SIZE'),
46-
assign: jest.fn(),
43+
size: vi.fn(() => 'SIZE'),
44+
assign: vi.fn(),
4745
};
4846

4947
init = () => launch(injector, core);
@@ -163,7 +161,7 @@ describe('$init', () => {
163161
},
164162
};
165163

166-
core.listeners = { test: jest.fn() };
164+
core.listeners = { test: vi.fn() };
167165
handler({ data });
168166

169167
expect(core.listeners.test).toHaveBeenCalledWith('TEST', data);

components/src/core/injector/index.spec.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ import Core from './core/Core';
44
import injectorFactory from './core/injectorFactory';
55
import launcher from './core/launcher';
66

7-
jest.mock('./core/Core', () => ({
7+
vi.mock('./core/Core', () => ({
88
__esModule: true,
9-
default: jest.fn().mockImplementation(() => ({ core: 'CORE' })),
9+
default: vi.fn().mockImplementation(() => ({ core: 'CORE' })),
1010
}));
1111

12-
jest.mock('./core/injectorFactory', () => ({
12+
vi.mock('./core/injectorFactory', () => ({
1313
__esModule: true,
14-
default: jest.fn(() => 'INJECTOR'),
14+
default: vi.fn(() => 'INJECTOR'),
1515
}));
1616

17-
jest.mock('./core/launcher', () => ({
17+
vi.mock('./core/launcher', () => ({
1818
__esModule: true,
19-
default: jest.fn(() => Promise.resolve()),
19+
default: vi.fn(() => Promise.resolve()),
2020
}));
2121

2222
describe('createInjector', () => {

components/src/index.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import createApp from './index';
33
import injector from '~core/injector';
44
import registerWidget from '~core/registerWidget';
55

6-
jest.mock('~core/injector', () => ({
6+
vi.mock('~core/injector', () => ({
77
__esModule: true,
8-
default: jest.fn(() => 'app'),
8+
default: vi.fn(() => 'app'),
99
}));
1010

11-
jest.mock('~core/registerWidget', () => ({
11+
vi.mock('~core/registerWidget', () => ({
1212
__esModule: true,
13-
default: jest.fn(),
13+
default: vi.fn(),
1414
}));
1515

1616
describe('#createApp function', () => {

components/src/widgets/button/widget.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { mount } from '@vue/test-utils';
2-
import Button from './widget';
2+
import Button from './widget.vue';
33

44
describe('Button widget', () => {
55
let wrapper;

components/src/widgets/complexTable/widget.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { mount } from '@vue/test-utils';
2-
import ComplexTable from './widget';
2+
import ComplexTable from './widget.vue';
33
import { nextTick } from 'vue';
44

55
describe('ComplexTable widget', () => {

components/src/widgets/icon/widget.spec.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import Icon from './widget';
1+
import Icon from './widget.vue';
2+
import { googleSnowboardingBaseline } from '@cloudblueconnect/material-svg';
23

34
describe('Icon', () => {
45
let result;
@@ -12,9 +13,7 @@ describe('Icon', () => {
1213
);
1314
result = component.icon.value;
1415

15-
expect(result).toEqual(
16-
'<svg>This replaces import of files from @cloudblueconnect/material-svg in .spec.js files to optimize the run time of all unit tests</svg>',
17-
);
16+
expect(result).toEqual(googleSnowboardingBaseline);
1817
});
1918
});
2019

components/src/widgets/menu/widget.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { mount } from '@vue/test-utils';
2-
import Menu from './widget';
2+
import Menu from './widget.vue';
33

44
describe('Menu component', () => {
55
describe('methods', () => {
@@ -23,7 +23,7 @@ describe('Menu component', () => {
2323

2424
describe('#handleClickOutside', () => {
2525
it('closes menu when clicked outside menu bounds', async () => {
26-
const event = { composedPath: jest.fn().mockReturnValue(['slot', 'button']) };
26+
const event = { composedPath: vi.fn().mockReturnValue(['slot', 'button']) };
2727
const wrapper = mount(Menu);
2828
wrapper.vm.menu = 'div';
2929
wrapper.vm.showMenu = true;
@@ -33,7 +33,7 @@ describe('Menu component', () => {
3333
});
3434

3535
it('does not close menu when clicked inside menu bounds', async () => {
36-
const event = { composedPath: jest.fn().mockReturnValue(['slot', 'button']) };
36+
const event = { composedPath: vi.fn().mockReturnValue(['slot', 'button']) };
3737
const wrapper = mount(Menu);
3838
wrapper.vm.menu = 'button';
3939
wrapper.vm.showMenu = true;
@@ -67,7 +67,7 @@ describe('Menu component', () => {
6767

6868
describe('onMounted', () => {
6969
it('adds up event listener on component mount', () => {
70-
const addEventListenerSpy = jest.spyOn(document, 'addEventListener');
70+
const addEventListenerSpy = vi.spyOn(document, 'addEventListener');
7171

7272
mount(Menu);
7373

@@ -79,7 +79,7 @@ describe('Menu component', () => {
7979

8080
describe('onUnmounted', () => {
8181
it('cleans up event listener on component unmount', async () => {
82-
const removeEventListenerSpy = jest.spyOn(document, 'removeEventListener');
82+
const removeEventListenerSpy = vi.spyOn(document, 'removeEventListener');
8383

8484
const wrapper = mount(Menu);
8585
await wrapper.unmount();

0 commit comments

Comments
 (0)