|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const {DependendenciesManager} = require('../lib/dependencies.js'); |
| 4 | +const assert = require('chai').assert; |
| 5 | +const fs = require('fs-extra'); |
| 6 | +const path = require('path'); |
| 7 | + |
| 8 | +describe('DependencyProcessor - APIC v5', function() { |
| 9 | + const logger = { |
| 10 | + warn: function() { |
| 11 | + // console.warn.apply(console, arguments); |
| 12 | + }, |
| 13 | + info: function() { |
| 14 | + // console.info.apply(console, arguments); |
| 15 | + }, |
| 16 | + log: function() { |
| 17 | + // console.log.apply(console, arguments); |
| 18 | + }, |
| 19 | + error: function() { |
| 20 | + // console.error.apply(console, arguments); |
| 21 | + } |
| 22 | + }; |
| 23 | + const workingDir = 'test/dependency-test'; |
| 24 | + let processor; |
| 25 | + const bowerFile = path.join(workingDir, 'bower.json'); |
| 26 | + const bowerContent = { |
| 27 | + name: 'test', |
| 28 | + description: 'test', |
| 29 | + version: '0.0.1', |
| 30 | + license: 'Apache-2.0 OR CC-BY-4.0', |
| 31 | + authors: [ |
| 32 | + 'The Advanced REST client authors <arc@mulesoft.com>' |
| 33 | + ], |
| 34 | + dependencies: { |
| 35 | + 'arc-definitions': 'advanced-rest-client/arc-definitions#^2.0.0' |
| 36 | + } |
| 37 | + }; |
| 38 | + before(function() { |
| 39 | + return fs.ensureDir(workingDir); |
| 40 | + }); |
| 41 | + |
| 42 | + after(function() { |
| 43 | + fs.remove(workingDir); |
| 44 | + }); |
| 45 | + |
| 46 | + /** |
| 47 | + * @param {Array<String>} files |
| 48 | + * @return {Promise} |
| 49 | + */ |
| 50 | + function finishTest(files) { |
| 51 | + let promise = []; |
| 52 | + if (files instanceof Array) { |
| 53 | + let list = files.map((file) => fs.pathExists(file)); |
| 54 | + promise = Promise.all(list); |
| 55 | + } else { |
| 56 | + promise = fs.pathExists(files); |
| 57 | + } |
| 58 | + return promise |
| 59 | + .then((result) => { |
| 60 | + if (result instanceof Array) { |
| 61 | + result = result.some((item) => item === false); |
| 62 | + assert.isFalse(result); |
| 63 | + } else { |
| 64 | + assert.isTrue(result); |
| 65 | + } |
| 66 | + }); |
| 67 | + } |
| 68 | + |
| 69 | + beforeEach(function() { |
| 70 | + const options = { |
| 71 | + app: false, |
| 72 | + parser: false, |
| 73 | + isV4: false, |
| 74 | + optionalDependencies: ['advanced-rest-client/bytes-counter#^2.0.0'] |
| 75 | + }; |
| 76 | + processor = new DependendenciesManager(workingDir, options, logger); |
| 77 | + processor.runningRoot = true; |
| 78 | + return fs.ensureDir(workingDir); |
| 79 | + }); |
| 80 | + |
| 81 | + afterEach(function() { |
| 82 | + return fs.remove(workingDir); |
| 83 | + }); |
| 84 | + |
| 85 | + it('Should install basic dependencies', function() { |
| 86 | + this.timeout(300000); |
| 87 | + return fs.writeJson(bowerFile, bowerContent) |
| 88 | + .then(() => processor.installDependencies()) |
| 89 | + .then(() => { |
| 90 | + return finishTest([ |
| 91 | + path.join(workingDir, 'bower_components'), |
| 92 | + path.join(workingDir, 'bower_components', 'arc-definitions') |
| 93 | + ]); |
| 94 | + }); |
| 95 | + }); |
| 96 | + |
| 97 | + it('Should install additional dependencies', function() { |
| 98 | + this.timeout(300000); |
| 99 | + return fs.writeJson(bowerFile, bowerContent) |
| 100 | + .then(() => processor.installDependencies()) |
| 101 | + .then(() => { |
| 102 | + return finishTest([ |
| 103 | + path.join(workingDir, 'bower_components', 'bytes-counter') |
| 104 | + ]); |
| 105 | + }); |
| 106 | + }); |
| 107 | +}); |
0 commit comments