Skip to content

Commit

Permalink
fix: playwright test port
Browse files Browse the repository at this point in the history
  • Loading branch information
chaxus committed Nov 4, 2023
1 parent a66d1b1 commit 7e9c2aa
Show file tree
Hide file tree
Showing 22 changed files with 81 additions and 54 deletions.
2 changes: 1 addition & 1 deletion packages/docs/src/article/astParse/tokenizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/ranui/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ import 'ranui';
/* #input 指的是当前的自定义元素
::part(input) 中的input指的是,当前自定义元素内部的 Shadow DOM 元素的类 */
#input::part(input) {
width:100px
width: 100px;
}
</style>
```
Expand Down
48 changes: 26 additions & 22 deletions packages/ml/client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div>
<h2>tf version:</h2>
<div>{JSON.stringify(tf.version)}</div>
<h2>tf backend:</h2>
<div>{JSON.stringify(tf.getBackend())}</div>
<h2>tf memory</h2>
<div>{JSON.stringify(tf.memory())}</div>
<h3>张量的数量</h3>
<div>Number of tensor in memory: {JSON.stringify(tf.memory().numTensors)}</div>
</div>
);
};
Expand Down
9 changes: 9 additions & 0 deletions packages/ml/client/lib.ts
Original file line number Diff line number Diff line change
@@ -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()
}
}
2 changes: 1 addition & 1 deletion packages/ml/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ model.fit(xs, ys).then(() => {
} else {
result.print();
}
});
});
7 changes: 4 additions & 3 deletions packages/ranui-react/bin/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
npx playwright install
npx playwright install-deps
npx playwright test
bin=./node_modules/.bin
$bin/playwright install
$bin/playwright install-deps
$bin/playwright test
5 changes: 5 additions & 0 deletions packages/ranui-react/build/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const TIME_OUT = 1000;

export const PORT = 5173

export const DEV_SERVER = `http://localhost:${PORT}/`;
5 changes: 1 addition & 4 deletions packages/ranui-react/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/ranui-react/tests/button.spec.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/ranui-react/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -37,6 +38,9 @@ export const viteConfig: UserConfig = {
'@/utils': resolve(__dirname, 'utils/'),
},
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'],
},
server: {
port: PORT
}
};

Expand Down
7 changes: 4 additions & 3 deletions packages/ranui/bin/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
npx playwright install
npx playwright install-deps
npx playwright test
bin=./node_modules/.bin
$bin/playwright install
$bin/playwright install-deps
$bin/playwright test
5 changes: 5 additions & 0 deletions packages/ranui/build/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const TIME_OUT = 1000;

export const PORT = 5173

export const DEV_SERVER = `http://localhost:${PORT}/`;
4 changes: 2 additions & 2 deletions packages/ranui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@

<body>
<h1>Hello RanUI</h1>
<h2 >Select</h2>
<r-select style="width: 120px;height:40px">
<h2>Select</h2>
<r-select style="width: 120px; height: 40px">
<r-option value="185">Mike</r-option>
<r-option value="186">Tom</r-option>
<r-option value="187">Lucy</r-option>
Expand Down
2 changes: 1 addition & 1 deletion packages/ranui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 1 addition & 5 deletions packages/ranui/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/ranui/tests/button.spec.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ranui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@/assets/*": ["assets/*"],
"@/components/*": ["components/*"],
"@/plugins/*": ["plugins/*"],
"@/utils/*": ["utils/*"]
"@/utils/*": ["utils/*"],
}
}
}
8 changes: 6 additions & 2 deletions packages/ranui/vite.config.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down Expand Up @@ -179,7 +180,7 @@ export const viteConfig: UserConfig = {
visualizer({
emitFile: false,
filename: 'report/build-stats.html',
}),
}) as PluginOption,
],
resolve: {
alias: {
Expand All @@ -200,6 +201,9 @@ export const viteConfig: UserConfig = {
generateScopedName: '[name--[local]--[hash:base64:5]]',
},
},
server: {
port: PORT
}
};

export default defineConfig(viteConfig);
4 changes: 2 additions & 2 deletions packages/ranuts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
retain,
scriptOnLoad,
throttle,
timestampToTime
timestampToTime,
} from '@/utils';
import type { Noop } from '@/utils';
import { MimeType, getMime, setMime } from '@/server/mimeType';
Expand Down Expand Up @@ -86,7 +86,7 @@ export {
createObjectURL,
addClassToElement,
AudioRecorder,
removeClassToElement
removeClassToElement,
};

export const EventEmitter = SyncHook;
2 changes: 1 addition & 1 deletion packages/ranuts/src/astParser/Tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
6 changes: 4 additions & 2 deletions packages/ranuts/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

1 change: 0 additions & 1 deletion packages/ranuts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"include": ["src", "test", "plugins", "**/*.ts"],
"exclude": ["node_modules", "dist"],
Expand Down

0 comments on commit 7e9c2aa

Please sign in to comment.