mirror of
https://github.com/morten-olsen/plainidx.git
synced 2026-02-08 01:06:24 +01:00
init
This commit is contained in:
2
packages/tests/.gitignore
vendored
Normal file
2
packages/tests/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/node_modules/
|
||||
/dist/
|
||||
20
packages/tests/package.json
Normal file
20
packages/tests/package.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "@plaindb/tests",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@plaindb/fs-memory": "workspace:*",
|
||||
"@plaindb/plaindb": "workspace:*",
|
||||
"@plaindb/plugin-core": "workspace:*",
|
||||
"@plaindb/plugin-markdown": "workspace:*",
|
||||
"@pnpm/find-workspace-dir": "^900.0.1",
|
||||
"sqlite3": "^5.1.7",
|
||||
"vitest": "^2.1.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@pnpm/find-workspace-packages": "^6.0.9",
|
||||
"@types/node": "^22.10.1",
|
||||
"typescript": "^5.7.2"
|
||||
}
|
||||
}
|
||||
53
packages/tests/src/documents.test.ts
Normal file
53
packages/tests/src/documents.test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { describe, it } from 'vitest';
|
||||
import { CorePlugin } from '@plaindb/plugin-core';
|
||||
import { MarkdownPlugin } from '@plaindb/plugin-markdown';
|
||||
import { PlainDB } from '../../plaindb/dist/exports.js';
|
||||
import { MemoryFileSystem } from '@plaindb/fs-memory';
|
||||
|
||||
describe('documents', () => {
|
||||
it('should be able to create a document', async () => {
|
||||
const fs = new MemoryFileSystem({});
|
||||
|
||||
const { plugins, documents, close } = new PlainDB({
|
||||
fs,
|
||||
getDBConfig: () => ({
|
||||
client: 'sqlite',
|
||||
useNullAsDefault: false,
|
||||
connection: {
|
||||
filename: ':memory:',
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
await plugins.add([MarkdownPlugin]);
|
||||
|
||||
const tags1 = await plugins.action(CorePlugin, 'getTags', undefined);
|
||||
|
||||
console.log('Done', tags1);
|
||||
|
||||
const demoDocument = await documents.get('hello/world.md');
|
||||
|
||||
demoDocument.data = Buffer.from(`
|
||||
# Hello World
|
||||
|
||||
:tag[hello]
|
||||
`);
|
||||
|
||||
await demoDocument.save();
|
||||
|
||||
const tags2 = await plugins.action(CorePlugin, 'getTags', undefined);
|
||||
console.log('Done', tags2);
|
||||
|
||||
demoDocument.data = Buffer.from(`
|
||||
# Hello World
|
||||
|
||||
:tag[world]
|
||||
`);
|
||||
await demoDocument.save();
|
||||
|
||||
const tags3 = await plugins.action(CorePlugin, 'getTags', undefined);
|
||||
console.log('Done', tags3);
|
||||
|
||||
await close();
|
||||
});
|
||||
});
|
||||
9
packages/tests/tsconfig.json
Normal file
9
packages/tests/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
]
|
||||
}
|
||||
25
packages/tests/vitest.config.ts
Normal file
25
packages/tests/vitest.config.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/// <reference types="vitest" />
|
||||
|
||||
import { resolve } from 'path';
|
||||
import { defineConfig } from 'vitest/config';
|
||||
import { findWorkspaceDir } from '@pnpm/find-workspace-dir';
|
||||
import { findWorkspacePackages } from '@pnpm/find-workspace-packages';
|
||||
|
||||
const root = await findWorkspaceDir(process.cwd());
|
||||
if (!root) {
|
||||
throw new Error('No workspace found');
|
||||
}
|
||||
const packages = await findWorkspacePackages(root);
|
||||
|
||||
const alias = Object.fromEntries(
|
||||
packages.map(({ dir, manifest }) => [
|
||||
manifest.name!,
|
||||
resolve(dir, 'src', 'exports.ts'),
|
||||
]),
|
||||
);
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
alias,
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user