切换vitest-browser
This commit is contained in:
1
.vscode/extensions.json
vendored
1
.vscode/extensions.json
vendored
@@ -1,3 +1,2 @@
|
|||||||
{
|
{
|
||||||
"recommendations": ["Orta.vscode-jest"]
|
|
||||||
}
|
}
|
67
.vscode/launch.json
vendored
67
.vscode/launch.json
vendored
@@ -1,36 +1,33 @@
|
|||||||
{
|
{
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "Jest All",
|
"name": "Run Vitest Browser",
|
||||||
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
|
||||||
"args": ["--runInBand"],
|
"console": "integratedTerminal",
|
||||||
"console": "integratedTerminal",
|
"args": [
|
||||||
"internalConsoleOptions": "neverOpen",
|
"--inspect-brk",
|
||||||
"disableOptimisticBPs": true,
|
"--browser",
|
||||||
"windows": {
|
"--no-file-parallelism"
|
||||||
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
|
]
|
||||||
}
|
},
|
||||||
},
|
{
|
||||||
{
|
"type": "chrome",
|
||||||
"type": "node",
|
"request": "attach",
|
||||||
"request": "launch",
|
"name": "Attach to Vitest Browser",
|
||||||
"name": "Jest Current File",
|
"port": 9229
|
||||||
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
}
|
||||||
"args": [
|
],
|
||||||
"--runTestsByPath",
|
"compounds": [
|
||||||
"${relativeFile}",
|
{
|
||||||
"--config",
|
"name": "Debug Vitest Browser",
|
||||||
"jest.config.js"
|
"configurations": [
|
||||||
],
|
"Attach to Vitest Browser",
|
||||||
"console": "integratedTerminal",
|
"Run Vitest Browser"
|
||||||
"internalConsoleOptions": "neverOpen",
|
],
|
||||||
"disableOptimisticBPs": true,
|
"stopAll": true
|
||||||
"windows": {
|
}
|
||||||
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
|
]
|
||||||
}
|
}
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@@ -1,3 +1,2 @@
|
|||||||
{
|
{
|
||||||
"jest.useJest30": true
|
|
||||||
}
|
}
|
23
package.json
23
package.json
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cut-abstractions",
|
"name": "cut-abstractions",
|
||||||
|
"type": "module",
|
||||||
"version": "0.1.5",
|
"version": "0.1.5",
|
||||||
"description": "",
|
"description": "",
|
||||||
"files": [
|
"files": [
|
||||||
@@ -11,40 +12,28 @@
|
|||||||
"exports": {
|
"exports": {
|
||||||
".": "./dist/index.js"
|
".": "./dist/index.js"
|
||||||
},
|
},
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"release": "pnpm pack --pack-destination ./dist-packs",
|
"release": "pnpm pack --pack-destination ./dist-packs",
|
||||||
"clean": "rimraf ./dist",
|
"clean": "rimraf ./dist",
|
||||||
"test": "vitest",
|
"test": "vitest"
|
||||||
"test:run": "vitest run",
|
|
||||||
"test:browser": "vitest --browser"
|
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"packageManager": "pnpm@9.1.1+sha1.09ada6cd05003e0ced25fb716f9fda4063ec2e3b",
|
"packageManager": "pnpm@9.1.1+sha1.09ada6cd05003e0ced25fb716f9fda4063ec2e3b",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@peculiar/webcrypto": "^1.5.0",
|
"@testing-library/dom": "^10.4.0",
|
||||||
"@swc/core": "^1.12.4",
|
|
||||||
"@vitest/browser": "^3.2.4",
|
"@vitest/browser": "^3.2.4",
|
||||||
"@vitest/coverage-v8": "^3.2.4",
|
|
||||||
"@vitest/ui": "^3.2.4",
|
|
||||||
"cadapi": "http://gitea.cf/MES-FE/webcad-api/archive/0.0.60.tar.gz",
|
"cadapi": "http://gitea.cf/MES-FE/webcad-api/archive/0.0.60.tar.gz",
|
||||||
"happy-dom": "^18.0.1",
|
|
||||||
"js-angusj-clipper": "^1.0.4",
|
"js-angusj-clipper": "^1.0.4",
|
||||||
"playwright": "^1.54.1",
|
"playwright": "^1.54.1",
|
||||||
"rimraf": "^6.0.1",
|
"rimraf": "^6.0.1",
|
||||||
"typescript": "^5.8.3",
|
"typescript": "^5.8.3",
|
||||||
"vitest": "^1.6.1"
|
"vitest": "^3.2.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/preset-typescript": "^7.27.1",
|
|
||||||
"@types/node": "^22.16.3",
|
"@types/node": "^22.16.3",
|
||||||
"comlink": "^4.4.2",
|
"three": "^0.178.0"
|
||||||
"import-meta-resolve": "^4.1.0",
|
|
||||||
"three": "^0.178.0",
|
|
||||||
"vite": "^5.0.0",
|
|
||||||
"webworker": "^0.8.4"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1508
pnpm-lock.yaml
generated
Normal file
1508
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,12 +1,12 @@
|
|||||||
import { describe, it, expect, test } from 'vitest';
|
import { test, it, expect } from 'vitest';
|
||||||
import { DemoParser } from '../samples/demoParser';
|
import { DemoParser } from '../samples/demoParser';
|
||||||
import { ProcessorModule, StepControllerProcessor } from '../src/device';
|
// import { ProcessorModule, StepControllerProcessor } from '../src/device';
|
||||||
import { ProcessorManager } from '../src/device';
|
// import { ProcessorManager } from '../src/device';
|
||||||
import { demoHandleGroupCutting } from '../samples/demoDatahandle/demoDataHandle1';
|
// import { demoHandleGroupCutting } from '../samples/demoDatahandle/demoDataHandle1';
|
||||||
import testJson from "./test.json"
|
// import testJson from "./test.json"
|
||||||
import { Worker, parentPort } from 'worker_threads';
|
// import { Worker, parentPort } from 'worker_threads';
|
||||||
import { UniversalWorker } from '../samples/WorkerHelper';
|
// import { UniversalWorker } from '../samples/WorkerHelper';
|
||||||
describe('demoParser', () => {
|
test('demoParser', () => {
|
||||||
const text = `FSTART
|
const text = `FSTART
|
||||||
TD 5
|
TD 5
|
||||||
G0 X100 Y100 Z10 F8000
|
G0 X100 Y100 Z10 F8000
|
||||||
@@ -23,163 +23,163 @@ FEND
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('data', async () => {
|
// describe('data', async () => {
|
||||||
const sysConfig = {
|
// const sysConfig = {
|
||||||
placeStyle: 1,
|
// placeStyle: 1,
|
||||||
boardWidth: 2440,
|
// boardWidth: 2440,
|
||||||
boardLength: 1220,
|
// boardLength: 1220,
|
||||||
// 测试刀库数据
|
// // 测试刀库数据
|
||||||
knifeList: [knifeData, knifeData1, knifeData2]
|
// knifeList: [knifeData, knifeData1, knifeData2]
|
||||||
}
|
// }
|
||||||
const json = testJson
|
// const json = testJson
|
||||||
// 创建处理器集合
|
// // 创建处理器集合
|
||||||
const processorManager = new ProcessorManager<any, any>();
|
// const processorManager = new ProcessorManager<any, any>();
|
||||||
// 这里省略了 选择处理器的环节 --这里选了demo开料机
|
// // 这里省略了 选择处理器的环节 --这里选了demo开料机
|
||||||
const cuttingHandle = new demoHandleGroupCutting()
|
// const cuttingHandle = new demoHandleGroupCutting()
|
||||||
// 注册处理器
|
// // 注册处理器
|
||||||
processorManager.registerProcessor(cuttingHandle.processorName, cuttingHandle.processor)
|
// processorManager.registerProcessor(cuttingHandle.processorName, cuttingHandle.processor)
|
||||||
// 使用XX处理器 会返回激活【正在使用】的 处理器
|
// // 使用XX处理器 会返回激活【正在使用】的 处理器
|
||||||
let processor = processorManager.useProcessor(cuttingHandle.processorName)
|
// let processor = processorManager.useProcessor(cuttingHandle.processorName)
|
||||||
// 或者 这样 获取 正在使用的处理器 注:若未执行useProcessor 将会返回 undefind
|
// // 或者 这样 获取 正在使用的处理器 注:若未执行useProcessor 将会返回 undefind
|
||||||
// processor = processorManager.getCurrentProcessor()
|
// // processor = processorManager.getCurrentProcessor()
|
||||||
/** 处理器配置加载 */
|
// /** 处理器配置加载 */
|
||||||
processor.updateModuleConfig(sysConfig)
|
// processor.updateModuleConfig(sysConfig)
|
||||||
const res = await processor.process(json)
|
// const res = await processor.process(json)
|
||||||
// console.log('处理器所有流程都结束了', res);
|
// // console.log('处理器所有流程都结束了', res);
|
||||||
})
|
// })
|
||||||
|
//
|
||||||
/** demo 刀具数据 */
|
// /** demo 刀具数据 */
|
||||||
export const knifeData = {
|
// export const knifeData = {
|
||||||
"isEnabled": true,
|
// "isEnabled": true,
|
||||||
"axleId": 2,
|
// "axleId": 2,
|
||||||
"knifeId": 2,
|
// "knifeId": 2,
|
||||||
"processFace": "",
|
// "processFace": "",
|
||||||
"knifeName": "T1",
|
// "knifeName": "T1",
|
||||||
"knifeType": 3,
|
// "knifeType": 3,
|
||||||
"ability": [
|
// "ability": [
|
||||||
5
|
// 5
|
||||||
],
|
// ],
|
||||||
"diameter": 5,
|
// "diameter": 5,
|
||||||
"length": 20,
|
// "length": 20,
|
||||||
"sawThiness": 7,
|
// "sawThiness": 7,
|
||||||
"sawDirection": 2,
|
// "sawDirection": 2,
|
||||||
"processDirection": 4,
|
// "processDirection": 4,
|
||||||
"speed": 0,
|
// "speed": 0,
|
||||||
"stepDepth": 0,
|
// "stepDepth": 0,
|
||||||
"offsetX": 0,
|
// "offsetX": 0,
|
||||||
"offsetY": 0,
|
// "offsetY": 0,
|
||||||
"offsetZ": 0,
|
// "offsetZ": 0,
|
||||||
"baseX": 0,
|
// "baseX": 0,
|
||||||
"baseY": 0,
|
// "baseY": 0,
|
||||||
"isModularDrill": false,
|
// "isModularDrill": false,
|
||||||
"isPreStartEnabled": false,
|
// "isPreStartEnabled": false,
|
||||||
"preStartAheadActionCount": 5,
|
// "preStartAheadActionCount": 5,
|
||||||
"isPreStartToolChangeDelay": false,
|
// "isPreStartToolChangeDelay": false,
|
||||||
"preStartToolChangeDelayCode": "",
|
// "preStartToolChangeDelayCode": "",
|
||||||
"isAxisStartCodePostpost": false,
|
// "isAxisStartCodePostpost": false,
|
||||||
"isAxisStopCodePrepose": false,
|
// "isAxisStopCodePrepose": false,
|
||||||
"drillGroupCode": "",
|
// "drillGroupCode": "",
|
||||||
"axisStartCode": "M03 S18000\n",
|
// "axisStartCode": "M03 S18000\n",
|
||||||
"knifeStartCode": `M06 T1\nG43 H1\n`,
|
// "knifeStartCode": `M06 T1\nG43 H1\n`,
|
||||||
"drillGroupStartCode": "T1",
|
// "drillGroupStartCode": "T1",
|
||||||
"drillGroupEndCode": "",
|
// "drillGroupEndCode": "",
|
||||||
"knifeStopCode": "",
|
// "knifeStopCode": "",
|
||||||
"axisStopCode": "M05\n",
|
// "axisStopCode": "M05\n",
|
||||||
"preStartActionDeferCode": "",
|
// "preStartActionDeferCode": "",
|
||||||
"useHolesGroupKnife": false,
|
// "useHolesGroupKnife": false,
|
||||||
"preStartActionStepsLimit": "",
|
// "preStartActionStepsLimit": "",
|
||||||
"knifeNo": "",
|
// "knifeNo": "",
|
||||||
"editable": true,
|
// "editable": true,
|
||||||
"isDefaultCutKnife": false,
|
// "isDefaultCutKnife": false,
|
||||||
"isPreStartChangeKnifeDefer": false
|
// "isPreStartChangeKnifeDefer": false
|
||||||
}
|
// }
|
||||||
export const knifeData1 = {
|
// export const knifeData1 = {
|
||||||
"isEnabled": true,
|
// "isEnabled": true,
|
||||||
"axleId": 2,
|
// "axleId": 2,
|
||||||
"knifeId": 2,
|
// "knifeId": 2,
|
||||||
"processFace": "",
|
// "processFace": "",
|
||||||
"knifeName": "T2",
|
// "knifeName": "T2",
|
||||||
"knifeType": 3,
|
// "knifeType": 3,
|
||||||
"ability": [
|
// "ability": [
|
||||||
5
|
// 5
|
||||||
],
|
// ],
|
||||||
"diameter": 6,
|
// "diameter": 6,
|
||||||
"length": 20,
|
// "length": 20,
|
||||||
"sawThiness": 7,
|
// "sawThiness": 7,
|
||||||
"sawDirection": 2,
|
// "sawDirection": 2,
|
||||||
"processDirection": 4,
|
// "processDirection": 4,
|
||||||
"speed": 0,
|
// "speed": 0,
|
||||||
"stepDepth": 0,
|
// "stepDepth": 0,
|
||||||
"offsetX": 0,
|
// "offsetX": 0,
|
||||||
"offsetY": 0,
|
// "offsetY": 0,
|
||||||
"offsetZ": 0,
|
// "offsetZ": 0,
|
||||||
"baseX": 0,
|
// "baseX": 0,
|
||||||
"baseY": 0,
|
// "baseY": 0,
|
||||||
"isModularDrill": false,
|
// "isModularDrill": false,
|
||||||
"isPreStartEnabled": false,
|
// "isPreStartEnabled": false,
|
||||||
"preStartAheadActionCount": 5,
|
// "preStartAheadActionCount": 5,
|
||||||
"isPreStartToolChangeDelay": false,
|
// "isPreStartToolChangeDelay": false,
|
||||||
"preStartToolChangeDelayCode": "",
|
// "preStartToolChangeDelayCode": "",
|
||||||
"isAxisStartCodePostpost": false,
|
// "isAxisStartCodePostpost": false,
|
||||||
"isAxisStopCodePrepose": false,
|
// "isAxisStopCodePrepose": false,
|
||||||
"drillGroupCode": "",
|
// "drillGroupCode": "",
|
||||||
"axisStartCode": "M03 S18000\n",
|
// "axisStartCode": "M03 S18000\n",
|
||||||
"knifeStartCode": `M06 T2\nG43 H2\n`,
|
// "knifeStartCode": `M06 T2\nG43 H2\n`,
|
||||||
"drillGroupStartCode": "T2",
|
// "drillGroupStartCode": "T2",
|
||||||
"drillGroupEndCode": "",
|
// "drillGroupEndCode": "",
|
||||||
"knifeStopCode": "",
|
// "knifeStopCode": "",
|
||||||
"axisStopCode": "M05\n",
|
// "axisStopCode": "M05\n",
|
||||||
"preStartActionDeferCode": "",
|
// "preStartActionDeferCode": "",
|
||||||
"useHolesGroupKnife": false,
|
// "useHolesGroupKnife": false,
|
||||||
"preStartActionStepsLimit": "",
|
// "preStartActionStepsLimit": "",
|
||||||
"knifeNo": "",
|
// "knifeNo": "",
|
||||||
"editable": true,
|
// "editable": true,
|
||||||
"isDefaultCutKnife": false,
|
// "isDefaultCutKnife": false,
|
||||||
"isPreStartChangeKnifeDefer": false
|
// "isPreStartChangeKnifeDefer": false
|
||||||
}
|
// }
|
||||||
export const knifeData2 = {
|
// export const knifeData2 = {
|
||||||
"isEnabled": true,
|
// "isEnabled": true,
|
||||||
"axleId": 2,
|
// "axleId": 2,
|
||||||
"knifeId": 2,
|
// "knifeId": 2,
|
||||||
"processFace": "",
|
// "processFace": "",
|
||||||
"knifeName": "T3",
|
// "knifeName": "T3",
|
||||||
"knifeType": 3,
|
// "knifeType": 3,
|
||||||
"ability": [
|
// "ability": [
|
||||||
5
|
// 5
|
||||||
],
|
// ],
|
||||||
"diameter": 6,
|
// "diameter": 6,
|
||||||
"length": 20,
|
// "length": 20,
|
||||||
"sawThiness": 7,
|
// "sawThiness": 7,
|
||||||
"sawDirection": 2,
|
// "sawDirection": 2,
|
||||||
"processDirection": 4,
|
// "processDirection": 4,
|
||||||
"speed": 0,
|
// "speed": 0,
|
||||||
"stepDepth": 0,
|
// "stepDepth": 0,
|
||||||
"offsetX": 0,
|
// "offsetX": 0,
|
||||||
"offsetY": 0,
|
// "offsetY": 0,
|
||||||
"offsetZ": 0,
|
// "offsetZ": 0,
|
||||||
"baseX": 0,
|
// "baseX": 0,
|
||||||
"baseY": 0,
|
// "baseY": 0,
|
||||||
"isModularDrill": false,
|
// "isModularDrill": false,
|
||||||
"isPreStartEnabled": false,
|
// "isPreStartEnabled": false,
|
||||||
"preStartAheadActionCount": 5,
|
// "preStartAheadActionCount": 5,
|
||||||
"isPreStartToolChangeDelay": false,
|
// "isPreStartToolChangeDelay": false,
|
||||||
"preStartToolChangeDelayCode": "",
|
// "preStartToolChangeDelayCode": "",
|
||||||
"isAxisStartCodePostpost": false,
|
// "isAxisStartCodePostpost": false,
|
||||||
"isAxisStopCodePrepose": false,
|
// "isAxisStopCodePrepose": false,
|
||||||
"drillGroupCode": "",
|
// "drillGroupCode": "",
|
||||||
|
//
|
||||||
"axisStartCode": "M03 S18000\n",
|
// "axisStartCode": "M03 S18000\n",
|
||||||
"knifeStartCode": `M06 T2\nG43 H2\n`,
|
// "knifeStartCode": `M06 T2\nG43 H2\n`,
|
||||||
"drillGroupStartCode": "T3",
|
// "drillGroupStartCode": "T3",
|
||||||
"drillGroupEndCode": "",
|
// "drillGroupEndCode": "",
|
||||||
"knifeStopCode": "",
|
// "knifeStopCode": "",
|
||||||
"axisStopCode": "M05\n",
|
// "axisStopCode": "M05\n",
|
||||||
|
//
|
||||||
"preStartActionDeferCode": "",
|
// "preStartActionDeferCode": "",
|
||||||
"useHolesGroupKnife": false,
|
// "useHolesGroupKnife": false,
|
||||||
"preStartActionStepsLimit": "",
|
// "preStartActionStepsLimit": "",
|
||||||
"knifeNo": "",
|
// "knifeNo": "",
|
||||||
"editable": true,
|
// "editable": true,
|
||||||
"isDefaultCutKnife": false,
|
// "isDefaultCutKnife": false,
|
||||||
"isPreStartChangeKnifeDefer": false
|
// "isPreStartChangeKnifeDefer": false
|
||||||
}
|
// }
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
// },
|
// },
|
||||||
// "include": ["src/**/*", "tests/**/*"], // 包含测试文件
|
// "include": ["src/**/*", "tests/**/*"], // 包含测试文件
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"types": [],
|
"types": ["@vitest/browser/providers/playwright"],
|
||||||
"resolveJsonModule": true, // 允许导入 .json 文件
|
"resolveJsonModule": true, // 允许导入 .json 文件
|
||||||
"esModuleInterop": true, // 确保 CommonJS/ESM 兼容
|
"esModuleInterop": true, // 确保 CommonJS/ESM 兼容
|
||||||
"module": "ESNext", // 推荐使用 ESM
|
"module": "ESNext", // 推荐使用 ESM
|
||||||
|
11
vitest-example/HelloWorld.test.ts
Normal file
11
vitest-example/HelloWorld.test.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { expect, test } from 'vitest'
|
||||||
|
import { getByText } from '@testing-library/dom'
|
||||||
|
import HelloWorld from './HelloWorld.js'
|
||||||
|
|
||||||
|
test('renders name', () => {
|
||||||
|
const parent = HelloWorld({ name: 'Vitest' })
|
||||||
|
document.body.appendChild(parent)
|
||||||
|
|
||||||
|
const element = getByText(parent, 'Hello Vitest!')
|
||||||
|
expect(element).toBeInTheDocument()
|
||||||
|
})
|
9
vitest-example/HelloWorld.ts
Normal file
9
vitest-example/HelloWorld.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export default function HelloWorld({ name }: { name: string }): HTMLDivElement {
|
||||||
|
const parent = document.createElement('div')
|
||||||
|
|
||||||
|
const h1 = document.createElement('h1')
|
||||||
|
h1.textContent = 'Hello ' + name + '!'
|
||||||
|
parent.appendChild(h1)
|
||||||
|
|
||||||
|
return parent
|
||||||
|
}
|
14
vitest.config.ts
Normal file
14
vitest.config.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { defineConfig } from 'vitest/config'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
browser: {
|
||||||
|
enabled: true,
|
||||||
|
provider: 'playwright',
|
||||||
|
// https://vitest.dev/guide/browser/playwright
|
||||||
|
instances: [
|
||||||
|
{ browser: 'chromium' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
Reference in New Issue
Block a user