BREAKING CHANGE(core): switch to esm
This commit is contained in:
76
test/test.ts
76
test/test.ts
@ -1,4 +1,4 @@
|
||||
import * as smartfile from '../ts/index';
|
||||
import * as smartfile from '../ts/index.js';
|
||||
import * as path from 'path';
|
||||
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
@ -9,47 +9,47 @@ import { expect, tap } from '@pushrocks/tapbundle';
|
||||
|
||||
tap.test('.fs.fileExistsSync -> should return an accurate boolean', async () => {
|
||||
// tslint:disable-next-line: no-unused-expression
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/mytest.json')).to.be.true;
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/mytest.json')).toBeTrue();
|
||||
// tslint:disable-next-line: no-unused-expression
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/notthere.json')).be.false;
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/notthere.json')).toBeFalse();
|
||||
});
|
||||
|
||||
tap.test('.fs.fileExists -> should resolve or reject a promise', async () => {
|
||||
expect(smartfile.fs.fileExists('./test/testassets/mytest.json')).to.be.instanceof(Promise);
|
||||
expect(smartfile.fs.fileExists('./test/testassets/mytest.json')).toBeInstanceOf(Promise);
|
||||
await smartfile.fs.fileExists('./test/testassets/mytest.json');
|
||||
await smartfile.fs.fileExists('./test/testassets/notthere.json').catch((err) => {
|
||||
return expect(err.message).to.equal(
|
||||
return expect(err.message).toEqual(
|
||||
"ENOENT: no such file or directory, access './test/testassets/notthere.json'"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
tap.test('.fs.listFoldersSync() -> should get the file type from a string', async () => {
|
||||
expect(smartfile.fs.listFoldersSync('./test/testassets/')).to.include('testfolder');
|
||||
expect(smartfile.fs.listFoldersSync('./test/testassets/')).to.not.include('notExistentFolder');
|
||||
expect(smartfile.fs.listFoldersSync('./test/testassets/')).toContain('testfolder');
|
||||
expect(smartfile.fs.listFoldersSync('./test/testassets/')).not.toContain('notExistentFolder');
|
||||
});
|
||||
|
||||
tap.test('.fs.listFolders() -> should get the file type from a string', async () => {
|
||||
const folderArrayArg = await smartfile.fs.listFolders('./test/testassets/');
|
||||
expect(folderArrayArg).to.include('testfolder');
|
||||
expect(folderArrayArg).to.not.include('notExistentFolder');
|
||||
expect(folderArrayArg).toContain('testfolder');
|
||||
expect(folderArrayArg).not.toContain('notExistentFolder');
|
||||
});
|
||||
|
||||
tap.test('.fs.listFilesSync() -> should get the file type from a string', async () => {
|
||||
expect(smartfile.fs.listFilesSync('./test/testassets/')).to.include('mytest.json');
|
||||
expect(smartfile.fs.listFilesSync('./test/testassets/')).to.not.include('notExistentFile');
|
||||
expect(smartfile.fs.listFilesSync('./test/testassets/', /mytest\.json/)).to.include(
|
||||
expect(smartfile.fs.listFilesSync('./test/testassets/')).toContain('mytest.json');
|
||||
expect(smartfile.fs.listFilesSync('./test/testassets/')).not.toContain('notExistentFile');
|
||||
expect(smartfile.fs.listFilesSync('./test/testassets/', /mytest\.json/)).toContain(
|
||||
'mytest.json'
|
||||
);
|
||||
expect(smartfile.fs.listFilesSync('./test/testassets/', /mytests.json/)).to.not.include(
|
||||
expect(smartfile.fs.listFilesSync('./test/testassets/', /mytests.json/)).not.toContain(
|
||||
'mytest.json'
|
||||
);
|
||||
});
|
||||
|
||||
tap.test('.fs.listFiles() -> should get the file type from a string', async () => {
|
||||
const folderArrayArg = await smartfile.fs.listFiles('./test/testassets/');
|
||||
expect(folderArrayArg).to.include('mytest.json');
|
||||
expect(folderArrayArg).to.not.include('notExistentFile');
|
||||
expect(folderArrayArg).toContain('mytest.json');
|
||||
expect(folderArrayArg).not.toContain('notExistentFile');
|
||||
});
|
||||
|
||||
tap.test('.fs.listFileTree() -> should get a file tree', async () => {
|
||||
@ -57,8 +57,8 @@ tap.test('.fs.listFileTree() -> should get a file tree', async () => {
|
||||
path.resolve('./test/testassets/'),
|
||||
'**/*.txt'
|
||||
);
|
||||
expect(folderArrayArg).to.include('testfolder/testfile1.txt');
|
||||
expect(folderArrayArg).to.not.include('mytest.json');
|
||||
expect(folderArrayArg).toContain('testfolder/testfile1.txt');
|
||||
expect(folderArrayArg).not.toContain('mytest.json');
|
||||
});
|
||||
|
||||
tap.test('.fs.fileTreeToObject -> should read a file tree into an Object', async () => {
|
||||
@ -66,8 +66,8 @@ tap.test('.fs.fileTreeToObject -> should read a file tree into an Object', async
|
||||
path.resolve('./test/testassets/'),
|
||||
'**/*.txt'
|
||||
);
|
||||
expect(fileArrayArg[0]).to.be.instanceof(smartfile.Smartfile);
|
||||
expect(fileArrayArg[0].contents.toString()).to.equal(fileArrayArg[0].contentBuffer.toString());
|
||||
expect(fileArrayArg[0]).toBeInstanceOf(smartfile.Smartfile);
|
||||
expect(fileArrayArg[0].contents.toString()).toEqual(fileArrayArg[0].contentBuffer.toString());
|
||||
});
|
||||
|
||||
tap.test('.fs.copy() -> should copy a directory', async () => {
|
||||
@ -93,15 +93,15 @@ tap.test('.fs.remove -> should remove single files', async () => {
|
||||
|
||||
tap.test('.fs.removeSync -> should remove single files synchronouly', async () => {
|
||||
smartfile.fs.removeSync('./test/testassets/temp/testfile1.txt');
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).to.be.false;
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).toBeFalse();
|
||||
});
|
||||
|
||||
tap.test('.fs.removeMany -> should remove and array of files', async () => {
|
||||
smartfile.fs
|
||||
.removeMany(['./test/testassets/temp/testfile1.txt', './test/testassets/temp/testfile2.txt'])
|
||||
.then(() => {
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).to.be.false;
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt')).to.be.false;
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).toBeFalse();
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt')).toBeFalse();
|
||||
});
|
||||
});
|
||||
|
||||
@ -110,14 +110,14 @@ tap.test('.fs.removeManySync -> should remove and array of single files synchron
|
||||
'./test/testassets/temp/testfile1.txt',
|
||||
'./test/testassets/temp/testfile2.txt',
|
||||
]);
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).to.be.false;
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt')).to.be.false;
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile1.txt')).toBeFalse();
|
||||
expect(smartfile.fs.fileExistsSync('./test/testassets/temp/testfile2.txt')).toBeFalse();
|
||||
});
|
||||
|
||||
tap.test('.fs.toObjectSync() -> should read an ' + '.yaml' + ' file to an object', async () => {
|
||||
tap.test('.fs.toObjectSync() -> should read an .yaml file to an object', async () => {
|
||||
const testData = smartfile.fs.toObjectSync('./test/testassets/mytest.yaml');
|
||||
expect(testData).to.include({ key1: 'this works' });
|
||||
expect(testData).to.include({ key2: 'this works too' });
|
||||
expect(testData.key1).toEqual('this works');
|
||||
expect(testData.key2).toEqual('this works too');
|
||||
});
|
||||
tap.test(
|
||||
'.fs.toObjectSync() -> should state unknown file type for unknown file types',
|
||||
@ -126,14 +126,14 @@ tap.test(
|
||||
}
|
||||
);
|
||||
|
||||
tap.test('.fs.toObjectSync() -> should read an ' + '.json' + ' file to an object', async () => {
|
||||
tap.test('.fs.toObjectSync() -> should read an .json file to an object', async () => {
|
||||
const testData = smartfile.fs.toObjectSync('./test/testassets/mytest.json');
|
||||
expect(testData).to.include({ key1: 'this works' });
|
||||
expect(testData).to.include({ key2: 'this works too' });
|
||||
expect(testData.key1).toEqual('this works');
|
||||
expect(testData.key2).toEqual('this works too');
|
||||
});
|
||||
|
||||
tap.test('.fs.toStringSync() -> should read a file to a string', async () => {
|
||||
expect(smartfile.fs.toStringSync('./test/testassets/mytest.txt')).to.equal(
|
||||
expect(smartfile.fs.toStringSync('./test/testassets/mytest.txt')).toEqual(
|
||||
'Some TestString &&%$'
|
||||
);
|
||||
});
|
||||
@ -143,7 +143,7 @@ tap.test('.fs.toStringSync() -> should read a file to a string', async () => {
|
||||
// ---------------------------
|
||||
|
||||
tap.test('.interpreter.filetype() -> should get the file type from a string', async () => {
|
||||
expect(smartfile.interpreter.filetype('./somefolder/data.json')).equal('json');
|
||||
expect(smartfile.interpreter.filetype('./somefolder/data.json')).toEqual('json');
|
||||
});
|
||||
|
||||
// ---------------------------
|
||||
@ -179,14 +179,14 @@ tap.test('.Smartfile -> should produce vinyl compatible files', async () => {
|
||||
'./test/testassets/testfolder/**/*'
|
||||
);
|
||||
const localSmartfile = smartfileArray[0];
|
||||
expect(localSmartfile).to.be.instanceof(smartfile.Smartfile);
|
||||
expect(localSmartfile.contents).to.be.instanceof(Buffer);
|
||||
expect(localSmartfile).toBeInstanceOf(smartfile.Smartfile);
|
||||
expect(localSmartfile.contents).toBeInstanceOf(Buffer);
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(localSmartfile.isBuffer()).to.be.true;
|
||||
expect(localSmartfile.isBuffer()).toBeTrue();
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(localSmartfile.isDirectory()).to.be.false;
|
||||
expect(localSmartfile.isDirectory()).toBeFalse();
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(localSmartfile.isNull()).to.be.false;
|
||||
expect(localSmartfile.isNull()).toBeFalse();
|
||||
});
|
||||
|
||||
tap.test('should output a smartfile array to disk', async () => {
|
||||
@ -210,7 +210,7 @@ tap.test('should create, store and retrieve valid smartfiles', async () => {
|
||||
smartfileInstance.write();
|
||||
const smartfileInstance2 = await smartfile.Smartfile.fromFilePath(filePath);
|
||||
const retrievedString = smartfileInstance.contents.toString();
|
||||
expect(retrievedString).to.equal(fileString);
|
||||
expect(retrievedString).toEqual(fileString);
|
||||
});
|
||||
|
||||
tap.test('should wait for file to be ready', async () => {
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
|
||||
import * as smartfile from '../ts';
|
||||
import * as smartfile from '../ts/index.js';
|
||||
|
||||
tap.test('should create a virtualdirectory', async () => {
|
||||
const virtualDir = await smartfile.VirtualDirectory.fromFsDirPath('./test/testassets/testfolder');
|
||||
expect(virtualDir.smartfileArray.length).to.equal(4);
|
||||
expect(virtualDir.smartfileArray.length).toEqual(4);
|
||||
});
|
||||
|
||||
tap.test('should write to a directory', async () => {
|
||||
|
Reference in New Issue
Block a user