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 10, 2022
1 parent b0621a9 commit e48280d
Show file tree
Hide file tree
Showing 24 changed files with 10,676 additions and 20,250 deletions.
30,820 changes: 10,590 additions & 20,230 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.0",
"@types/jest": "27.5.0",
"@types/sinon": "10.0.13",
"@typescript-eslint/parser": "5.39.0",
"@vitejs/plugin-vue": "3.1.2",
"@vitest/coverage-istanbul": "0.24.0",
"@vue/eslint-config-prettier": "7.0.0",
"@vue/eslint-config-typescript": "10.0.0",
"@vue/test-utils": "2.1.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": "28.0.0",
"stylelint-config-standard-scss": "5.0.0",
"tikuidoc-tikui": "5.0.0",
"ts-jest": "26.5.6",
"typescript": "4.8.4",
"vite": "3.1.6",
"vue-jest": "5.0.0-alpha.10",
"vitest": "0.24.0",
"vue-tsc": "0.40.13"
},
"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/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
@@ -1,5 +1,6 @@
import { shallowMount } from '@vue/test-utils';
import { HeaderVue } from '@/common/primary/header';
import { describe, it, expect } from 'vitest';

describe('Header', () => {
it('should exist', () => {
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
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 @@ -560,7 +561,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 @@ -13,6 +13,7 @@ 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';

interface WrapperOptions {
modules: ModulesRepository;
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
47 changes: 47 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { defineConfig } from 'vitest/config';
import path from 'path';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
resolve: {
alias: {
'@': path.resolve(__dirname, './src/main/webapp/app'),
},
},
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: tag => /^x-/.test(tag),
},
},
}),
],
test: {
include: ['src/test/javascript/spec/**/*.spec.ts'],
logHeapUsage: true,
minThreads: 1,
maxThreads: 2,
environment: 'jsdom',
cache: false,
coverage: {
clean: true,
exclude: [
'src/main/webapp/**/*.component.ts',
'src/main/webapp/app/main.ts',
'src/main/webapp/app/router/index.ts',
'**/*.d.ts',
'src/test/**/*',
],
provider: 'istanbul',
reportsDirectory: 'target/test-results/',
reporter: ['html', 'json-summary', 'text', 'text-summary', 'lcov', 'clover'],
watermarks: {
statements: [100, 100],
branches: [100, 100],
functions: [100, 100],
lines: [100, 100],
},
},
},
});

0 comments on commit e48280d

Please sign in to comment.