mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 19:02:23 +08:00
fix: some potential tests issue (#2982)
This commit is contained in:
@@ -204,6 +204,7 @@ const config = {
|
|||||||
'scripts/**/*',
|
'scripts/**/*',
|
||||||
'**/benchmark/**/*',
|
'**/benchmark/**/*',
|
||||||
'**/__debug__/**/*',
|
'**/__debug__/**/*',
|
||||||
|
'**/e2e/**/*',
|
||||||
],
|
],
|
||||||
rules: {
|
rules: {
|
||||||
'@typescript-eslint/no-non-null-assertion': 0,
|
'@typescript-eslint/no-non-null-assertion': 0,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import type { PlaywrightTestConfig } from '@playwright/test';
|
|||||||
* See https://playwright.dev/docs/test-configuration.
|
* See https://playwright.dev/docs/test-configuration.
|
||||||
*/
|
*/
|
||||||
const config: PlaywrightTestConfig = {
|
const config: PlaywrightTestConfig = {
|
||||||
testDir: './tests',
|
testDir: './e2e',
|
||||||
testIgnore: '**/lib/**',
|
testIgnore: '**/lib/**',
|
||||||
fullyParallel: true,
|
fullyParallel: true,
|
||||||
timeout: process.env.CI ? 50_000 : 30_000,
|
timeout: process.env.CI ? 50_000 : 30_000,
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { setTimeout } from 'node:timers/promises';
|
import { setTimeout } from 'node:timers/promises';
|
||||||
|
|
||||||
import fs from 'fs-extra';
|
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
import { afterEach, beforeEach, expect, test, vi } from 'vitest';
|
import { afterEach, beforeEach, expect, test, vi } from 'vitest';
|
||||||
|
|
||||||
|
import { removeWithRetry } from '../../../../tests/utils';
|
||||||
|
|
||||||
const tmpDir = path.join(__dirname, 'tmp');
|
const tmpDir = path.join(__dirname, 'tmp');
|
||||||
const appDataPath = path.join(tmpDir, 'app-data');
|
const appDataPath = path.join(tmpDir, 'app-data');
|
||||||
|
|
||||||
@@ -44,11 +45,7 @@ beforeEach(() => {
|
|||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
existProcess();
|
existProcess();
|
||||||
// wait for the db to be closed on Windows
|
await removeWithRetry(tmpDir);
|
||||||
if (process.platform === 'win32') {
|
|
||||||
await setTimeout(200);
|
|
||||||
}
|
|
||||||
await fs.remove(tmpDir);
|
|
||||||
vi.useRealTimers();
|
vi.useRealTimers();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { v4 } from 'uuid';
|
|||||||
import { afterEach, expect, test, vi } from 'vitest';
|
import { afterEach, expect, test, vi } from 'vitest';
|
||||||
import * as Y from 'yjs';
|
import * as Y from 'yjs';
|
||||||
|
|
||||||
|
import { removeWithRetry } from '../../../../tests/utils';
|
||||||
import { dbSubjects } from '../subjects';
|
import { dbSubjects } from '../subjects';
|
||||||
|
|
||||||
const tmpDir = path.join(__dirname, 'tmp');
|
const tmpDir = path.join(__dirname, 'tmp');
|
||||||
@@ -17,7 +18,7 @@ vi.doMock('../../main-rpc', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await fs.remove(tmpDir);
|
await removeWithRetry(tmpDir);
|
||||||
});
|
});
|
||||||
|
|
||||||
let testYDoc: Y.Doc;
|
let testYDoc: Y.Doc;
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import fs from 'fs-extra';
|
|||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
import { afterEach, describe, expect, test, vi } from 'vitest';
|
import { afterEach, describe, expect, test, vi } from 'vitest';
|
||||||
|
|
||||||
|
import { removeWithRetry } from '../../../../tests/utils';
|
||||||
|
|
||||||
const tmpDir = path.join(__dirname, 'tmp');
|
const tmpDir = path.join(__dirname, 'tmp');
|
||||||
const appDataPath = path.join(tmpDir, 'app-data');
|
const appDataPath = path.join(tmpDir, 'app-data');
|
||||||
|
|
||||||
@@ -20,7 +22,7 @@ vi.doMock('../../main-rpc', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await fs.remove(tmpDir);
|
await removeWithRetry(tmpDir);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('list workspaces', () => {
|
describe('list workspaces', () => {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import assert from 'node:assert';
|
import assert from 'node:assert';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { setTimeout } from 'node:timers/promises';
|
|
||||||
|
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
||||||
|
|
||||||
|
import { removeWithRetry } from '../../../tests/utils';
|
||||||
import type { MainIPCHandlerMap } from '../exposed';
|
import type { MainIPCHandlerMap } from '../exposed';
|
||||||
|
|
||||||
const registeredHandlers = new Map<
|
const registeredHandlers = new Map<
|
||||||
@@ -121,11 +121,7 @@ beforeEach(async () => {
|
|||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
// reset registered handlers
|
// reset registered handlers
|
||||||
registeredHandlers.get('before-quit')?.forEach(fn => fn());
|
registeredHandlers.get('before-quit')?.forEach(fn => fn());
|
||||||
// wait for the db to be closed on Windows
|
await removeWithRetry(SESSION_DATA_PATH);
|
||||||
if (process.platform === 'win32') {
|
|
||||||
await setTimeout(200);
|
|
||||||
}
|
|
||||||
await fs.remove(SESSION_DATA_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('UI handlers', () => {
|
describe('UI handlers', () => {
|
||||||
|
|||||||
26
apps/electron/tests/utils.ts
Normal file
26
apps/electron/tests/utils.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { setTimeout } from 'node:timers/promises';
|
||||||
|
|
||||||
|
import fs from 'fs-extra';
|
||||||
|
|
||||||
|
export async function removeWithRetry(
|
||||||
|
filePath: string,
|
||||||
|
maxRetries = 5,
|
||||||
|
delay = 500
|
||||||
|
) {
|
||||||
|
for (let i = 0; i < maxRetries; i++) {
|
||||||
|
try {
|
||||||
|
await fs.remove(filePath);
|
||||||
|
console.log(`File ${filePath} successfully deleted.`);
|
||||||
|
return true;
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err.code === 'EBUSY' || err.code === 'EPERM') {
|
||||||
|
console.log(`File ${filePath} is busy or locked, retrying...`);
|
||||||
|
await setTimeout(delay);
|
||||||
|
} else {
|
||||||
|
console.error(`Failed to delete file ${filePath}:`, err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Add a return statement here to ensure that a value is always returned
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
"noImplicitOverride": true
|
"noImplicitOverride": true
|
||||||
},
|
},
|
||||||
"include": ["./src"],
|
"include": ["./src"],
|
||||||
"exclude": ["node_modules", "out", "dist"],
|
"exclude": ["node_modules", "out", "dist", "**/__tests__/**/*"],
|
||||||
"references": [
|
"references": [
|
||||||
{
|
{
|
||||||
"path": "../../packages/plugin-infra"
|
"path": "../../packages/plugin-infra"
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
"path": "./tsconfig.node.json"
|
"path": "./tsconfig.node.json"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "./tests/tsconfig.json"
|
"path": "./e2e/tsconfig.json"
|
||||||
},
|
},
|
||||||
{ "path": "../../tests/kit" }
|
{ "path": "../../tests/kit" }
|
||||||
],
|
],
|
||||||
|
|||||||
12
apps/electron/tsconfig.tests.json
Normal file
12
apps/electron/tsconfig.tests.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"composite": true
|
||||||
|
},
|
||||||
|
"include": ["**/__tests__/**/*", "./tests"],
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"path": "./tsconfig.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user