-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove unused test data from repository * fix missing write in stringify function * add new bundle to replace current fs module
- Loading branch information
1 parent
044ba53
commit 542d138
Showing
18 changed files
with
228 additions
and
697 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import LoomIO from '@loom-io/core'; | ||
import jsonConverter from '@loom-io/jsonConverter'; | ||
import yamlConverter from '@loom-io/yamlConverter'; | ||
import fileSystemAdapter from '@loom-io/node-filesystem-adapter'; | ||
|
||
LoomIO.register(fileSystemAdapter('file://')); | ||
LoomIO.register(jsonConverter); | ||
LoomIO.register(yamlConverter); | ||
|
||
export * from '@loom-io/core'; | ||
|
||
export default LoomIO; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { describe, test, expect } from 'vitest'; | ||
import LoomIO, {isDirectory, isFile} from '../src/bundle'; | ||
|
||
describe('minimal export test', async () => { | ||
|
||
test('exports', async () => { | ||
expect(LoomIO).toBeDefined(); | ||
}); | ||
|
||
test('isDirectory', async () => { | ||
expect(isDirectory).toBeDefined(); | ||
expect(isDirectory).toBeInstanceOf(Function); | ||
}); | ||
|
||
test('isFile', async () => { | ||
expect(isFile).toBeDefined(); | ||
expect(isFile).toBeInstanceOf(Function); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
import { describe, test, expect, afterAll } from 'vitest'; | ||
import { rmdir } from 'fs/promises'; | ||
import { resolve as resolvePath } from 'node:path'; | ||
import LoomIO, { Directory, DirectoryNotEmptyException, isDirectory } from '../src/bundle'; | ||
|
||
const BASE_TEST_PATH = './tmp-test/'; | ||
|
||
const randomStrings = new Set<string>(); | ||
|
||
const createRandomDirectory = async (): Promise<Directory> => { | ||
const random = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); | ||
if ( randomStrings.has(random) ) { | ||
return createRandomDirectory(); | ||
} | ||
randomStrings.add(random); | ||
return LoomIO.dir(`file://${BASE_TEST_PATH}/${random}`); | ||
}; | ||
|
||
const deleteRandomDirectory = async (dir: Directory) => { | ||
const random = dir.path; | ||
await rmdir(resolvePath(random), {recursive: true}); | ||
randomStrings.delete(random); | ||
}; | ||
|
||
describe.concurrent('test integration of bundle for interacting with filesystem', () => { | ||
|
||
afterAll(async () => { | ||
await rmdir(resolvePath(BASE_TEST_PATH), {recursive: true}); | ||
}); | ||
|
||
describe('test base functionality', () => { | ||
|
||
test('create directory', async () => { | ||
const dir = await createRandomDirectory(); | ||
expect(dir).toBeDefined(); | ||
expect(isDirectory(dir)).toBeTruthy(); | ||
await dir.create(); | ||
expect(await dir.exists()).toBeTruthy(); | ||
await deleteRandomDirectory(dir); | ||
await expect(dir.exists()).resolves.toBeFalsy(); | ||
}); | ||
|
||
test('delete directory', async () => { | ||
const dir = await createRandomDirectory(); | ||
await dir.delete(); | ||
expect(await dir.exists()).toBeFalsy(); | ||
}); | ||
|
||
test('list empty directory', async () => { | ||
const dir = await createRandomDirectory(); | ||
await dir.create(); | ||
const list = await dir.list(); | ||
expect(list).toBeDefined(); | ||
expect(list.length).toBe(0); | ||
await deleteRandomDirectory(dir); | ||
}); | ||
|
||
test('list directory with files', async () => { | ||
const dir = await createRandomDirectory(); | ||
await dir.create(); | ||
const file = dir.file('test.txt'); | ||
await file.create(); | ||
const list = await dir.list(); | ||
expect(list).toBeDefined(); | ||
expect(list.length).toBe(1); | ||
await deleteRandomDirectory(dir); | ||
}); | ||
|
||
test('delete directory with files', async () => { | ||
const dir = await createRandomDirectory(); | ||
await dir.create(); | ||
const file = dir.file('test.txt'); | ||
await file.create(); | ||
expect(await dir.exists()).toBeTruthy(); | ||
expect(await file.exists()).toBeTruthy(); | ||
await expect(dir.delete()).rejects.toThrow(DirectoryNotEmptyException); | ||
await dir.delete(true); | ||
expect(await dir.exists()).toBeFalsy(); | ||
}); | ||
|
||
test('create file', async () => { | ||
const dir = await createRandomDirectory(); | ||
await dir.create(); | ||
const file = dir.file('test.txt'); | ||
await file.create(); | ||
expect(await file.exists()).toBeTruthy(); | ||
await deleteRandomDirectory(dir); | ||
}); | ||
|
||
test('delete file', async () => { | ||
const dir = await createRandomDirectory(); | ||
await dir.create(); | ||
const file = dir.file('test.txt'); | ||
await file.create(); | ||
expect(await file.exists()).toBeTruthy(); | ||
await file.delete(); | ||
expect(await file.exists()).toBeFalsy(); | ||
await deleteRandomDirectory(dir); | ||
}); | ||
|
||
test('write file', async () => { | ||
const dir = await createRandomDirectory(); | ||
await dir.create(); | ||
const file = dir.file('test.txt'); | ||
await file.create(); | ||
const content = 'test content'; | ||
await file.write(content); | ||
expect(await file.text()).toBe(content); | ||
await deleteRandomDirectory(dir); | ||
}); | ||
|
||
test('read file', async () => { | ||
const dir = await createRandomDirectory(); | ||
await dir.create(); | ||
const file = dir.file('test.txt'); | ||
await file.create(); | ||
const content = 'test content'; | ||
await file.write(content); | ||
expect(await file.text()).toBe(content); | ||
await deleteRandomDirectory(dir); | ||
}); | ||
|
||
test('read yml file', async () => { | ||
const dir = await createRandomDirectory(); | ||
await dir.create(); | ||
const file = dir.file('test.yml'); | ||
await file.create(); | ||
const content = 'test: content'; | ||
await file.write(content); | ||
const json = await file.json(); | ||
expect(json).toStrictEqual({test: 'content'}); | ||
await deleteRandomDirectory(dir); | ||
}); | ||
|
||
test('read json file', async () => { | ||
const dir = await createRandomDirectory(); | ||
await dir.create(); | ||
const file = dir.file('test.json'); | ||
await file.create(); | ||
const content = '{"test": "content"}'; | ||
await file.write(content); | ||
const json = await file.json(); | ||
expect(json).toStrictEqual({test: 'content'}); | ||
await deleteRandomDirectory(dir); | ||
}); | ||
|
||
test('read log file', async () => { | ||
const dir = await createRandomDirectory(); | ||
await dir.create(); | ||
const file = dir.file('test.log'); | ||
await file.create(); | ||
const content = 'test content'; | ||
await file.write(content); | ||
await expect(file.text()).resolves.toBe(content); | ||
await deleteRandomDirectory(dir); | ||
}); | ||
|
||
test('write json file', async () => { | ||
const dir = await createRandomDirectory(); | ||
await dir.create(); | ||
const file = dir.file('test.json'); | ||
await file.create(); | ||
const content = {test: 'content'}; | ||
await file.stringify(content); | ||
await expect(file.text()).resolves.toBe(JSON.stringify(content)); | ||
await deleteRandomDirectory(dir); | ||
}); | ||
|
||
test('write yml file', async () => { | ||
const dir = await createRandomDirectory(); | ||
await dir.create(); | ||
const file = dir.file('test.yml'); | ||
await file.create(); | ||
const content = {test: 'content', test2: ['content', 'content2']}; | ||
await file.stringify(content); | ||
expect(await file.text()).toBe('test: content\ntest2:\n - content\n - content2\n'); | ||
await deleteRandomDirectory(dir); | ||
}); | ||
|
||
|
||
}); | ||
|
||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.