switch to smartq
This commit is contained in:
75
test/test.js
75
test/test.js
File diff suppressed because one or more lines are too long
91
test/test.ts
91
test/test.ts
@ -2,54 +2,56 @@ import 'typings-test'
|
||||
import * as smartfile from '../dist/index'
|
||||
import beautylog = require('beautylog')
|
||||
import path = require('path')
|
||||
import * as should from 'should'
|
||||
|
||||
import { expect } from 'smartchai'
|
||||
|
||||
import * as vinyl from 'vinyl'
|
||||
|
||||
describe('smartfile', function () {
|
||||
describe('.fs', function () {
|
||||
describe('.fileExistsSync', function () {
|
||||
it('should return an accurate boolean', function () {
|
||||
should(smartfile.fs.fileExistsSync('./test/mytest.json')).be.true()
|
||||
should(smartfile.fs.fileExistsSync('./test/notthere.json')).be.false()
|
||||
expect(smartfile.fs.fileExistsSync('./test/mytest.json')).to.be.true
|
||||
expect(smartfile.fs.fileExistsSync('./test/notthere.json')).be.false
|
||||
})
|
||||
})
|
||||
describe('.fileExists', function () {
|
||||
it('should return a working promise', function () {
|
||||
should(smartfile.fs.fileExists('./test/mytest.json')).be.Promise()
|
||||
should(smartfile.fs.fileExists('./test/mytest.json')).be.fulfilled()
|
||||
should(smartfile.fs.fileExists('./test/notthere.json')).not.be.fulfilled()
|
||||
expect(smartfile.fs.fileExists('./test/mytest.json')).to.be.a('promise')
|
||||
expect(smartfile.fs.fileExists('./test/mytest.json')).to.be.fulfilled
|
||||
expect(smartfile.fs.fileExists('./test/notthere.json')).to.not.be.fulfilled
|
||||
})
|
||||
})
|
||||
describe('.listFoldersSync()', function () {
|
||||
it('should get the file type from a string', function () {
|
||||
should(smartfile.fs.listFoldersSync('./test/')).containDeep(['testfolder'])
|
||||
should(smartfile.fs.listFoldersSync('./test/')).not.containDeep(['notExistentFolder'])
|
||||
expect(smartfile.fs.listFoldersSync('./test/')).to.deep.include('testfolder')
|
||||
expect(smartfile.fs.listFoldersSync('./test/')).to.not.deep.include('notExistentFolder')
|
||||
})
|
||||
})
|
||||
describe('.listFolders()', function () {
|
||||
it('should get the file type from a string', function (done) {
|
||||
smartfile.fs.listFolders('./test/')
|
||||
.then(function (folderArrayArg) {
|
||||
should(folderArrayArg).containDeep(['testfolder'])
|
||||
should(folderArrayArg).not.containDeep(['notExistentFolder'])
|
||||
expect(folderArrayArg).to.deep.include('testfolder')
|
||||
expect(folderArrayArg).to.not.deep.include('notExistentFolder')
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('.listFilesSync()', function () {
|
||||
it('should get the file type from a string', function () {
|
||||
should(smartfile.fs.listFilesSync('./test/')).containDeep(['mytest.json'])
|
||||
should(smartfile.fs.listFilesSync('./test/')).not.containDeep(['notExistentFile'])
|
||||
should(smartfile.fs.listFilesSync('./test/', /mytest\.json/)).containDeep(['mytest.json'])
|
||||
should(smartfile.fs.listFilesSync('./test/', /mytests.json/)).not.containDeep(['mytest.json'])
|
||||
expect(smartfile.fs.listFilesSync('./test/')).to.deep.include('mytest.json')
|
||||
expect(smartfile.fs.listFilesSync('./test/')).to.not.deep.include('notExistentFile')
|
||||
expect(smartfile.fs.listFilesSync('./test/', /mytest\.json/)).to.deep.include('mytest.json')
|
||||
expect(smartfile.fs.listFilesSync('./test/', /mytests.json/)).to.not.deep.include('mytest.json')
|
||||
})
|
||||
})
|
||||
describe('.listFiles()', function () {
|
||||
it('should get the file type from a string', function (done) {
|
||||
smartfile.fs.listFiles('./test/')
|
||||
.then(function (folderArrayArg) {
|
||||
should(folderArrayArg).containDeep(['mytest.json'])
|
||||
should(folderArrayArg).not.containDeep(['notExistentFile'])
|
||||
expect(folderArrayArg).to.deep.include('mytest.json')
|
||||
expect(folderArrayArg).to.not.deep.include('notExistentFile')
|
||||
done()
|
||||
})
|
||||
})
|
||||
@ -58,8 +60,8 @@ describe('smartfile', function () {
|
||||
it('should get a file tree', function (done) {
|
||||
smartfile.fs.listFileTree(path.resolve('./test/'), '**/*.txt')
|
||||
.then(function (folderArrayArg) {
|
||||
should(folderArrayArg).containDeep(['testfolder/testfile1.txt'])
|
||||
should(folderArrayArg).not.containDeep(['mytest.json'])
|
||||
expect(folderArrayArg).to.deep.include('testfolder/testfile1.txt')
|
||||
expect(folderArrayArg).to.not.deep.include('mytest.json')
|
||||
done()
|
||||
})
|
||||
})
|
||||
@ -85,19 +87,19 @@ describe('smartfile', function () {
|
||||
})
|
||||
it('smartfile.fs.removeSync -> should remove single files synchronouly',function() {
|
||||
smartfile.fs.removeSync('./test/temp/testfile1.txt')
|
||||
should(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).be.false()
|
||||
expect(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).to.be.false
|
||||
})
|
||||
it('smartfile.fs.removeMany -> should remove and array of files',function(done) {
|
||||
smartfile.fs.removeMany(['./test/temp/testfile1.txt','./test/temp/testfile2.txt']).then(() => {
|
||||
should(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).be.false()
|
||||
should(smartfile.fs.fileExistsSync('./test/temp/testfile2.txt')).be.false()
|
||||
expect(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).to.be.false
|
||||
expect(smartfile.fs.fileExistsSync('./test/temp/testfile2.txt')).to.be.false
|
||||
done()
|
||||
})
|
||||
})
|
||||
it('smartfile.fs.removeManySync -> should remove and array of single files synchronouly',function() {
|
||||
smartfile.fs.removeManySync(['./test/temp/testfile1.txt','./test/temp/testfile2.txt'])
|
||||
should(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).be.false()
|
||||
should(smartfile.fs.fileExistsSync('./test/temp/testfile2.txt')).be.false()
|
||||
expect(smartfile.fs.fileExistsSync('./test/temp/testfile1.txt')).to.be.false
|
||||
expect(smartfile.fs.fileExistsSync('./test/temp/testfile2.txt')).to.be.false
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -105,7 +107,7 @@ describe('smartfile', function () {
|
||||
describe('.interpreter', function () {
|
||||
describe('.filetype()', function () {
|
||||
it('should get the file type from a string', function () {
|
||||
should(smartfile.interpreter.filetype('./somefolder/data.json')).equal('json')
|
||||
expect(smartfile.interpreter.filetype('./somefolder/data.json')).equal('json')
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -114,8 +116,8 @@ describe('smartfile', function () {
|
||||
describe('.toObjectSync()', function () {
|
||||
it('should read an ' + '.yaml' + ' file to an object', function () {
|
||||
let testData = smartfile.fs.toObjectSync('./test/mytest.yaml')
|
||||
should(testData).have.property('key1', 'this works')
|
||||
should(testData).have.property('key2', 'this works too')
|
||||
expect(testData).have.property('key1', 'this works')
|
||||
expect(testData).have.property('key2', 'this works too')
|
||||
|
||||
})
|
||||
it('should state unknown file type for unknown file types', function () {
|
||||
@ -123,23 +125,21 @@ describe('smartfile', function () {
|
||||
})
|
||||
it('should read an ' + '.json' + ' file to an object', function () {
|
||||
let testData = smartfile.fs.toObjectSync('./test/mytest.json')
|
||||
should(testData).have.property('key1', 'this works')
|
||||
should(testData).have.property('key2', 'this works too')
|
||||
expect(testData).have.property('key1', 'this works')
|
||||
expect(testData).have.property('key2', 'this works too')
|
||||
|
||||
})
|
||||
})
|
||||
describe('.toStringSync()', function () {
|
||||
it('should read a file to a string', function () {
|
||||
should.equal(
|
||||
smartfile.fs.toStringSync('./test/mytest.txt'),
|
||||
'Some TestString &&%$'
|
||||
)
|
||||
expect(smartfile.fs.toStringSync('./test/mytest.txt'))
|
||||
.to.equal('Some TestString &&%$')
|
||||
})
|
||||
})
|
||||
describe('.toVinylSync', function () {
|
||||
it('should read an ' + '.json OR .yaml' + ' file to an ' + 'vinyl file object', function () {
|
||||
let testData = smartfile.fs.toVinylSync('./test/mytest.json')
|
||||
should(vinyl.isVinyl(testData)).be.true()
|
||||
expect(vinyl.isVinyl(testData)).to.be.true
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -155,7 +155,7 @@ describe('smartfile', function () {
|
||||
it('should produce a vinylFile', function () {
|
||||
let localString = 'myString'
|
||||
let localOptions = { filename: 'vinylfile2', base: '/someDir' }
|
||||
should(smartfile.memory.toVinylFileSync(localString, localOptions) instanceof vinyl).be.true()
|
||||
expect(smartfile.memory.toVinylFileSync(localString, localOptions) instanceof vinyl).to.be.true
|
||||
})
|
||||
})
|
||||
describe('toVinylArraySync()', function () {
|
||||
@ -163,10 +163,10 @@ describe('smartfile', function () {
|
||||
let localStringArray = ['string1', 'string2', 'string3']
|
||||
let localOptions = { filename: 'vinylfile2', base: '/someDir' }
|
||||
let testResult = smartfile.memory.toVinylArraySync(localStringArray, localOptions)
|
||||
should(testResult).be.Array()
|
||||
should(testResult.length === 3).be.true()
|
||||
expect(testResult).to.be.a('array')
|
||||
expect(testResult.length === 3).to.be.true
|
||||
for (let myKey in testResult) {
|
||||
should(testResult[myKey] instanceof vinyl).be.true()
|
||||
expect(testResult[myKey] instanceof vinyl).to.be.true
|
||||
}
|
||||
})
|
||||
})
|
||||
@ -177,7 +177,7 @@ describe('smartfile', function () {
|
||||
path: '/test.txt',
|
||||
contents: new Buffer('myString')
|
||||
}))
|
||||
should(localString).equal('myString')
|
||||
expect(localString).equal('myString')
|
||||
})
|
||||
})
|
||||
describe('toFs()', function () {
|
||||
@ -207,18 +207,21 @@ describe('smartfile', function () {
|
||||
smartfile.remote.toString(
|
||||
'https://raw.githubusercontent.com/pushrocks/smartfile/master/test/mytest.txt'
|
||||
).then(function (responseString) {
|
||||
should.equal(responseString, 'Some TestString &&%$')
|
||||
expect(responseString).to.equal('Some TestString &&%$')
|
||||
done()
|
||||
})
|
||||
})
|
||||
it('should reject a Promise when the link is false', function (done) {
|
||||
this.timeout(10000)
|
||||
smartfile.remote.toString('https://push.rocks/doesnotexist.txt')
|
||||
.then(function () {
|
||||
throw new Error('this test should not be resolved')
|
||||
}, function () {
|
||||
done()
|
||||
})
|
||||
.then(
|
||||
function () {
|
||||
throw new Error('this test should not be resolved')
|
||||
},
|
||||
function () {
|
||||
done()
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user