Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add packages/tdesign-vue-next for test #5021

Merged
merged 20 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions internal/tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@tdesign/internal-tests",
"private": true,
"author": "tdesign",
"license": "MIT"
}
20 changes: 14 additions & 6 deletions test/utils/index.js → internal/tests/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export function mockDelay(timeout = 300) {
});
}

export function simulateInputChange(dom, text) {
export function simulateInputChange(dom: HTMLInputElement, text: string) {
dom.value = text;
dom.dispatchEvent(new Event('input'));
}

// input enter
export function simulateInputEnter(dom) {
export function simulateInputEnter(dom: HTMLInputElement) {
fireEvent.keyDown(dom, { key: 'Enter', code: 'Enter', charCode: 13 });
}

Expand All @@ -21,12 +21,15 @@ export function simulateDocumentClick(dom = document) {
}

// image event enums:load/error
export function simulateImageEvent(dom, event) {
export function simulateImageEvent(dom: HTMLImageElement, event: 'error' | 'load') {
fireEvent(dom, createEvent(event, dom));
}

// document keydown
export function simulateKeydownEvent(dom, type) {
export function simulateKeydownEvent(
dom: Document,
type: 'ArrowDown' | 'ArrowUp' | 'ArrowLeft' | 'ArrowRight' | 'Escape' | 'Enter',
) {
let event;
switch (type) {
case 'ArrowDown':
Expand Down Expand Up @@ -83,7 +86,7 @@ export function getFakeFileList(type = 'file', count = 1) {
* @param {Number} count 文件数量
* @returns File[]
*/
export function simulateFileChange(dom, type = 'file', count = 1) {
export function simulateFileChange(dom: HTMLInputElement, type = 'file', count = 1) {
const fakeFileList = getFakeFileList(type, count);
fireEvent.change(dom, { target: { files: fakeFileList } });
return fakeFileList;
Expand All @@ -97,7 +100,12 @@ export function simulateFileChange(dom, type = 'file', count = 1) {
* @param {Number} count 数量
* @returns File[]
*/
export function simulateDragFileChange(dom, trigger, type = 'file', count = 1) {
export function simulateDragFileChange(
dom: Element,
trigger: 'dragEnter' | 'dragLeave' | 'dragOver' | 'drop',
type = 'file',
count = 1,
) {
const fakeFileList = getFakeFileList(type, count);
fireEvent[trigger](dom, {
dataTransfer: { files: fakeFileList },
Expand Down
33 changes: 16 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "tdesign-vue-mono",
"private": true,
"packageManager": "[email protected]",
"repository": {
"type": "git",
Expand All @@ -25,23 +26,21 @@
"generate:coverage-badge": "pnpm test:unit-coverage && node script/test/generate-coverage.js",
"build": "cross-env NODE_ENV=production rollup -c script/rollup.config.js && pnpm build:tsc",
"build:tsc": "run-p build:tsc-*",
"build:tsc-es": "tsc --emitDeclarationOnly -d --rootDir packages/components --outDir packages/tdesign-vue-next/es/",
"build:tsc-esm": "tsc --emitDeclarationOnly -d --rootDir packages/components --outDir packages/tdesign-vue-next/esm/",
"build:tsc-lib": "tsc --emitDeclarationOnly -d --rootDir packages/components --outDir packages/tdesign-vue-next/lib/",
"build:tsc-cjs": "tsc --emitDeclarationOnly -d --rootDir packages/components --outDir packages/tdesign-vue-next/cjs/",
"build:tsc-es": "tsc --outDir packages/tdesign-vue-next/es/ -p tsconfig.components.json",
"build:tsc-esm": "tsc --outDir packages/tdesign-vue-next/esm/ -p tsconfig.components.json",
"build:tsc-lib": "tsc --outDir packages/tdesign-vue-next/lib/ -p tsconfig.components.json",
"build:tsc-cjs": "tsc --outDir packages/tdesign-vue-next/cjs/ -p tsconfig.components.json",
"lint:fix": "eslint --ext .vue,.js,.ts,.tsx ./packages --max-warnings 0 --fix --cache",
"lint": "pnpm lint:tsc && eslint --ext .vue,.js,.ts,.tsx ./packages --max-warnings 0 --cache",
"lint:tsc": "tsc --emitDeclarationOnly",
"test": "pnpm test:unit && pnpm test:snap",
"test:unit": "vitest run",
"test:update": "vitest run -u && pnpm test:snap-update",
"test:unit-dev": "vitest ",
"test:unit-gui": "vitest --ui",
"test:unit-coverage": "vitest run --coverage",
"test:snap": "cross-env NODE_ENV=test-snap vitest run ",
"test:snap-update": "cross-env NODE_ENV=test-snap vitest run -u",
"test:e2e": "cypress run --config-file test/cypress/cypress.config.js --component",
"test:e2e-gui": "cypress open --config-file test/cypress/cypress.config.js",
"lint:tsc": "tsc --noEmit",
"test": "pnpm -C packages/tdesign-vue-next/test test",
"test:unit": "pnpm -C packages/tdesign-vue-next/test test:unit",
"test:update": "pnpm -C packages/tdesign-vue-next/test test:update",
"test:unit-dev":"pnpm -C packages/tdesign-vue-next/test test:unit-dev",
"test:unit-gui":"pnpm -C packages/tdesign-vue-next/test test:unit-gui",
"test:unit-coverage":"pnpm -C packages/tdesign-vue-next/test test:unit-coverage",
"test:snap": "pnpm -C packages/tdesign-vue-next/test test:snap",
"test:snap-update":"pnpm -C packages/tdesign-vue-next/test test:snap-update",
"robot": "publish-cli robot-msg",
"prepare": "husky install"
},
Expand All @@ -52,6 +51,7 @@
"@popperjs/core": "^2.11.8",
"@tdesign/common-js": "workspace:^",
"@tdesign/common-style": "workspace:^",
"@tdesign/components": "workspace:^",
"@types/sortablejs": "^1.15.1",
"@types/tinycolor2": "^1.4.3",
"@types/validator": "^13.7.17",
Expand Down Expand Up @@ -83,6 +83,7 @@
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-replace": "^4.0.0",
"@rollup/plugin-url": "^7.0.0",
"@tdesign/internal-tests": "workspace:^",
"@testing-library/dom": "^8.20.1",
"@types/babel__traverse": "~7.20.6",
"@types/lodash-es": "^4.17.12",
Expand Down Expand Up @@ -115,7 +116,6 @@
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-vue": "^8.7.1",
"glob": "^7.2.3",
"gray-matter": "^4.0.3",
"husky": "^7.0.4",
"ignore": "^5.2.4",
Expand Down Expand Up @@ -152,7 +152,6 @@
"vite-plugin-pwa": "^0.12.8",
"vite-plugin-tdoc": "^2.0.4",
"vitest": "^2.1.8",
"vitest-fetch-mock": "^0.1.0",
"vue": "3.3.9",
"vue-router": "^4.2.4",
"workbox-precaching": "^6.6.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { mount } from '@vue/test-utils';
import { vi } from 'vitest';
import { AutoComplete } from '..';
import { getNormalAutoCompleteMount, getOptionSlotAutoCompleteMount } from './mount';
import { simulateKeydownEvent } from '@test/utils';
import { simulateKeydownEvent } from '@tdesign/internal-tests/utils';

describe('AutoComplete Component', () => {
it(`props.autofocus is equal to false`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { mount } from '@vue/test-utils';
import { vi } from 'vitest';
import { Avatar, AvatarGroup } from '..';
import { getAvatarGroupDefaultMount } from './mount';
import { mockDelay, simulateImageEvent } from '@test/utils';
import { mockDelay, simulateImageEvent } from '@tdesign/internal-tests/utils';

describe('Avatar Component', () => {
it('props.alt works fine', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
getCustomGuideStepMount,
getCustomMultipleGuideStepMount,
} from './mount';
import { mockDelay } from '@test/utils';
import { mockDelay } from '@tdesign/internal-tests/utils';

describe('Guide Component', () => {
afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { mount } from '@vue/test-utils';
import { vi } from 'vitest';
import { Image } from '..';
import { getOverlayImageMount } from './mount';
import { simulateImageEvent } from '@test/utils';
import { simulateImageEvent } from '@tdesign/internal-tests/utils';

describe('Image Component', () => {
it('props.alt works fine', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { mount } from '@vue/test-utils';
import { vi } from 'vitest';
import { Input, InputGroup } from '..';
import { getInputGroupDefaultMount } from './mount';
import { simulateInputChange } from '@test/utils';
import { simulateInputChange } from '@tdesign/internal-tests/utils';

describe('Input Component', () => {
const alignClassNameList = [{ 't-align-left': false }, 't-align-center', 't-align-right'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { mount } from '@vue/test-utils';
import { vi } from 'vitest';
import { TagInput } from '..';
import { getTagInputValueMount, getTagInputDefaultMount } from './mount';
import { simulateInputChange, simulateInputEnter } from '@test/utils';
import { simulateInputChange, simulateInputEnter } from '@tdesign/internal-tests/utils';

describe('TagInput Component', () => {
it('props.clearable: empty TagInput does not need clearIcon', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { mount } from '@vue/test-utils';
import { vi } from 'vitest';
import { Upload } from '..';
import { mockDelay, simulateFileChange, getFakeFileList, simulateDragFileChange } from '@test/utils';
import { mockDelay, simulateFileChange, getFakeFileList, simulateDragFileChange } from '@tdesign/internal-tests/utils';
import { getUploadServer } from './request';

describe('Upload Component', () => {
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions packages/tdesign-vue-next/test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@tdesign/vue-next-test",
"private": true,
"author": "tdesign",
"license": "MIT",
"scripts": {
"test": "pnpm test:unit && pnpm test:snap",
"test:unit": "vitest run",
"test:update": "vitest run -u && pnpm test:snap-update",
"test:unit-dev": "vitest",
"test:unit-gui": "vitest --ui",
"test:unit-coverage": "vitest run --coverage",
"test:snap": "cross-env NODE_ENV=test-snap vitest run ",
"test:snap-update": "cross-env NODE_ENV=test-snap vitest run -u"
},
"devDependencies": {
"@vue/test-utils": "^2.4.1",
"glob": "^11.0.1",
"vitest-fetch-mock": "^0.1.0",
"vue": "3.3.9",
"vue-router": "^4.2.4"
}
}
Loading