|
| 1 | +import { getProjectDetails } from '@angular/cli/utilities/project'; |
| 2 | +import * as mockFs from 'mock-fs'; |
| 3 | +import * as os from 'os'; |
| 4 | +import {join} from 'path'; |
| 5 | + |
| 6 | +const homedir = os.homedir(); |
| 7 | +const cwds = [`${homedir}/proj`, `${homedir}/proj/abc`]; |
| 8 | +cwds.forEach(cwd => { |
| 9 | + describe(`getProjectDetails (cwd: ${cwd})`, () => { |
| 10 | + beforeEach(() => { |
| 11 | + spyOn(process, 'cwd').and.callFake(() => cwd); |
| 12 | + }); |
| 13 | + |
| 14 | + afterEach(() => { |
| 15 | + mockFs.restore(); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should handle finding "angular.json"', () => { |
| 19 | + mockFs({ |
| 20 | + [`${homedir}/proj/angular.json`]: 'foo' |
| 21 | + }); |
| 22 | + const result = getProjectDetails(); |
| 23 | + expect(result.root).toEqual(join(homedir, 'proj')); |
| 24 | + expect(result.configFile).toEqual('angular.json'); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should handle finding ".angular.json"', () => { |
| 28 | + mockFs({ |
| 29 | + [`${homedir}/proj/.angular.json`]: 'foo' |
| 30 | + }); |
| 31 | + const result = getProjectDetails(); |
| 32 | + expect(result.root).toEqual(join(homedir, 'proj')); |
| 33 | + expect(result.configFile).toEqual('.angular.json'); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should handle finding "angular-cli.json"', () => { |
| 37 | + mockFs({ |
| 38 | + [`${homedir}/proj/angular-cli.json`]: 'foo' |
| 39 | + }); |
| 40 | + const result = getProjectDetails(); |
| 41 | + expect(result.root).toEqual(join(homedir, 'proj')); |
| 42 | + expect(result.configFile).toEqual('angular-cli.json'); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should handle finding ".angular-cli.json"', () => { |
| 46 | + mockFs({ |
| 47 | + [`${homedir}/proj/.angular-cli.json`]: 'foo' |
| 48 | + }); |
| 49 | + const result = getProjectDetails(); |
| 50 | + expect(result.root).toEqual(join(homedir, 'proj')); |
| 51 | + expect(result.configFile).toEqual('.angular-cli.json'); |
| 52 | + }); |
| 53 | + |
| 54 | + it('should handle not finding a config file at all', () => { |
| 55 | + mockFs({}); |
| 56 | + const result = getProjectDetails(); |
| 57 | + expect(result).toEqual(null); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should handle searching up the home directory', () => { |
| 61 | + mockFs({ |
| 62 | + [`${homedir}/angular.json`]: 'foo' |
| 63 | + }); |
| 64 | + const result = getProjectDetails(); |
| 65 | + expect(result).toEqual(null); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should handle searching up the home directory', () => { |
| 69 | + mockFs({ |
| 70 | + [`${homedir}/.angular-cli.json`]: 'foo' |
| 71 | + }); |
| 72 | + const result = getProjectDetails(); |
| 73 | + expect(result).toEqual(null); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should handle searching up the home directory and finding a project', () => { |
| 77 | + mockFs({ |
| 78 | + [`${homedir}/angular.json`]: 'foo', |
| 79 | + [`${homedir}/package.json`]: JSON.stringify({ |
| 80 | + dependencies: { |
| 81 | + '@angular/cli': '0.0.0' |
| 82 | + } |
| 83 | + }) |
| 84 | + }); |
| 85 | + const result = getProjectDetails(); |
| 86 | + expect(result.root).toEqual(homedir); |
| 87 | + expect(result.configFile).toEqual('angular.json'); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should handle searching up the home directory and finding a project', () => { |
| 91 | + mockFs({ |
| 92 | + [`${homedir}/.angular-cli.json`]: 'foo', |
| 93 | + [`${homedir}/package.json`]: JSON.stringify({ |
| 94 | + dependencies: { |
| 95 | + '@angular/cli': '0.0.0' |
| 96 | + } |
| 97 | + }) |
| 98 | + }); |
| 99 | + const result = getProjectDetails(); |
| 100 | + expect(result.root).toEqual(homedir); |
| 101 | + expect(result.configFile).toEqual('.angular-cli.json'); |
| 102 | + }); |
| 103 | + }); |
| 104 | +}); |
0 commit comments