|
| 1 | +import * as chai from 'chai'; |
| 2 | +import 'chai/register-should'; |
| 3 | +import * as sinonChai from 'sinon-chai'; |
| 4 | +import 'mocha'; |
| 5 | +import * as path from 'path'; |
| 6 | + |
| 7 | +import { gatherQlFiles } from '../../src/files'; |
| 8 | + |
| 9 | +chai.use(sinonChai); |
| 10 | +const expect = chai.expect; |
| 11 | + |
| 12 | +describe('files', () => { |
| 13 | + const dataDir = path.join(path.dirname(__dirname), 'data'); |
| 14 | + const data2Dir = path.join(path.dirname(__dirname), 'data2'); |
| 15 | + |
| 16 | + it('should pass', () => { |
| 17 | + expect(true).to.be.eq(true); |
| 18 | + }); |
| 19 | + it('should find one file', async () => { |
| 20 | + const singleFile = path.join(dataDir, 'query.ql'); |
| 21 | + const result = await gatherQlFiles([singleFile]); |
| 22 | + expect(result).to.deep.equal([[singleFile], false]); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should find no files', async () => { |
| 26 | + const result = await gatherQlFiles([]); |
| 27 | + expect(result).to.deep.equal([[], false]); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should find no files', async () => { |
| 31 | + const singleFile = path.join(dataDir, 'library.qll'); |
| 32 | + const result = await gatherQlFiles([singleFile]); |
| 33 | + expect(result).to.deep.equal([[], false]); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should handle invalid file', async () => { |
| 37 | + const singleFile = path.join(dataDir, 'xxx'); |
| 38 | + const result = await gatherQlFiles([singleFile]); |
| 39 | + expect(result).to.deep.equal([[], false]); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should find two files', async () => { |
| 43 | + const singleFile = path.join(dataDir, 'query.ql'); |
| 44 | + const otherFile = path.join(dataDir, 'multiple-result-sets.ql'); |
| 45 | + const notFile = path.join(dataDir, 'library.qll'); |
| 46 | + const invalidFile = path.join(dataDir, 'xxx'); |
| 47 | + |
| 48 | + const result = await gatherQlFiles([singleFile, otherFile, notFile, invalidFile]); |
| 49 | + expect(result.sort()).to.deep.equal([[singleFile, otherFile], false]); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should scan a directory', async () => { |
| 53 | + const singleFile = path.join(dataDir, 'query.ql'); |
| 54 | + const otherFile = path.join(dataDir, 'multiple-result-sets.ql'); |
| 55 | + |
| 56 | + const result = await gatherQlFiles([dataDir]); |
| 57 | + expect(result.sort()).to.deep.equal([[otherFile, singleFile], true]); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should scan a directory and some files', async () => { |
| 61 | + const singleFile = path.join(dataDir, 'query.ql'); |
| 62 | + const empty1File = path.join(data2Dir, 'empty1.ql'); |
| 63 | + const empty2File = path.join(data2Dir, 'sub-folder', 'empty2.ql'); |
| 64 | + |
| 65 | + const result = await gatherQlFiles([singleFile, data2Dir]); |
| 66 | + expect(result.sort()).to.deep.equal([[singleFile, empty1File, empty2File], true]); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should avoid duplicates', async () => { |
| 70 | + const singleFile = path.join(dataDir, 'query.ql'); |
| 71 | + const otherFile = path.join(dataDir, 'multiple-result-sets.ql'); |
| 72 | + |
| 73 | + const result = await gatherQlFiles([singleFile, dataDir, otherFile]); |
| 74 | + expect(result.sort()).to.deep.equal([[singleFile, otherFile], true]); |
| 75 | + }); |
| 76 | +}); |
0 commit comments