|
| 1 | +const chai = require("chai"), |
| 2 | + rewire = require("rewire"), |
| 3 | + chaiAsPromised = require("chai-as-promised"); |
| 4 | + |
| 5 | +const utils = require("../../../../bin/helpers/utils"), |
| 6 | + Constants = require("../../../../bin/helpers/constants"), |
| 7 | + logger = require("../../../../bin/helpers/logger").winstonLogger; |
| 8 | + |
| 9 | +chai.use(chaiAsPromised); |
| 10 | +logger.transports["console.info"].silent = true; |
| 11 | + |
| 12 | +const archiver = rewire("../../../../bin/helpers/archiver"); |
| 13 | + |
| 14 | +_getFilesToIgnore = archiver.__get__("getFilesToIgnore"); |
| 15 | + |
| 16 | +describe("archiver.js", () => { |
| 17 | + |
| 18 | + describe("getFilesToIgnore", () => { |
| 19 | + it("no args, no exclude in runSettings", () => { |
| 20 | + chai.expect(_getFilesToIgnore({}, undefined)).to.be.eql(Constants.filesToIgnoreWhileUploading); |
| 21 | + }); |
| 22 | + |
| 23 | + it("args passed, no exclude in runSettings", () => { |
| 24 | + let excludeFiles = "file1.js, file2.json"; |
| 25 | + let argsToArray = utils.fixCommaSeparatedString(excludeFiles).split(','); |
| 26 | + chai.expect(_getFilesToIgnore({}, excludeFiles)).to.be.eql(Constants.filesToIgnoreWhileUploading.concat(argsToArray)); |
| 27 | + |
| 28 | + excludeFiles = "file1.js,file2.json"; |
| 29 | + argsToArray = utils.fixCommaSeparatedString(excludeFiles).split(','); |
| 30 | + chai.expect(_getFilesToIgnore({}, excludeFiles)).to.be.eql(Constants.filesToIgnoreWhileUploading.concat(argsToArray)); |
| 31 | + |
| 32 | + excludeFiles = " file1.js , file2.json "; |
| 33 | + argsToArray = utils.fixCommaSeparatedString(excludeFiles).split(','); |
| 34 | + chai.expect(_getFilesToIgnore({}, excludeFiles)).to.be.eql(Constants.filesToIgnoreWhileUploading.concat(argsToArray)); |
| 35 | + }); |
| 36 | + |
| 37 | + it("args passed, exclude added in runSettings", () => { |
| 38 | + // args preceed over config file |
| 39 | + let excludeFiles = "file1.js, file2.json "; |
| 40 | + let argsToArray = utils.fixCommaSeparatedString(excludeFiles).split(','); |
| 41 | + |
| 42 | + let runSettings = { exclude: [] }; |
| 43 | + chai.expect(_getFilesToIgnore(runSettings, excludeFiles)).to.be.eql(Constants.filesToIgnoreWhileUploading.concat(argsToArray)); |
| 44 | + |
| 45 | + runSettings = { exclude: ["sample1.js", "sample2.json"] }; |
| 46 | + chai.expect(_getFilesToIgnore(runSettings, excludeFiles)).to.be.eql(Constants.filesToIgnoreWhileUploading.concat(argsToArray)); |
| 47 | + }); |
| 48 | + |
| 49 | + it("no args, exclude added in runSettings", () => { |
| 50 | + let runSettings = { exclude: [] }; |
| 51 | + chai.expect(_getFilesToIgnore(runSettings, undefined)).to.be.eql(Constants.filesToIgnoreWhileUploading); |
| 52 | + |
| 53 | + runSettings = { exclude: ["sample1.js", "sample2.json"] }; |
| 54 | + chai.expect(_getFilesToIgnore(runSettings, undefined)).to.be.eql(Constants.filesToIgnoreWhileUploading.concat(runSettings.exclude)); |
| 55 | + }); |
| 56 | + }); |
| 57 | +}); |
0 commit comments