fix: some potential tests issue (#2982)

This commit is contained in:
Peng Xiao
2023-07-03 18:46:47 +08:00
committed by Alex Yang
parent 425439ec42
commit 3a3053fb49
14 changed files with 52 additions and 17 deletions

View File

@@ -1,10 +1,11 @@
import path from 'node:path';
import { setTimeout } from 'node:timers/promises';
import fs from 'fs-extra';
import { v4 } from 'uuid';
import { afterEach, beforeEach, expect, test, vi } from 'vitest';
import { removeWithRetry } from '../../../../tests/utils';
const tmpDir = path.join(__dirname, 'tmp');
const appDataPath = path.join(tmpDir, 'app-data');
@@ -44,11 +45,7 @@ beforeEach(() => {
afterEach(async () => {
existProcess();
// wait for the db to be closed on Windows
if (process.platform === 'win32') {
await setTimeout(200);
}
await fs.remove(tmpDir);
await removeWithRetry(tmpDir);
vi.useRealTimers();
});

View File

@@ -5,6 +5,7 @@ import { v4 } from 'uuid';
import { afterEach, expect, test, vi } from 'vitest';
import * as Y from 'yjs';
import { removeWithRetry } from '../../../../tests/utils';
import { dbSubjects } from '../subjects';
const tmpDir = path.join(__dirname, 'tmp');
@@ -17,7 +18,7 @@ vi.doMock('../../main-rpc', () => ({
}));
afterEach(async () => {
await fs.remove(tmpDir);
await removeWithRetry(tmpDir);
});
let testYDoc: Y.Doc;

View File

@@ -4,6 +4,8 @@ import fs from 'fs-extra';
import { v4 } from 'uuid';
import { afterEach, describe, expect, test, vi } from 'vitest';
import { removeWithRetry } from '../../../../tests/utils';
const tmpDir = path.join(__dirname, 'tmp');
const appDataPath = path.join(tmpDir, 'app-data');
@@ -20,7 +22,7 @@ vi.doMock('../../main-rpc', () => ({
}));
afterEach(async () => {
await fs.remove(tmpDir);
await removeWithRetry(tmpDir);
});
describe('list workspaces', () => {

View File

@@ -1,10 +1,10 @@
import assert from 'node:assert';
import path from 'node:path';
import { setTimeout } from 'node:timers/promises';
import fs from 'fs-extra';
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
import { removeWithRetry } from '../../../tests/utils';
import type { MainIPCHandlerMap } from '../exposed';
const registeredHandlers = new Map<
@@ -121,11 +121,7 @@ beforeEach(async () => {
afterEach(async () => {
// reset registered handlers
registeredHandlers.get('before-quit')?.forEach(fn => fn());
// wait for the db to be closed on Windows
if (process.platform === 'win32') {
await setTimeout(200);
}
await fs.remove(SESSION_DATA_PATH);
await removeWithRetry(SESSION_DATA_PATH);
});
describe('UI handlers', () => {