als-store
Version:
Library for streamlined file management and advanced data caching, featuring intelligent file searching, dynamic cache control, and flexible file operations
56 lines (49 loc) • 2.08 kB
JavaScript
const assert = require('node:assert')
const { describe, it, beforeEach, afterEach } = require('node:test')
const Store = require('../lib/store')
const { join } = require('node:path')
const File = require('../lib/file')
const { ensureDirSync, removeSync, existsSync, readFileSync, pathExistsSync } = require('fs-extra')
const { readdir, readdirSync } = require('als-readdir')
const store = new Store({dirPath:__dirname})
describe('Add ons tests', () => {
it('value setter - can get buffer as value',async () => {
const text = "test text";
const buffer = Buffer.from(text, 'utf-8');
const file = await store.create('test.txt',buffer).save()
assert(file.value === text)
await file.remove()
})
it('fixed updating stats after saving',async () => {
const file = await store.create('test.txt','test').save()
const stats1 = file.stats
file.value = 'test2'
await file.save()
const stats2 = file.stats
assert(stats1.mtimeMs !== stats2.mtimeMs)
await file.remove()
})
it('create(name,value) - name can include dir, like - some/filename.ext',async () => {
const path = 'some/test.txt'
const fullPath = join(__dirname,path)
assert(pathExistsSync(fullPath) === false)
const file = await store.create(path,'test').save()
assert(pathExistsSync(fullPath) === true)
await file.remove()
removeSync(join(__dirname,'some'))
})
it('first/get(value=false) instead values()',async () => {
const file = await store.first(true)
assert(file.value !== undefined)
const {results} = await store.get(true)
assert(results[1].value !== undefined)
})
it('store.file(filename,value=false)',async () => {
const file = await store.file('add-ons.test.js',true)
assert(file.value.startsWith('const assert = require'))
})
it('empty/undefined dir store.dir("") should work now',async () => {
const {results} = await store.dir().get()
assert(results.length > 0)
})
})