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

View File

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

View File

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