update tests

This commit is contained in:
Philipp Kunz 2017-04-28 11:28:11 +02:00
parent 6ac60cb3a5
commit 0be281746d
3 changed files with 127 additions and 129 deletions

View File

@ -28,7 +28,7 @@
"dependencies": {
"@types/fs-extra": "2.x.x",
"@types/vinyl": "^2.0.0",
"fs-extra": "^2.1.2",
"fs-extra": "^3.0.0",
"glob": "^7.1.1",
"js-yaml": "^3.8.3",
"require-reload": "0.2.2",
@ -41,6 +41,6 @@
},
"devDependencies": {
"gulp-function": "^2.2.3",
"tapbundle": "^1.0.9"
"tapbundle": "^1.0.10"
}
}

View File

@ -47,105 +47,96 @@ tap.test('.fs.listFileTree() -> should get a file tree', async () => {
expect(folderArrayArg).to.not.deep.include('mytest.json')
})
tap.test('.fstoObjectFromFileTree -> should read a file tree into an Object', async () => {
let fileArrayArg = await smartfile.fs.fileTreeToObject(path.resolve('./test/'), '**/*.txt')
// expect(fileArrayArg[1]).to.be.instanceof(smartfile.Smartfile)
})
tap.test('.fs.copy()', async () => {
tap.test('should copy a directory', async () => {
tap.test('.fs.copy() -> should copy a directory', async () => {
smartfile.fs.copy('./test/testfolder/', './test/temp/')
})
tap.test('should copy a file', async () => {
tap.test('.fs.copy() -> should copy a file', async () => {
smartfile.fs.copy('./test/mytest.yaml', './test/temp/')
})
tap.test('should copy a file and rename it', async () => {
tap.test('.fs.copy() -> should copy a file and rename it', async () => {
smartfile.fs.copy('./test/mytest.yaml', './test/temp/mytestRenamed.yaml')
})
})
tap.test('.fs.remove()', async () => {
tap.test('should remove an entire directory', async () => {
tap.test('.fs.remove() -> should remove an entire directory', async () => {
})
tap.test('smartfile.fs.remove -> should remove single files', async () => {
await expect(smartfile.fs.remove('./test/temp/mytestRenamed.yaml')).to.eventually.be.fulfilled
})
tap.test('smartfile.fs.removeSync -> should remove single files synchronouly', async () => {
smartfile.fs.removeSync('./test/temp/testfile1.txt')
expect(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).to.be.false
})
tap.test('smartfile.fs.removeMany -> should remove and array of files', async () => {
smartfile.fs.removeMany([ './test/temp/testfile1.txt', './test/temp/testfile2.txt' ]).then(() => {
expect(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).to.be.false
expect(smartfile.fs.fileExistsSync('./test/temp/testfile2.txt')).to.be.false
})
})
tap.test('smartfile.fs.removeManySync -> should remove and array of single files synchronouly', async () => {
smartfile.fs.removeManySync([ './test/temp/testfile1.txt', './test/temp/testfile2.txt' ])
expect(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).to.be.false
expect(smartfile.fs.fileExistsSync('./test/temp/testfile2.txt')).to.be.false
})
})
// ---------------------------
// .interpreter
// ---------------------------
tap.test('.interpreter.filetype()', async () => {
tap.test('should get the file type from 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')
})
})
tap.test('.fs', async () => {
tap.test('.toObjectSync()', async () => {
tap.test('should read an ' + '.yaml' + ' file to an object', async () => {
tap.test('.fs.toObjectSync() -> should read an ' + '.yaml' + ' file to an object', async () => {
let testData = smartfile.fs.toObjectSync('./test/mytest.yaml')
expect(testData).have.property('key1', 'this works')
expect(testData).have.property('key2', 'this works too')
})
tap.test('should state unknown file type for unknown file types', async () => {
tap.test('.fs.toObjectSync() -> should state unknown file type for unknown file types', async () => {
let testData = smartfile.fs.toObjectSync('./test/mytest.txt')
})
tap.test('should read an ' + '.json' + ' file to an object', async () => {
tap.test('.fs.toObjectSync() -> should read an ' + '.json' + ' file to an object', async () => {
let testData = smartfile.fs.toObjectSync('./test/mytest.json')
expect(testData).have.property('key1', 'this works')
expect(testData).have.property('key2', 'this works too')
})
})
})
tap.test('.toStringSync()', async () => {
tap.test('should read a file to a string', async () => {
tap.test('.fs.toStringSync() -> should read a file to a string', async () => {
expect(smartfile.fs.toStringSync('./test/mytest.txt'))
.to.equal('Some TestString &&%$')
})
})
tap.test('.toVinylSync', async () => {
tap.test('should read an ' + '.json OR .yaml' + ' file to an ' + 'vinyl file object', async () => {
tap.test('.fs.toVinylSync -> should read an ' + '.json OR .yaml' + ' file to an ' + 'vinyl file object', async () => {
let testData = smartfile.fs.toVinylSync('./test/mytest.json')
expect(vinyl.isVinyl(testData)).to.be.true
})
})
})
tap.test('.memory', async () => {
tap.test('.toGulpStream()', async () => {
tap.test('should produce a valid gulp stream', async () => {
tap.test('.memory.toGulpStream() -> should produce a valid gulp stream', async () => {
let localArray = [ 'test1', 'test2', 'test3' ]
smartfile.memory.toGulpStream(localArray)
})
})
tap.test('toVinylFileSync()', async () => {
tap.test('should produce a vinylFile', async () => {
tap.test('.memory.toVinylFileSync() -> should produce a vinylFile', async () => {
let localString = 'myString'
let localOptions = { filename: 'vinylfile2', base: '/someDir' }
expect(smartfile.memory.toVinylFileSync(localString, localOptions) instanceof vinyl).to.be.true
})
})
tap.test('toVinylArraySync()', async () => {
tap.test('should produce a an array of vinylfiles', async () => {
tap.test('.memory.toVinylArraySync() -> should produce a an array of vinylfiles', async () => {
let localStringArray = [ 'string1', 'string2', 'string3' ]
let localOptions = { filename: 'vinylfile2', base: '/someDir' }
let testResult = smartfile.memory.toVinylArraySync(localStringArray, localOptions)
@ -155,9 +146,8 @@ tap.test('.memory', async () => {
expect(testResult[ myKey ] instanceof vinyl).to.be.true
}
})
})
tap.test('vinylToStringSync()', async () => {
tap.test('should produce a String from vinyl file', async () => {
tap.test('.memory.vinylToStringSync() -> should produce a String from vinyl file', async () => {
let localString = smartfile.memory.vinylToStringSync(new vinyl({
base: '/',
path: '/test.txt',
@ -165,26 +155,22 @@ tap.test('.memory', async () => {
}))
expect(localString).equal('myString')
})
})
tap.test('toFs()', async () => {
tap.test('should write a file to disk and return a promise', async () => {
tap.test('.memory.toFs() -> should write a file to disk and return a promise', async () => {
let localString = 'myString'
smartfile.memory.toFs(
localString,
path.join(process.cwd(), './test/temp/testMemToFs.txt')
)
})
})
tap.test('toFsSync()', async () => {
tap.test('should write a file to disk and return true if successfull', async () => {
tap.test('.memory.toFsSync() -> should write a file to disk and return true if successfull', async () => {
let localString = 'myString'
smartfile.memory.toFsSync(
localString,
path.join(process.cwd(), './test/temp/testMemToFsSync.txt')
)
})
})
})
tap.test('.remote.toString() -> should load a remote file to a variable', async () => {
let responseString = await smartfile.remote.toString(

View File

@ -163,12 +163,13 @@ first-chunk-stream@^2.0.0:
dependencies:
readable-stream "^2.0.2"
fs-extra@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-2.1.2.tgz#046c70163cef9aad46b0e4a7fa467fb22d71de35"
fs-extra@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-3.0.0.tgz#244e0c4b0b8818f54040ec049d8a2bddc1202861"
dependencies:
graceful-fs "^4.1.2"
jsonfile "^2.1.0"
jsonfile "^3.0.0"
universalify "^0.1.0"
fs.realpath@^1.0.0:
version "1.0.0"
@ -239,9 +240,9 @@ js-yaml@^3.8.3:
argparse "^1.0.7"
esprima "^3.1.1"
jsonfile@^2.1.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8"
jsonfile@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-3.0.0.tgz#92e7c7444e5ffd5fa32e6a9ae8b85034df8347d0"
optionalDependencies:
graceful-fs "^4.1.6"
@ -372,6 +373,12 @@ smartchai@^1.0.3:
chai-as-promised "^6.0.0"
chai-string "^1.3.0"
smartdelay@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/smartdelay/-/smartdelay-1.0.1.tgz#687f8bcc09d7c62c9c5a8a1771c1aba3aff54156"
dependencies:
typings-global "^1.0.14"
smartpath@^3.2.8:
version "3.2.8"
resolved "https://registry.yarnpkg.com/smartpath/-/smartpath-3.2.8.tgz#4834bd3a8bae2295baacadba23c87a501952f940"
@ -422,13 +429,14 @@ strip-bom@^2.0.0:
dependencies:
is-utf8 "^0.2.0"
tapbundle@^1.0.9:
version "1.0.9"
resolved "https://registry.yarnpkg.com/tapbundle/-/tapbundle-1.0.9.tgz#e4afa8ccb6db21ffe02613c371805aec692dbdf3"
tapbundle@^1.0.10:
version "1.0.10"
resolved "https://registry.yarnpkg.com/tapbundle/-/tapbundle-1.0.10.tgz#36fd40036f6b5b738cbb9b5fc400df4c4031bc26"
dependencies:
early "^2.1.1"
leakage "^0.2.0"
smartchai "^1.0.3"
smartdelay "^1.0.1"
smartq "^1.1.1"
typings-global "^1.0.16"
@ -458,6 +466,10 @@ typings-global@^1.0.14, typings-global@^1.0.16:
semver "^5.3.0"
shelljs "^0.7.7"
universalify@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.0.tgz#9eb1c4651debcc670cc94f1a75762332bb967778"
util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"