license-check-and-add
Version:
A tool to enable the checking, inserting and removal of licenses
89 lines • 4.41 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var chai = __importStar(require("chai"));
var mockery = __importStar(require("mockery"));
var path = __importStar(require("path"));
var sinon = __importStar(require("sinon"));
var sinon_chai_1 = __importDefault(require("sinon-chai"));
var file_finder_1 = require("./file-finder");
var expect = chai.expect;
chai.use(sinon_chai_1.default);
describe('#FileFinder', function () {
var sandbox;
var globbySyncStub;
var gitignoreToGlobStub;
var FileFinder;
var ignoreInput = ['should', 'ignore'];
var mockValidPaths = ['some', 'valid', 'paths'];
var globbyConfig = {
dot: true,
expandDirectories: true,
};
before(function () {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false,
});
});
beforeEach(function () {
sandbox = sinon.createSandbox();
globbySyncStub = sandbox.stub().returns(mockValidPaths);
gitignoreToGlobStub = sandbox.stub().returns(['some', 'ignore', 'values']);
mockery.registerMock('globby', { sync: globbySyncStub });
mockery.registerMock('gitignore-to-glob', gitignoreToGlobStub);
delete require.cache[require.resolve('./file-finder')];
FileFinder = require('./file-finder').FileFinder;
});
afterEach(function () {
sandbox.restore();
mockery.deregisterAll();
});
after(function () {
mockery.disable();
});
it('should return the list of files from globby filtered by ignore list passed', function () {
var paths = FileFinder.getPaths(ignoreInput, true);
expect(paths).to.deep.equal(mockValidPaths);
expect(globbySyncStub).to.have.been.calledOnceWithExactly(['**/*'], Object.assign(globbyConfig, { ignore: ignoreInput }));
});
it('should return the list of files from globby filtered by ignore list passed and default ignore', function () {
var paths = FileFinder.getPaths(ignoreInput, false);
expect(paths).to.deep.equal(mockValidPaths);
expect(globbySyncStub).to.have.been.calledOnceWithExactly(['**/*'], Object.assign(globbyConfig, { ignore: ignoreInput.concat(file_finder_1.DEFAULT_IGNORES) }));
});
it('should return the list of file from globby filtered by ignore file passed and default ignores', function () {
var paths = FileFinder.getPaths([], false, 'some/file/path');
expect(paths).to.deep.equal(mockValidPaths);
expect(globbySyncStub).to.have.been.calledOnceWithExactly(['**/*', 'some', 'ignore', 'values', '!some/file/path'], Object.assign(globbyConfig, { ignore: file_finder_1.DEFAULT_IGNORES }));
expect(gitignoreToGlobStub).to.have.been.calledOnceWithExactly(path.resolve(process.cwd(), 'some/file/path'));
});
it('should combine ignore array and ignore file', function () {
var paths = FileFinder.getPaths(ignoreInput, false, 'some/file/path');
expect(paths).to.deep.equal(mockValidPaths);
expect(globbySyncStub).to.have.been.calledOnceWithExactly(['**/*', 'some', 'ignore', 'values', '!some/file/path'], Object.assign(globbyConfig, { ignore: ignoreInput.concat(file_finder_1.DEFAULT_IGNORES) }));
expect(gitignoreToGlobStub).to.have.been.calledOnceWithExactly(path.resolve(process.cwd(), 'some/file/path'));
});
});
//# sourceMappingURL=file-finder.spec.js.map
;