UNPKG

license-check-and-add

Version:

A tool to enable the checking, inserting and removal of licenses

69 lines 3.26 kB
"use strict"; 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; }; Object.defineProperty(exports, "__esModule", { value: true }); var chai = __importStar(require("chai")); var childProcess = __importStar(require("child_process")); var fs = __importStar(require("fs-extra")); var path = __importStar(require("path")); var utils_1 = require("../utils"); var expect = chai.expect; describe('#Non Identified Regex', function () { var packageJson = fs.readJSONSync(path.resolve(__dirname, '../../package.json')); var pwd = process.cwd(); var tmp = '/tmp/license-check-and-add'; var bin = path.resolve(__dirname, '../..', packageJson.bin['license-check-and-add']); var config = path.resolve(__dirname, 'license-check-and-add-config.json'); before(function () { fs.copySync(path.resolve(__dirname, 'original-files'), tmp); fs.copyFileSync(path.resolve(__dirname, '.ignorefile'), path.resolve(tmp, '.ignorefile')); process.chdir(tmp); }); after(function () { process.chdir(pwd); fs.removeSync(tmp); }); describe('Check licenses', function () { it('should check licenses', function () { expect(function () { childProcess.execSync("node " + bin + " check -f " + config); }).to.throw(/1 file\(s\) did not have the license/); }); }); describe('Insert licenses', function () { it('should insert the license into those without', function () { var goalFilesDir = path.resolve(__dirname, 'goal-files/insert'); var stdout = childProcess.execSync("node " + bin + " add -f " + config).toString(); // tslint:disable-next-line: no-unused-expression expect(utils_1.directoriesMatch(tmp, goalFilesDir)).to.be.true; expect(stdout).to.match(/Inserted license into 1 file\(s\)/); }); }); describe('Remove licenses', function () { it('should remove the license from those with', function () { var goalFilesDir = path.resolve(__dirname, 'goal-files/remove'); var stdout = childProcess.execSync("node " + bin + " remove -f " + config).toString(); // tslint:disable-next-line: no-unused-expression expect(utils_1.directoriesMatch(tmp, goalFilesDir)).to.be.true; expect(stdout).to.match(/Removed license from 2 file\(s\)/); }); }); }); //# sourceMappingURL=integration-tests.spec.js.map