Skip to content

Commit

Permalink
Move to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnuk committed Oct 26, 2022
1 parent 45202a1 commit 8b5f5aa
Show file tree
Hide file tree
Showing 26 changed files with 10,768 additions and 20,294 deletions.
30,898 changes: 10,629 additions & 20,269 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 6 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"format": "prettier . --write",
"glyph:build": "rimraf .fontello-session && fontello-cli install --config src/main/glyph/config.json --font src/main/glyph/font --css src/main/glyph/css",
"glyph:open": "rimraf .fontello-session && fontello-cli open --config src/main/glyph/config.json",
"jest": "jest src/test/javascript/spec --logHeapUsage --maxWorkers=2 --no-cache",
"lint": "npm run lint:js && npm run lint:pug && npm run lint:sass && npm run prettier:format",
"lint:ci": "npm run lint:ci:js && npm run lint:ci:pug && npm run lint:ci:sass && npm run prettier:check",
"lint:ci:js": "npm run lint:js:run -- --no-fix",
Expand All @@ -37,10 +36,10 @@
"prettier:run": "prettier \"{{src/**/,}*.{md,json,yml,html,vue,java,xml},*.{js,ts},src/{main/glyph,main/webapp,test/javascript}/**/*.{css,scss}}\"",
"preview": "vite preview",
"start": "npm run dev",
"test": "npm run jest --",
"test:clear": "jest --clearCache",
"test:watch": "npm run jest -- --watch",
"test": "npm run vitest -- run --coverage --",
"test:watch": "npm run vitest --",
"tikui:serve": "tikui-core serve",
"vitest": "vitest",
"webapp:serve": "vite"
},
"dependencies": {
Expand All @@ -53,10 +52,10 @@
"@prettier/plugin-xml": "2.2.0",
"@rushstack/eslint-patch": "1.2.0",
"@tikui/core": "3.0.1",
"@types/jest": "27.5.0",
"@types/sinon": "10.0.13",
"@typescript-eslint/parser": "5.41.0",
"@vitejs/plugin-vue": "3.1.2",
"@vitest/coverage-istanbul": "0.24.3",
"@vue/eslint-config-prettier": "7.0.0",
"@vue/eslint-config-typescript": "10.0.0",
"@vue/test-utils": "2.2.0",
Expand All @@ -66,9 +65,7 @@
"eslint-plugin-vue": "8.7.1",
"fontello-cli": "0.6.2",
"husky": "8.0.1",
"jest": "26.6.3",
"jest-sonar-reporter": "2.0.0",
"jest-transform-stub": "2.0.0",
"jsdom": "20.0.1",
"lint-staged": "13.0.3",
"postcss-scss": "4.0.5",
"prettier": "2.7.1",
Expand All @@ -83,10 +80,9 @@
"stylelint-config-standard": "29.0.0",
"stylelint-config-standard-scss": "5.0.0",
"tikuidoc-tikui": "5.0.1",
"ts-jest": "26.5.6",
"typescript": "4.8.4",
"vite": "3.1.8",
"vue-jest": "5.0.0-alpha.10",
"vitest": "0.24.3",
"vue-tsc": "1.0.9"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/app/common/primary/timeout/Timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface TimeoutListener {
export type TimeoutLauncher = () => TimeoutListener;

export class Timeout implements TimeoutListener {
private registration: Optional<number>;
private registration: Optional<ReturnType<typeof setTimeout>>;
constructor() {
this.registration = Optional.empty();
}
Expand Down
1 change: 1 addition & 0 deletions src/test/javascript/spec/common/domain/Optional.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Optional } from '@/common/domain/Optional';
import { describe, it, expect } from 'vitest';

describe('Optional', () => {
describe('Empty check', () => {
Expand Down
1 change: 1 addition & 0 deletions src/test/javascript/spec/common/domain/Statistics.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Statistics } from '@/common/domain/Statistics';
import { describe, it, expect } from 'vitest';

describe('Statistics', () => {
it('Should not build with negative application count', () => {
Expand Down
1 change: 1 addition & 0 deletions src/test/javascript/spec/common/primary/app/App.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { shallowMount, VueWrapper } from '@vue/test-utils';
import { AppVue } from '@/common/primary/app';
import { describe, it, expect } from 'vitest';

let wrapper: VueWrapper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { HeaderVue } from '@/common/primary/header';
import { flushPromises, shallowMount, VueWrapper } from '@vue/test-utils';
import sinon, { SinonStub } from 'sinon';
import { wrappedElement } from '../../../WrappedElement';
import { describe, it, expect } from 'vitest';

export interface StatisticsRepositoryStub extends StatisticsRepository {
get: SinonStub;
Expand Down
1 change: 1 addition & 0 deletions src/test/javascript/spec/common/primary/icon/Icon.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { shallowMount } from '@vue/test-utils';
import { IconVue } from '@/common/primary/icon';
import { describe, it, expect } from 'vitest';

describe('Icon', () => {
it('should exist', () => {
Expand Down
19 changes: 12 additions & 7 deletions src/test/javascript/spec/common/primary/timeout/Timeout.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { Timeout } from '@/common/primary/timeout/Timeout';
import sinon from 'sinon';
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';

const TIMEOUT_TIME = 3000;
const LESS_TIME = 1000;

describe('Timeout', () => {
beforeEach(() => jest.useFakeTimers());
beforeEach(() => {
vi.useFakeTimers();
});

afterEach(() => jest.useRealTimers());
afterEach(() => {
vi.useRealTimers();
});

it('Should launch timeout after passed time', () => {
const stub = sinon.stub();
new Timeout().register(stub, TIMEOUT_TIME);

jest.advanceTimersByTime(TIMEOUT_TIME);
vi.advanceTimersByTime(TIMEOUT_TIME);

expect(stub.callCount).toBe(1);
});
Expand All @@ -22,7 +27,7 @@ describe('Timeout', () => {
const stub = sinon.stub();
new Timeout().register(stub, TIMEOUT_TIME);

jest.advanceTimersByTime(LESS_TIME);
vi.advanceTimersByTime(LESS_TIME);

expect(stub.callCount).toBe(0);
});
Expand All @@ -33,7 +38,7 @@ describe('Timeout', () => {
timeout.register(stub, TIMEOUT_TIME);

timeout.unregister();
jest.advanceTimersByTime(TIMEOUT_TIME);
vi.advanceTimersByTime(TIMEOUT_TIME);

expect(stub.callCount).toBe(0);
});
Expand All @@ -50,9 +55,9 @@ describe('Timeout', () => {
const secondCall = sinon.stub();

timeout.register(firstCall, TIMEOUT_TIME);
jest.advanceTimersByTime(LESS_TIME);
vi.advanceTimersByTime(LESS_TIME);
timeout.register(secondCall, TIMEOUT_TIME);
jest.advanceTimersByTime(TIMEOUT_TIME);
vi.advanceTimersByTime(TIMEOUT_TIME);

expect(firstCall.callCount).toBe(0);
expect(secondCall.callCount).toBe(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AlertListener } from '@/common/domain/alert/AlertListener';
import { AlertListenerFixture, stubAlertListener } from '../../domain/AlertListener.fixure';
import { TimeoutListener } from '@/common/primary/timeout/Timeout';
import { stubTimeout } from '../timeout/Timeout.fixture';
import { describe, it, expect } from 'vitest';

let wrapper: VueWrapper;
let component: any;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sinon from 'sinon';

import ConsoleLogger from '@/common/secondary/ConsoleLogger';
import { describe, it, expect } from 'vitest';

describe('ConsoleLogger', () => {
it('should log an error', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RestStatistics } from '@/common/secondary/RestStatistics';
import { RestStatisticsRepository } from '@/common/secondary/RestStatisticsRepository';
import { dataBackendResponse, stubAxiosHttp } from '../../http/AxiosHttpStub';
import { describe, it, expect } from 'vitest';

describe('Rest statistics repository', () => {
it('Should get statistics using axios', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import sinon, { SinonStub } from 'sinon';
import { Emitter } from 'mitt';
import { MittAlertBus } from '@/common/secondary/alert/MittAlertBus';
import { AlertType } from '@/common/secondary/alert/AlertType';
import { describe, it, expect } from 'vitest';

interface EmitterStub extends Emitter<any> {
emit: SinonStub;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import sinon from 'sinon';
import mitt from 'mitt';
import { MittAlertListener } from '@/common/secondary/alert/MittAlertListener';
import { AlertType } from '@/common/secondary/alert/AlertType';
import { describe, it, expect } from 'vitest';

describe('MittAlertListener', () => {
it('should listen sent success message', () => {
Expand Down
1 change: 1 addition & 0 deletions src/test/javascript/spec/http/AxiosHttp.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AxiosResponse } from 'axios';
import { AxiosHttp } from '@/http/AxiosHttp';
import { dataAxiosResponse, stubAxiosInstance } from './AxiosStub';
import { describe, it, expect } from 'vitest';

interface Payload {
payload: string;
Expand Down
1 change: 1 addition & 0 deletions src/test/javascript/spec/loader/primary/Loader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Loader } from '@/loader/primary/Loader';
import { describe, it, expect } from 'vitest';

describe('Loader', () => {
it('Should be loading for loading loader', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { LandscapeSelectionElement } from '@/module/domain/landscape/LandscapeSe
import { LandscapeSelectionTree } from '@/module/domain/landscape/LandscapeSelectionTree';
import { applicationBaseNamePropertyDefinition, moduleSlug, optionalBooleanPropertyDefinition } from '../Modules.fixture';
import { defaultLandscape, featureSlug } from './Landscape.fixture';
import { describe, it, expect } from 'vitest';

describe('Landscape', () => {
describe('Reset applied modules', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LandscapeSelectionElement } from '@/module/domain/landscape/LandscapeSelectionElement';
import { LandscapeSelectionTree } from '@/module/domain/landscape/LandscapeSelectionTree';
import { moduleSlug } from '../Modules.fixture';
import { describe, expect, it } from 'vitest';

describe('Landscape selection tree', () => {
it('Should get empty optional for unknown element', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LandscapeUnselectionTree } from '@/module/domain/landscape/LandscapeUnselectionTree';
import { moduleSlug } from '../Modules.fixture';
import { describe, it, expect } from 'vitest';

describe('Unselection tree', () => {
it('Should not include unknown element', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { defaultLandscape } from '../../domain/landscape/Landscape.fixture';
import { ModulesRepositoryStub, projectHistoryWithInit, stubModulesRepository } from '../../domain/Modules.fixture';
import { ProjectFoldersRepositoryStub, stubProjectFoldersRepository } from '../../domain/ProjectFolders.fixture';
import { stubWindow } from '../GlobalWindow.fixture';
import { describe, it, expect, vi } from 'vitest';

interface ApplicationListenerStub extends ApplicationListener {
addEventListener: SinonStub;
Expand Down Expand Up @@ -200,7 +201,20 @@ describe('Landscape', () => {
assertSelectableHighlightedConnectorsCount(wrapper, 4);
});

it('Should un-highlight module and dependencies', async () => {
it('Should un-highlight single module and dependencies', async () => {
const wrapper = await componentWithLandscape();

wrapper.find(wrappedElement('java-base-module')).trigger('mouseover');
await wrapper.vm.$nextTick();
wrapper.find(wrappedElement('java-base-module')).trigger('mouseleave');
await wrapper.vm.$nextTick();

expect(wrapper.find(wrappedElement('java-base-module')).classes()).not.toContain('-selectable-highlighted');
expect(wrapper.find(wrappedElement('init-module')).classes()).not.toContain('-selectable-highlighted');
assertSelectableHighlightedConnectorsCount(wrapper, 0);
});

it('Should un-highlight featured module and dependencies', async () => {
const wrapper = await componentWithLandscape();

wrapper.find(wrappedElement('vue-module')).trigger('mouseover');
Expand Down Expand Up @@ -560,7 +574,7 @@ describe('Landscape', () => {
const wrapper = wrap({ modules });
await flushPromises();

const consoleErrors = jest.spyOn(console, 'error').mockImplementation();
const consoleErrors = vi.spyOn(console, 'error').mockImplementation();
await updatePath(wrapper);

expect(console.error).toHaveBeenCalledTimes(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
defaultModules,
defaultModulesWithNonDefaultProperties,
defaultProjectHistory,
moduleSlug,
ModulesRepositoryStub,
stubModulesRepository,
} from '../../domain/Modules.fixture';
Expand All @@ -13,6 +14,9 @@ import { stubAlertBus } from '../../../common/domain/AlertBus.fixture';
import { ProjectFoldersRepository } from '@/module/domain/ProjectFoldersRepository';
import { ProjectFoldersRepositoryStub, stubProjectFoldersRepository } from '../../domain/ProjectFolders.fixture';
import { stubWindow } from '../GlobalWindow.fixture';
import { describe, it, expect } from 'vitest';
import { Modules } from '@/module/domain/Modules';
import { Module } from '@/module/domain/Module';

interface WrapperOptions {
modules: ModulesRepository;
Expand All @@ -39,6 +43,13 @@ const wrap = (options?: Partial<WrapperOptions>): VueWrapper => {
});
};

const makeTaggedModule = (tag: string): Module => ({
slug: moduleSlug(`${tag}-slug`),
description: `${tag} description`,
properties: [],
tags: [tag],
});

describe('Modules', () => {
describe('Loading', () => {
it('Should display loader when waiting for modules', () => {
Expand Down Expand Up @@ -76,10 +87,10 @@ describe('Modules', () => {
});

describe('Properties filling', () => {
it('Should select module', async () => {
it.each(['click', 'keyup.enter'])('Should select module on %s', async trigger => {
const wrapper = await componentWithModules();

await selectModule(wrapper);
await selectModule(wrapper, trigger);

expect(wrapper.find(wrappedElement('parameter-baseName-field')).attributes('type')).toBe('text');
expect(wrapper.find(wrappedElement('parameter-baseName-optional-marker')).exists()).toBe(false);
Expand Down Expand Up @@ -494,6 +505,29 @@ describe('Modules', () => {
expect(wrapper.find(wrappedElement('module-spring-cucumber-application-button')).exists()).toBe(false);
});

it.each([{ tag: 'init' }, { tag: 'server' }, { tag: 'client' }])('Should filter modules with $tag filter', async ({ tag }) => {
const tags = ['init', 'server', 'client'];
const otherTags = tags.filter(current => current !== tag);
const repository = stubModulesRepository();

repository.list.resolves(
new Modules([
{
name: 'Three filters',
modules: tags.map(makeTaggedModule),
},
])
);
const wrapper = wrap({ modules: repository });
await flushForm(wrapper);

wrapper.find(wrappedElement(`${tag}-tag-filter`)).trigger('click');
await flushForm(wrapper);

expect(wrapper.find(wrappedElement(`module-${tag}-slug-application-button`)).exists()).toBe(true);
otherTags.forEach(other => expect(wrapper.find(wrappedElement(`module-${other}-slug-application-button`)).exists()).toBe(false));
});

it('Should filter modules with tag filter', async () => {
const modules = repositoryWithModules();
const wrapper = await filledModuleForm(modules);
Expand Down Expand Up @@ -605,8 +639,8 @@ const componentWithModulesAndNonDefaultProperties = async (): Promise<VueWrapper
return wrapper;
};

const selectModule = async (wrapper: VueWrapper) => {
wrapper.find(wrappedElement('spring-cucumber-module-content')).trigger('click');
const selectModule = async (wrapper: VueWrapper, trigger = 'click') => {
wrapper.find(wrappedElement('spring-cucumber-module-content')).trigger(trigger);
await wrapper.vm.$nextTick();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ModulesRepository } from '@/module/domain/ModulesRepository';
import { wrappedElement } from '../../../WrappedElement';
import { stubWindow } from '../GlobalWindow.fixture';
import sinon from 'sinon';
import { describe, it, expect } from 'vitest';

interface WrapperOptions {
folderPath: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { RestLandscapeFeature } from '@/module/secondary/RestLandscapeFeature';
import { ModuleSlug } from '@/module/domain/ModuleSlug';
import { RestModulePropertyDefinition } from '@/module/secondary/RestModulePropertyDefinition';
import { defaultLandscape } from '../domain/landscape/Landscape.fixture';
import { describe, it, expect } from 'vitest';

describe('Rest modules repository', () => {
it('Should list modules using axios', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { stubAxiosHttp } from '../../http/AxiosHttpStub';
import { RestProjectFoldersRepository } from '@/module/secondary/RestProjectFoldersRepository';
import { describe, it, expect } from 'vitest';

describe('Rest project folders repository', () => {
it('Should get project folder using axios', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"resolveJsonModule": true,
"esModuleInterop": true,
"lib": ["esnext", "dom"],
"types": ["vite/client", "@types/jest"],
"types": ["vite/client"],
"baseUrl": ".",
"paths": {
"@/*": ["src/main/webapp/app/*"]
Expand Down

0 comments on commit 8b5f5aa

Please sign in to comment.