From 7e9c2aa6aed2b7526166d4b4a145658eefa8d1c0 Mon Sep 17 00:00:00 2001 From: chaxus Date: Sat, 4 Nov 2023 16:52:25 +0800 Subject: [PATCH] fix: playwright test port --- .../docs/src/article/astParse/tokenizer.md | 2 +- packages/docs/src/ranui/index.md | 2 +- packages/ml/client/index.tsx | 48 ++++++++++--------- packages/ml/client/lib.ts | 9 ++++ packages/ml/server/index.ts | 2 +- packages/ranui-react/bin/test.sh | 7 +-- packages/ranui-react/build/config.ts | 5 ++ packages/ranui-react/playwright.config.ts | 5 +- packages/ranui-react/tests/button.spec.ts | 2 +- packages/ranui-react/vite.config.ts | 4 ++ packages/ranui/bin/test.sh | 7 +-- packages/ranui/build/config.ts | 5 ++ packages/ranui/index.html | 4 +- packages/ranui/index.ts | 2 +- packages/ranui/playwright.config.ts | 6 +-- packages/ranui/tests/button.spec.ts | 2 +- packages/ranui/tsconfig.json | 2 +- packages/ranui/vite.config.ts | 8 +++- packages/ranuts/index.ts | 4 +- packages/ranuts/src/astParser/Tokenizer.ts | 2 +- packages/ranuts/src/utils/index.ts | 6 ++- packages/ranuts/tsconfig.json | 1 - 22 files changed, 81 insertions(+), 54 deletions(-) create mode 100644 packages/ml/client/lib.ts create mode 100644 packages/ranui-react/build/config.ts create mode 100644 packages/ranui/build/config.ts diff --git a/packages/docs/src/article/astParse/tokenizer.md b/packages/docs/src/article/astParse/tokenizer.md index e2a008389..d6aefd2be 100644 --- a/packages/docs/src/article/astParse/tokenizer.md +++ b/packages/docs/src/article/astParse/tokenizer.md @@ -421,7 +421,7 @@ type SingleCharTokens = '(' | ')' | '{' | '}' | '='; // 单字符到 Token 生成器的映射 const KNOWN_SINGLE_CHAR_TOKENS = new Map< SingleCharTokens, - (typeof TOKENS_GENERATOR)[keyof typeof TOKENS_GENERATOR] + typeof TOKENS_GENERATOR[keyof typeof TOKENS_GENERATOR] >([ ['(', TOKENS_GENERATOR.leftParen], [')', TOKENS_GENERATOR.rightParen], diff --git a/packages/docs/src/ranui/index.md b/packages/docs/src/ranui/index.md index 4f85a4425..d858a47e6 100644 --- a/packages/docs/src/ranui/index.md +++ b/packages/docs/src/ranui/index.md @@ -323,7 +323,7 @@ import 'ranui'; /* #input 指的是当前的自定义元素 ::part(input) 中的input指的是,当前自定义元素内部的 Shadow DOM 元素的类 */ #input::part(input) { - width:100px + width: 100px; } ``` diff --git a/packages/ml/client/index.tsx b/packages/ml/client/index.tsx index eba0cd52e..d48fc1009 100644 --- a/packages/ml/client/index.tsx +++ b/packages/ml/client/index.tsx @@ -3,35 +3,39 @@ import { createRoot } from 'react-dom/client'; import { BrowserRouter } from 'react-router-dom'; import * as tf from '@tensorflow/tfjs'; -// Define a model for linear regression. -const model = tf.sequential(); -model.add(tf.layers.dense({ units: 1, inputShape: [1] })); - -// Prepare the model for training: Specify the loss and the optimizer. -model.compile({ loss: 'meanSquaredError', optimizer: 'sgd' }); - -// Generate some synthetic data for training. -const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]); -const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]); - -// Train the model using the data. -model.fit(xs, ys).then(() => { - // Use the model to do inference on a data point the model hasn't seen before: - const result = model.predict(tf.tensor2d([5], [1, 1])); - if (Array.isArray(result)) { - result.forEach((item) => item.print()); - } else { - result.print(); - } -}); - const App = () => { + // Define a model for linear regression. + const model = tf.sequential(); + model.add(tf.layers.dense({ units: 1, inputShape: [1] })); + + // Prepare the model for training: Specify the loss and the optimizer. + model.compile({ loss: 'meanSquaredError', optimizer: 'sgd' }); + + // Generate some synthetic data for training. + const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]); + const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]); + + // Train the model using the data. + model.fit(xs, ys).then(() => { + // Use the model to do inference on a data point the model hasn't seen before: + const result = model.predict(tf.tensor2d([5], [1, 1])); + if (Array.isArray(result)) { + result.forEach((item) => item.print()); + } else { + result.print(); + } + }); + return (

tf version:

{JSON.stringify(tf.version)}

tf backend:

{JSON.stringify(tf.getBackend())}
+

tf memory

+
{JSON.stringify(tf.memory())}
+

张量的数量

+
Number of tensor in memory: {JSON.stringify(tf.memory().numTensors)}
); }; diff --git a/packages/ml/client/lib.ts b/packages/ml/client/lib.ts new file mode 100644 index 000000000..a475e0a09 --- /dev/null +++ b/packages/ml/client/lib.ts @@ -0,0 +1,9 @@ +import * as tf from '@tensorflow/tfjs'; + +export function createLotsOfTensors(): void { + for (let i = 0; i < 1000; i++) { + const a = tf.tensor1d([1, 2, 3]) + const b = tf.scalar(i) + a.mul(b).print() + } +} \ No newline at end of file diff --git a/packages/ml/server/index.ts b/packages/ml/server/index.ts index 3ee95c8fd..ea9dec98c 100644 --- a/packages/ml/server/index.ts +++ b/packages/ml/server/index.ts @@ -20,4 +20,4 @@ model.fit(xs, ys).then(() => { } else { result.print(); } -}); \ No newline at end of file +}); diff --git a/packages/ranui-react/bin/test.sh b/packages/ranui-react/bin/test.sh index 07a0c4dd3..bcd702ae8 100644 --- a/packages/ranui-react/bin/test.sh +++ b/packages/ranui-react/bin/test.sh @@ -1,3 +1,4 @@ -npx playwright install -npx playwright install-deps -npx playwright test \ No newline at end of file +bin=./node_modules/.bin +$bin/playwright install +$bin/playwright install-deps +$bin/playwright test \ No newline at end of file diff --git a/packages/ranui-react/build/config.ts b/packages/ranui-react/build/config.ts new file mode 100644 index 000000000..7c6d874c1 --- /dev/null +++ b/packages/ranui-react/build/config.ts @@ -0,0 +1,5 @@ +export const TIME_OUT = 1000; + +export const PORT = 5173 + +export const DEV_SERVER = `http://localhost:${PORT}/`; \ No newline at end of file diff --git a/packages/ranui-react/playwright.config.ts b/packages/ranui-react/playwright.config.ts index c51e21d45..4ddda7c65 100644 --- a/packages/ranui-react/playwright.config.ts +++ b/packages/ranui-react/playwright.config.ts @@ -1,8 +1,5 @@ import { defineConfig, devices } from '@playwright/test'; - -export const TIME_OUT = 6000; - -export const DEV_SERVER = 'http://localhost:5124/'; +import { DEV_SERVER } from './build/config'; /** * Read environment variables from file. diff --git a/packages/ranui-react/tests/button.spec.ts b/packages/ranui-react/tests/button.spec.ts index 5927e2324..f5c5a0397 100644 --- a/packages/ranui-react/tests/button.spec.ts +++ b/packages/ranui-react/tests/button.spec.ts @@ -1,5 +1,5 @@ import { expect, test } from '@playwright/test'; -import { DEV_SERVER, TIME_OUT } from '../playwright.config'; +import { DEV_SERVER, TIME_OUT } from '../build/config'; test('button', async ({ page }) => { setTimeout(async () => { diff --git a/packages/ranui-react/vite.config.ts b/packages/ranui-react/vite.config.ts index 4f5308abb..ad28ad4d5 100644 --- a/packages/ranui-react/vite.config.ts +++ b/packages/ranui-react/vite.config.ts @@ -4,6 +4,7 @@ import type { BuildOptions, UserConfig } from 'vite'; import { defineConfig } from 'vite'; import dts from 'vite-plugin-dts'; import react from '@vitejs/plugin-react'; +import { PORT } from './build/config'; const __filename = fileURLToPath(import.meta.url); @@ -37,6 +38,9 @@ export const viteConfig: UserConfig = { '@/utils': resolve(__dirname, 'utils/'), }, extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'], + }, + server: { + port: PORT } }; diff --git a/packages/ranui/bin/test.sh b/packages/ranui/bin/test.sh index 07a0c4dd3..bcd702ae8 100644 --- a/packages/ranui/bin/test.sh +++ b/packages/ranui/bin/test.sh @@ -1,3 +1,4 @@ -npx playwright install -npx playwright install-deps -npx playwright test \ No newline at end of file +bin=./node_modules/.bin +$bin/playwright install +$bin/playwright install-deps +$bin/playwright test \ No newline at end of file diff --git a/packages/ranui/build/config.ts b/packages/ranui/build/config.ts new file mode 100644 index 000000000..7c6d874c1 --- /dev/null +++ b/packages/ranui/build/config.ts @@ -0,0 +1,5 @@ +export const TIME_OUT = 1000; + +export const PORT = 5173 + +export const DEV_SERVER = `http://localhost:${PORT}/`; \ No newline at end of file diff --git a/packages/ranui/index.html b/packages/ranui/index.html index 7a02dcae2..22eaf9794 100644 --- a/packages/ranui/index.html +++ b/packages/ranui/index.html @@ -91,8 +91,8 @@

Hello RanUI

-

Select

- +

Select

+ Mike Tom Lucy diff --git a/packages/ranui/index.ts b/packages/ranui/index.ts index b8a5f023d..3ab49d6b6 100644 --- a/packages/ranui/index.ts +++ b/packages/ranui/index.ts @@ -12,7 +12,7 @@ export * as tab from '@/components/tab'; export * as radar from '@/components/radar'; export * as video from '@/components/video'; export * as modal from '@/components/modal'; -export * as select from '@/components/select' +export * as select from '@/components/select'; if (typeof document !== 'undefined') { const style = document.createElement('style'); diff --git a/packages/ranui/playwright.config.ts b/packages/ranui/playwright.config.ts index c51e21d45..26021a2bc 100644 --- a/packages/ranui/playwright.config.ts +++ b/packages/ranui/playwright.config.ts @@ -1,9 +1,5 @@ import { defineConfig, devices } from '@playwright/test'; - -export const TIME_OUT = 6000; - -export const DEV_SERVER = 'http://localhost:5124/'; - +import { DEV_SERVER } from './build/config'; /** * Read environment variables from file. * https://github.com/motdotla/dotenv diff --git a/packages/ranui/tests/button.spec.ts b/packages/ranui/tests/button.spec.ts index 5927e2324..f5c5a0397 100644 --- a/packages/ranui/tests/button.spec.ts +++ b/packages/ranui/tests/button.spec.ts @@ -1,5 +1,5 @@ import { expect, test } from '@playwright/test'; -import { DEV_SERVER, TIME_OUT } from '../playwright.config'; +import { DEV_SERVER, TIME_OUT } from '../build/config'; test('button', async ({ page }) => { setTimeout(async () => { diff --git a/packages/ranui/tsconfig.json b/packages/ranui/tsconfig.json index c515f4332..6d67241c4 100644 --- a/packages/ranui/tsconfig.json +++ b/packages/ranui/tsconfig.json @@ -20,7 +20,7 @@ "@/assets/*": ["assets/*"], "@/components/*": ["components/*"], "@/plugins/*": ["plugins/*"], - "@/utils/*": ["utils/*"] + "@/utils/*": ["utils/*"], } } } diff --git a/packages/ranui/vite.config.ts b/packages/ranui/vite.config.ts index 6983a64b6..a3052e926 100644 --- a/packages/ranui/vite.config.ts +++ b/packages/ranui/vite.config.ts @@ -1,11 +1,12 @@ import path, { resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; -import type { BuildOptions, UserConfig } from 'vite'; +import type { BuildOptions, PluginOption, UserConfig } from 'vite'; import { defineConfig } from 'vite'; import dts from 'vite-plugin-dts'; import { visualizer } from 'rollup-plugin-visualizer'; import loadStyle from './plugins/load-style'; import loadSvg from './plugins/load-svg'; +import { PORT } from './build/config'; const __filename = fileURLToPath(import.meta.url); @@ -179,7 +180,7 @@ export const viteConfig: UserConfig = { visualizer({ emitFile: false, filename: 'report/build-stats.html', - }), + }) as PluginOption, ], resolve: { alias: { @@ -200,6 +201,9 @@ export const viteConfig: UserConfig = { generateScopedName: '[name--[local]--[hash:base64:5]]', }, }, + server: { + port: PORT + } }; export default defineConfig(viteConfig); diff --git a/packages/ranuts/index.ts b/packages/ranuts/index.ts index 5e5614eb0..65986c589 100644 --- a/packages/ranuts/index.ts +++ b/packages/ranuts/index.ts @@ -35,7 +35,7 @@ import { retain, scriptOnLoad, throttle, - timestampToTime + timestampToTime, } from '@/utils'; import type { Noop } from '@/utils'; import { MimeType, getMime, setMime } from '@/server/mimeType'; @@ -86,7 +86,7 @@ export { createObjectURL, addClassToElement, AudioRecorder, - removeClassToElement + removeClassToElement, }; export const EventEmitter = SyncHook; diff --git a/packages/ranuts/src/astParser/Tokenizer.ts b/packages/ranuts/src/astParser/Tokenizer.ts index f5eeed0dc..a6ecbf7a1 100644 --- a/packages/ranuts/src/astParser/Tokenizer.ts +++ b/packages/ranuts/src/astParser/Tokenizer.ts @@ -204,7 +204,7 @@ type SingleCharTokens = '(' | ')' | '{' | '}' | '.' | ';' | ',' | '*' | '='; // 单字符到 Token 生成器的映射 const KNOWN_SINGLE_CHAR_TOKENS = new Map< SingleCharTokens, - (typeof TOKENS_GENERATOR)[keyof typeof TOKENS_GENERATOR] + typeof TOKENS_GENERATOR[keyof typeof TOKENS_GENERATOR] >([ ['(', TOKENS_GENERATOR.leftParen], [')', TOKENS_GENERATOR.rightParen], diff --git a/packages/ranuts/src/utils/index.ts b/packages/ranuts/src/utils/index.ts index 3109c0674..677cfe30d 100644 --- a/packages/ranuts/src/utils/index.ts +++ b/packages/ranuts/src/utils/index.ts @@ -665,10 +665,12 @@ export const addClassToElement = (element: Element, addClass: string): void => { * @param {Element} element * @param {string} removeClass */ -export const removeClassToElement = (element: Element, removeClass: string): void => { +export const removeClassToElement = ( + element: Element, + removeClass: string, +): void => { const classList = element.classList; if (classList.contains(removeClass)) { classList.remove(removeClass); } }; - diff --git a/packages/ranuts/tsconfig.json b/packages/ranuts/tsconfig.json index aa2ea0846..8baee4056 100644 --- a/packages/ranuts/tsconfig.json +++ b/packages/ranuts/tsconfig.json @@ -1,4 +1,3 @@ - { "include": ["src", "test", "plugins", "**/*.ts"], "exclude": ["node_modules", "dist"],