mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
refactor(native): remove unused code (#4651)
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
import assert from 'node:assert';
|
||||
import { test } from 'node:test';
|
||||
import test from 'ava';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import { SqliteConnection, ValidationResult } from '../index';
|
||||
|
||||
test('db', { concurrency: false }, async t => {
|
||||
await t.test('validate', async () => {
|
||||
const path = fileURLToPath(
|
||||
new URL('./fixtures/test01.affine', import.meta.url)
|
||||
);
|
||||
const result = await SqliteConnection.validate(path);
|
||||
assert.equal(result, ValidationResult.MissingVersionColumn);
|
||||
});
|
||||
test('db validate', async t => {
|
||||
const path = fileURLToPath(
|
||||
new URL('./fixtures/test01.affine', import.meta.url)
|
||||
);
|
||||
const result = await SqliteConnection.validate(path);
|
||||
t.is(result, ValidationResult.MissingVersionColumn);
|
||||
});
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
import assert, { doesNotThrow } from 'node:assert';
|
||||
import { promises as fs } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { test } from 'node:test';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import { lastValueFrom, Subject } from 'rxjs';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
import { FsWatcher } from '../index';
|
||||
|
||||
test('fs watch', { concurrency: false }, async t => {
|
||||
let watcher: FsWatcher;
|
||||
let fixture: string;
|
||||
t.beforeEach(async () => {
|
||||
const fixtureName = `fs-${v4()}.fixture`;
|
||||
fixture = join(fileURLToPath(import.meta.url), '..', fixtureName);
|
||||
await fs.writeFile(fixture, '\n');
|
||||
watcher = FsWatcher.watch(fixture);
|
||||
});
|
||||
|
||||
t.afterEach(async () => {
|
||||
FsWatcher.close();
|
||||
await fs.unlink(fixture).catch(() => false);
|
||||
});
|
||||
|
||||
await t.test('should watch without error', () => {
|
||||
doesNotThrow(() => {
|
||||
const subscription = watcher.subscribe(() => {});
|
||||
subscription.unsubscribe();
|
||||
});
|
||||
});
|
||||
|
||||
await t.test('should watch file change', () => {
|
||||
return (async () => {
|
||||
const defer = new Subject<void>();
|
||||
const subscription = watcher.subscribe(
|
||||
event => {
|
||||
assert.deepEqual(event.paths, [fixture]);
|
||||
subscription.unsubscribe();
|
||||
defer.next();
|
||||
defer.complete();
|
||||
},
|
||||
err => {
|
||||
subscription.unsubscribe();
|
||||
defer.error(err);
|
||||
}
|
||||
);
|
||||
await fs.appendFile(fixture, 'test');
|
||||
return lastValueFrom(defer.asObservable());
|
||||
})();
|
||||
});
|
||||
|
||||
await t.test('should watch file delete', () => {
|
||||
return (async () => {
|
||||
const defer = new Subject<void>();
|
||||
const subscription = watcher.subscribe(
|
||||
event => {
|
||||
if (typeof event.type === 'object' && 'rename' in event.type) {
|
||||
assert.deepEqual(event.paths, [fixture]);
|
||||
assert.deepEqual(event.type, {
|
||||
remove: {
|
||||
kind: 'file',
|
||||
},
|
||||
});
|
||||
}
|
||||
subscription.unsubscribe();
|
||||
defer.next();
|
||||
defer.complete();
|
||||
},
|
||||
err => {
|
||||
subscription.unsubscribe();
|
||||
defer.error(err);
|
||||
}
|
||||
);
|
||||
await fs.unlink(fixture);
|
||||
return lastValueFrom(defer.asObservable());
|
||||
})();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user