Skip to content

Commit

Permalink
feat: add raw-load-data
Browse files Browse the repository at this point in the history
  • Loading branch information
hexf00 committed Mar 16, 2024
1 parent 3443b11 commit d0a33e1
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ on:
branches: [ main ]
jobs:
test:
timeout-minutes: 60
timeout-minutes: 300
continue-on-error: true # 允许失败后继续执行
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ run n times
pnpm benchmark --repeat=3
pnpm benchmark --repeat=10
```

run with a regular filter, only run the test with the name contains 'raw load'
```bash
pnpm benchmark -g "raw load"
```

## How to write a new test

```typescript
Expand Down
1 change: 1 addition & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { defineConfig, devices } from '@playwright/test';
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
timeout: 10 * 1000, // 10 seconds
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
Expand Down
9 changes: 2 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,5 @@ univer.registerPlugin(UniverSheetsNumfmtPlugin);
univer.registerPlugin(UniverFormulaEnginePlugin);
univer.registerPlugin(UniverSheetsFormulaPlugin);

// create univer sheet instance
univer.createUniverSheet({});

const univerAPI = FUniver.newAPI(univer);

window.univerAPI = univerAPI;
window.univer = univer;
window.univer = univer;
window.FUniver = FUniver;
2 changes: 1 addition & 1 deletion src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Univer } from "@univerjs/core";

declare global {
interface Window {
FUniver: typeof FUniver;
univer: Univer;
univerAPI: FUniver;
}
}
30 changes: 20 additions & 10 deletions tests/load-data.spec.ts → tests/sheets/facade-set-values.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,37 @@ test.beforeEach(async ({ context }) => {
});

const createTest = (row: number, col: number) => {
test(`load ${row}*${col} data`, async ({ page }) => {
test(`facade setValues ${row}*${col} data`, async ({ page }) => {
await page.goto('/');

const jsHandle = await page.evaluateHandle('window');

await test.step('create data', async () => {
await page.evaluate(({ row, col, window }: any) => {
window.data = window.createData(row, col);
// create univer sheet instance
window.univer.createUniverSheet({});
const univerAPI = window.FUniver.newAPI(window.univer);
window.univerAPI = univerAPI;
}, { row, col, window: jsHandle });
})

await test.step('timeCost', async () => {
await page.evaluate((window: any) => {
window.setValues(window.data);
}, jsHandle);
await page.waitForTimeout(200);

await page.waitForFunction(() => {
return document.querySelectorAll('canvas')[2]!.getContext('2d')!.getImageData(70, 40, 1, 1).data[3] !== 0;
});
})

try {
await test.step('timeCost', async () => {
await page.evaluate((window: any) => {
window.setValues(window.data);
}, jsHandle);

await page.waitForFunction(() => {
return document.querySelectorAll('canvas')[2]!.getContext('2d')!.getImageData(70, 40, 1, 1).data[3] !== 0;
});
})
} catch (error) {
console.log('error', error);
}
})
};

Expand All @@ -47,7 +58,6 @@ createTest(1000, 1000);
createTest(10000, 100);
createTest(100000, 10);


createTest(10, 1000000);
createTest(100, 100000);
createTest(1000, 10000);
Expand Down
218 changes: 218 additions & 0 deletions tests/sheets/raw-load-data.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
import { test } from '@playwright/test';
import { BooleanNumber, ICellData, IWorkbookData, LocaleType } from '@univerjs/core';

test.beforeEach(async ({ context }) => {
await context.addInitScript(() => {
// @ts-expect-error
window.createData = (row: number, col: number) => {
const cellData: ICellData[][] = [];
for (let i = 0; i < row; i++) {
const row: ICellData[] = [];
for (let j = 0; j < col; j++) {
row.push({
v: i + ',' + j,
});
}
cellData.push(row);
}

const workbookData: IWorkbookData = {
id: 'workbook-01',
locale: 'zhCN' as LocaleType,
name: 'universheet',
sheetOrder: ['sheet-01', 'sheet-02', 'sheet-03', 'sheet-04', 'sheet-05', 'sheet-06'],
styles: {
},
appVersion: '3.0.0-alpha',
sheets: {
'sheet-01': {
id: 'sheet-01',
cellData,
name: 'sheet1',
tabColor: 'red',
hidden: 0 as 0 as BooleanNumber.FALSE,
rowCount: 1000,
columnCount: 20,
zoomRatio: 1,
scrollTop: 200,
scrollLeft: 100,
mergeData: [
{
startRow: 2,
endRow: 6,
startColumn: 5,
endColumn: 10,
},
{
startRow: 10,
endRow: 12,
startColumn: 9,
endColumn: 12,
},
{
startRow: 10,
endRow: 12,
startColumn: 9,
endColumn: 12,
},
{
startRow: 17,
endRow: 21,
startColumn: 3,
endColumn: 6,
},
{
startRow: 13,
endRow: 15,
startColumn: 9,
endColumn: 10,
},
{
startRow: 24,
endRow: 27,
startColumn: 9,
endColumn: 10,
},
{
startRow: 32,
endRow: 53,
startColumn: 3,
endColumn: 5,
},
],
rowData: {
3: {
h: 50,
hd: 0 as BooleanNumber.FALSE,
},
4: {
h: 60,
hd: 0 as BooleanNumber.FALSE,
},
29: {
h: 200,
hd: 0 as BooleanNumber.FALSE,
},
},
columnData: {
5: {
w: 100,
hd: 0 as BooleanNumber.FALSE,
},
6: {
w: 200,
hd: 0 as BooleanNumber.FALSE,
},
13: {
w: 300,
hd: 0 as BooleanNumber.FALSE,
},
},
showGridlines: 1,
rowHeader: {
width: 46,
hidden: 0 as BooleanNumber.FALSE,
},
columnHeader: {
height: 20,
hidden: 0 as BooleanNumber.FALSE,
},
selections: ['A2'],
rightToLeft: 0 as BooleanNumber.FALSE,
},
'sheet-02': {
id: 'sheet-02',
name: 'sheet2',
cellData: {
0: {
0: {
s: '1',
v: 1,
},
1: {
s: '1',
v: 1,
},
5: {
s: '1',
v: 8,
},
6: {
s: '2',
v: 8,
},
},
20: {
0: {
v: 'sheet2',
},
1: {
v: 'sheet2 - 2',
},
},
},
},
'sheet-03': {
id: 'sheet-03',
name: 'sheet3',
},
'sheet-04': {
id: 'sheet-04',
name: 'sheet4',
},
'sheet-05': {
id: 'sheet-05',
name: 'sheet5',
},
'sheet-06': {
id: 'sheet-06',
name: 'sheet6',
},
},
};
return workbookData;
};
});
});

const createTest = (row: number, col: number) => {
test(`raw load ${row}*${col} data`, async ({ page }) => {
await page.goto('/');

const jsHandle = await page.evaluateHandle('window');

await test.step('create data', async () => {
await page.evaluate(({ row, col, window }: any) => {
window.data = window.createData(row, col);
}, { row, col, window: jsHandle });
})

try {
await test.step('timeCost', async () => {
await page.evaluate((window: any) => {
window.univer.createUniverSheet(window.data);
}, jsHandle);

await page.waitForFunction(() => {
return document.querySelectorAll('canvas')[2]!.getContext('2d')!.getImageData(70, 40, 1, 1).data[3] !== 0;
});
})
} catch (error) {
console.log('error', error);
}
})
};


createTest(10, 100000);
createTest(100, 10000);
createTest(1000, 1000);
createTest(10000, 100);
createTest(100000, 10);

createTest(10, 1000000);
createTest(100, 100000);
createTest(1000, 10000);
createTest(10000, 1000);
createTest(100000, 100);
createTest(1000000, 10);

0 comments on commit d0a33e1

Please sign in to comment.