2017-10-06 05:48:18 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const fs = require('fs-extra');
|
2019-02-04 09:45:45 -05:00
|
|
|
const lockfile = require('@yarnpkg/lockfile');
|
2017-10-06 05:48:18 -04:00
|
|
|
const path = require('canonical-path');
|
|
|
|
const shelljs = require('shelljs');
|
|
|
|
|
|
|
|
const NgPackagesInstaller = require('./index');
|
|
|
|
|
|
|
|
describe('NgPackagesInstaller', () => {
|
|
|
|
const rootDir = 'root/dir';
|
|
|
|
const absoluteRootDir = path.resolve(rootDir);
|
|
|
|
const nodeModulesDir = path.resolve(absoluteRootDir, 'node_modules');
|
|
|
|
const packageJsonPath = path.resolve(absoluteRootDir, 'package.json');
|
2019-02-04 09:45:45 -05:00
|
|
|
const yarnLockPath = path.resolve(absoluteRootDir, 'yarn.lock');
|
2017-10-06 05:48:18 -04:00
|
|
|
const packagesDir = path.resolve(path.resolve(__dirname, '../../../dist/packages-dist'));
|
2017-10-06 17:25:27 -04:00
|
|
|
const toolsDir = path.resolve(path.resolve(__dirname, '../../../dist/tools/@angular'));
|
2017-10-06 05:48:18 -04:00
|
|
|
let installer;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(fs, 'existsSync');
|
|
|
|
spyOn(fs, 'readFileSync');
|
|
|
|
spyOn(fs, 'writeFileSync');
|
|
|
|
spyOn(shelljs, 'exec');
|
|
|
|
spyOn(shelljs, 'rm');
|
|
|
|
spyOn(console, 'log');
|
|
|
|
spyOn(console, 'warn');
|
|
|
|
installer = new NgPackagesInstaller(rootDir);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('checkDependencies()', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(installer, '_printWarning');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not print a warning if there is no _local_.json file', () => {
|
|
|
|
fs.existsSync.and.returnValue(false);
|
|
|
|
installer.checkDependencies();
|
|
|
|
expect(fs.existsSync).toHaveBeenCalledWith(path.resolve(rootDir, 'node_modules/_local_.json'));
|
|
|
|
expect(installer._printWarning).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should print a warning if there is a _local_.json file', () => {
|
|
|
|
fs.existsSync.and.returnValue(true);
|
|
|
|
installer.checkDependencies();
|
|
|
|
expect(fs.existsSync).toHaveBeenCalledWith(path.resolve(rootDir, 'node_modules/_local_.json'));
|
|
|
|
expect(installer._printWarning).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('installLocalDependencies()', () => {
|
2017-10-09 06:11:13 -04:00
|
|
|
const copyJsonObj = obj => JSON.parse(JSON.stringify(obj));
|
2017-10-06 05:48:18 -04:00
|
|
|
let dummyNgPackages, dummyPackage, dummyPackageJson, expectedModifiedPackage, expectedModifiedPackageJson;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(installer, '_checkLocalMarker');
|
2019-02-04 07:55:58 -05:00
|
|
|
spyOn(installer, '_installDeps');
|
|
|
|
spyOn(installer, '_setLocalMarker');
|
2017-10-06 05:48:18 -04:00
|
|
|
|
2019-02-04 09:45:45 -05:00
|
|
|
spyOn(installer, '_parseLockfile').and.returnValue({
|
|
|
|
'rxjs@^6.3.0': {version: '6.3.3'},
|
|
|
|
'zone.js@^0.8.26': {version: '0.8.27'}
|
|
|
|
});
|
|
|
|
|
2017-10-06 05:48:18 -04:00
|
|
|
// These are the packages that are "found" in the dist directory
|
|
|
|
dummyNgPackages = {
|
2017-10-09 06:11:13 -04:00
|
|
|
'@angular/core': {
|
|
|
|
parentDir: packagesDir,
|
|
|
|
packageJsonPath: `${packagesDir}/core/package.json`,
|
2019-02-04 09:45:45 -05:00
|
|
|
config: {
|
|
|
|
peerDependencies: {
|
|
|
|
'rxjs': '^6.4.0',
|
|
|
|
'some-package': '5.0.1',
|
|
|
|
'zone.js': '~0.8.26'
|
|
|
|
}
|
|
|
|
}
|
2017-10-09 06:11:13 -04:00
|
|
|
},
|
|
|
|
'@angular/common': {
|
|
|
|
parentDir: packagesDir,
|
|
|
|
packageJsonPath: `${packagesDir}/common/package.json`,
|
|
|
|
config: { peerDependencies: { '@angular/core': '4.4.4-1ab23cd4' } }
|
|
|
|
},
|
|
|
|
'@angular/compiler': {
|
|
|
|
parentDir: packagesDir,
|
|
|
|
packageJsonPath: `${packagesDir}/compiler/package.json`,
|
|
|
|
config: { peerDependencies: { '@angular/common': '4.4.4-1ab23cd4' } }
|
|
|
|
},
|
|
|
|
'@angular/compiler-cli': {
|
|
|
|
parentDir: toolsDir,
|
|
|
|
packageJsonPath: `${toolsDir}/compiler-cli/package.json`,
|
|
|
|
config: {
|
|
|
|
dependencies: { '@angular/tsc-wrapped': '4.4.4-1ab23cd4' },
|
|
|
|
peerDependencies: { typescript: '^2.4.2', '@angular/compiler': '4.4.4-1ab23cd4' }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'@angular/tsc-wrapped': {
|
|
|
|
parentDir: toolsDir,
|
|
|
|
packageJsonPath: `${toolsDir}/tsc-wrapped/package.json`,
|
|
|
|
config: {
|
|
|
|
devDependencies: { '@angular/common': '4.4.4-1ab23cd4' },
|
|
|
|
peerDependencies: { tsickle: '^1.4.0' }
|
|
|
|
}
|
|
|
|
}
|
2017-10-06 05:48:18 -04:00
|
|
|
};
|
2017-10-09 06:11:13 -04:00
|
|
|
spyOn(installer, '_getDistPackages').and.callFake(() => copyJsonObj(dummyNgPackages));
|
2017-10-06 05:48:18 -04:00
|
|
|
|
|
|
|
// This is the package.json in the "test" folder
|
|
|
|
dummyPackage = {
|
|
|
|
dependencies: {
|
|
|
|
'@angular/core': '4.4.1',
|
2019-02-04 09:45:45 -05:00
|
|
|
'@angular/common': '4.4.1',
|
|
|
|
rxjs: '^6.3.0'
|
2017-10-06 05:48:18 -04:00
|
|
|
},
|
|
|
|
devDependencies: {
|
2019-02-04 09:45:45 -05:00
|
|
|
'@angular/compiler-cli': '4.4.1',
|
|
|
|
'zone.js': '^0.8.26'
|
2017-10-06 05:48:18 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
dummyPackageJson = JSON.stringify(dummyPackage);
|
|
|
|
fs.readFileSync.and.returnValue(dummyPackageJson);
|
|
|
|
|
|
|
|
// This is the package.json that is temporarily written to the "test" folder
|
|
|
|
// Note that the Angular (dev)dependencies have been modified to use a "file:" path
|
2019-02-04 09:45:45 -05:00
|
|
|
// And that the peerDependencies from `dummyNgPackages` have been updated or added as
|
|
|
|
// (dev)dependencies (unless the current version in lockfile satisfies semver).
|
|
|
|
//
|
|
|
|
// For example, `zone.js@0.8.27` (from lockfile) satisfies `zone.js@~0.8.26` (from
|
|
|
|
// `@angular/core`), thus `zone.js: ^0.8.26` (from original `package.json`) is retained.
|
|
|
|
// In contrast, `rxjs@6.3.3` (from lockfile) does not satisfy `rxjs@^6.4.0 (from
|
|
|
|
// `@angular/core`), thus `rxjs: ^6.3.0` (from original `package.json`) is replaced with
|
|
|
|
// `rxjs: ^6.4.0` (from `@angular/core`).
|
2017-10-06 05:48:18 -04:00
|
|
|
expectedModifiedPackage = {
|
|
|
|
dependencies: {
|
|
|
|
'@angular/core': `file:${packagesDir}/core`,
|
2019-02-04 09:45:45 -05:00
|
|
|
'@angular/common': `file:${packagesDir}/common`,
|
|
|
|
'rxjs': '^6.4.0'
|
2017-10-06 05:48:18 -04:00
|
|
|
},
|
|
|
|
devDependencies: {
|
2017-10-06 17:25:27 -04:00
|
|
|
'@angular/compiler-cli': `file:${toolsDir}/compiler-cli`,
|
2019-02-04 09:45:45 -05:00
|
|
|
'zone.js': '^0.8.26',
|
2018-03-06 12:01:25 -05:00
|
|
|
'some-package': '5.0.1',
|
2017-10-06 05:48:18 -04:00
|
|
|
typescript: '^2.4.2'
|
|
|
|
},
|
|
|
|
__angular: { local: true }
|
|
|
|
};
|
|
|
|
expectedModifiedPackageJson = JSON.stringify(expectedModifiedPackage, null, 2);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when there is a local package marker', () => {
|
2019-02-04 07:55:58 -05:00
|
|
|
beforeEach(() => installer._checkLocalMarker.and.returnValue(true));
|
|
|
|
|
2017-10-06 05:48:18 -04:00
|
|
|
it('should not continue processing', () => {
|
|
|
|
installer.installLocalDependencies();
|
|
|
|
expect(installer._checkLocalMarker).toHaveBeenCalled();
|
|
|
|
expect(installer._getDistPackages).not.toHaveBeenCalled();
|
|
|
|
});
|
2019-02-04 07:55:58 -05:00
|
|
|
|
|
|
|
it('should continue processing (without checking for local marker) if `force` is true', () => {
|
|
|
|
installer.force = true;
|
|
|
|
installer.installLocalDependencies();
|
|
|
|
expect(installer._checkLocalMarker).not.toHaveBeenCalled();
|
|
|
|
expect(installer._getDistPackages).toHaveBeenCalled();
|
|
|
|
});
|
2017-10-06 05:48:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('when there is no local package marker', () => {
|
|
|
|
let log;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
log = [];
|
|
|
|
fs.writeFileSync.and.callFake((filePath, contents) => filePath === packageJsonPath && log.push(`writeFile: ${contents}`));
|
2019-02-04 08:03:25 -05:00
|
|
|
installer._installDeps.and.callFake((...args) => log.push(`installDeps: ${args.join(' ')}`));
|
2017-10-06 05:48:18 -04:00
|
|
|
installer._checkLocalMarker.and.returnValue(false);
|
|
|
|
installer.installLocalDependencies();
|
|
|
|
});
|
|
|
|
|
2019-02-04 09:45:45 -05:00
|
|
|
it('should parse the lockfile and get the dist packages', () => {
|
2017-10-06 05:48:18 -04:00
|
|
|
expect(installer._checkLocalMarker).toHaveBeenCalled();
|
2019-02-04 09:45:45 -05:00
|
|
|
expect(installer._parseLockfile).toHaveBeenCalledWith(yarnLockPath);
|
2017-10-06 05:48:18 -04:00
|
|
|
expect(installer._getDistPackages).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2017-10-09 06:11:13 -04:00
|
|
|
it('should temporarily overwrite the package.json files of local Angular packages', () => {
|
|
|
|
const pkgJsonFor = pkgName => dummyNgPackages[`@angular/${pkgName}`].packageJsonPath;
|
|
|
|
const pkgConfigFor = pkgName => copyJsonObj(dummyNgPackages[`@angular/${pkgName}`].config);
|
|
|
|
const overwriteConfigFor = (pkgName, newProps) => Object.assign(pkgConfigFor(pkgName), newProps);
|
2019-02-04 07:31:43 -05:00
|
|
|
const stringifyConfig = config => JSON.stringify(config, null, 2);
|
2017-10-09 06:11:13 -04:00
|
|
|
|
|
|
|
const allArgs = fs.writeFileSync.calls.allArgs();
|
|
|
|
const firstFiveArgs = allArgs.slice(0, 5);
|
|
|
|
const lastFiveArgs = allArgs.slice(-5);
|
|
|
|
|
|
|
|
expect(firstFiveArgs).toEqual([
|
2019-02-04 07:31:43 -05:00
|
|
|
[pkgJsonFor('core'), stringifyConfig(overwriteConfigFor('core', {private: true}))],
|
|
|
|
[pkgJsonFor('common'), stringifyConfig(overwriteConfigFor('common', {private: true}))],
|
|
|
|
[pkgJsonFor('compiler'), stringifyConfig(overwriteConfigFor('compiler', {private: true}))],
|
|
|
|
[pkgJsonFor('compiler-cli'), stringifyConfig(overwriteConfigFor('compiler-cli', {
|
2017-10-09 06:11:13 -04:00
|
|
|
private: true,
|
|
|
|
dependencies: { '@angular/tsc-wrapped': `file:${toolsDir}/tsc-wrapped` }
|
|
|
|
}))],
|
2019-02-04 07:31:43 -05:00
|
|
|
[pkgJsonFor('tsc-wrapped'), stringifyConfig(overwriteConfigFor('tsc-wrapped', {
|
2017-10-09 06:11:13 -04:00
|
|
|
private: true,
|
|
|
|
devDependencies: { '@angular/common': `file:${packagesDir}/common` }
|
|
|
|
}))],
|
|
|
|
]);
|
|
|
|
|
|
|
|
expect(lastFiveArgs).toEqual(['core', 'common', 'compiler', 'compiler-cli', 'tsc-wrapped']
|
2019-02-04 07:31:43 -05:00
|
|
|
.map(pkgName => [pkgJsonFor(pkgName), stringifyConfig(pkgConfigFor(pkgName))]));
|
2017-10-09 06:11:13 -04:00
|
|
|
});
|
|
|
|
|
2017-10-06 05:48:18 -04:00
|
|
|
it('should load the package.json', () => {
|
2019-02-04 07:31:43 -05:00
|
|
|
expect(fs.readFileSync).toHaveBeenCalledWith(packageJsonPath, 'utf8');
|
2017-10-06 05:48:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should overwrite package.json with modified config', () => {
|
|
|
|
expect(fs.writeFileSync).toHaveBeenCalledWith(packageJsonPath, expectedModifiedPackageJson);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should restore original package.json', () => {
|
|
|
|
expect(fs.writeFileSync).toHaveBeenCalledWith(packageJsonPath, dummyPackageJson);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should overwrite package.json, then install deps, then restore original package.json', () => {
|
|
|
|
expect(log).toEqual([
|
|
|
|
`writeFile: ${expectedModifiedPackageJson}`,
|
2019-02-04 08:03:25 -05:00
|
|
|
`installDeps: --pure-lockfile --check-files`,
|
2017-10-06 05:48:18 -04:00
|
|
|
`writeFile: ${dummyPackageJson}`
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set the local marker file with the contents of the modified package.json', () => {
|
|
|
|
expect(installer._setLocalMarker).toHaveBeenCalledWith(expectedModifiedPackageJson);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('restoreNpmDependencies()', () => {
|
2017-10-09 06:18:51 -04:00
|
|
|
it('should run `yarn install` in the specified directory, with the correct options', () => {
|
2017-10-06 05:48:18 -04:00
|
|
|
spyOn(installer, '_installDeps');
|
|
|
|
installer.restoreNpmDependencies();
|
2017-10-19 05:19:45 -04:00
|
|
|
expect(installer._installDeps).toHaveBeenCalledWith('--frozen-lockfile', '--check-files');
|
2017-10-06 05:48:18 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-09 06:11:13 -04:00
|
|
|
describe('_getDistPackages()', () => {
|
2017-10-06 05:48:18 -04:00
|
|
|
it('should include top level Angular packages', () => {
|
|
|
|
const ngPackages = installer._getDistPackages();
|
2017-10-06 17:25:27 -04:00
|
|
|
const expectedValue = jasmine.objectContaining({
|
|
|
|
parentDir: jasmine.any(String),
|
2017-10-09 06:11:13 -04:00
|
|
|
packageJsonPath: jasmine.any(String),
|
2017-10-06 17:25:27 -04:00
|
|
|
config: jasmine.any(Object),
|
|
|
|
});
|
2017-10-06 05:48:18 -04:00
|
|
|
|
|
|
|
// For example...
|
2017-10-06 17:25:27 -04:00
|
|
|
expect(ngPackages['@angular/common']).toEqual(expectedValue);
|
|
|
|
expect(ngPackages['@angular/core']).toEqual(expectedValue);
|
|
|
|
expect(ngPackages['@angular/router']).toEqual(expectedValue);
|
|
|
|
expect(ngPackages['@angular/upgrade']).toEqual(expectedValue);
|
2017-10-06 05:48:18 -04:00
|
|
|
|
|
|
|
expect(ngPackages['@angular/upgrade/static']).not.toBeDefined();
|
2017-10-06 17:25:27 -04:00
|
|
|
});
|
2017-10-06 05:48:32 -04:00
|
|
|
|
2017-10-06 17:25:27 -04:00
|
|
|
it('should store each package\'s parent directory', () => {
|
|
|
|
const ngPackages = installer._getDistPackages();
|
2017-10-06 05:48:32 -04:00
|
|
|
|
2017-10-06 17:25:27 -04:00
|
|
|
// For example...
|
|
|
|
expect(ngPackages['@angular/core'].parentDir).toBe(packagesDir);
|
|
|
|
expect(ngPackages['@angular/router'].parentDir).toBeDefined(toolsDir);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not include packages that have been ignored', () => {
|
|
|
|
installer = new NgPackagesInstaller(rootDir, { ignorePackages: ['@angular/router'] });
|
|
|
|
const ngPackages = installer._getDistPackages();
|
|
|
|
|
|
|
|
expect(ngPackages['@angular/common']).toBeDefined();
|
|
|
|
expect(ngPackages['@angular/router']).toBeUndefined();
|
2017-10-06 05:48:18 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('_log()', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
spyOn(console, 'info');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should assign the debug property from the options', () => {
|
|
|
|
installer = new NgPackagesInstaller(rootDir, { debug: true });
|
|
|
|
expect(installer.debug).toBe(true);
|
|
|
|
installer = new NgPackagesInstaller(rootDir, { });
|
|
|
|
expect(installer.debug).toBe(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should log a message to the console if the `debug` property is true', () => {
|
|
|
|
installer._log('foo');
|
|
|
|
expect(console.info).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
installer.debug = true;
|
|
|
|
installer._log('bar');
|
|
|
|
expect(console.info).toHaveBeenCalledWith(' [NgPackagesInstaller]: bar');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-02-04 09:45:45 -05:00
|
|
|
describe('_parseLockfile()', () => {
|
|
|
|
let originalLockfileParseDescriptor;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
// Workaround for `lockfile.parse()` being non-writable.
|
|
|
|
let parse = lockfile.parse;
|
|
|
|
originalLockfileParseDescriptor = Object.getOwnPropertyDescriptor(lockfile, 'parse');
|
|
|
|
Object.defineProperty(lockfile, 'parse', {
|
|
|
|
get() { return parse; },
|
|
|
|
set(newParse) { parse = newParse; },
|
|
|
|
});
|
|
|
|
|
|
|
|
fs.readFileSync.and.returnValue('mock content');
|
|
|
|
spyOn(lockfile, 'parse').and.returnValue({type: 'success', object: {foo: {version: 'bar'}}});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => Object.defineProperty(lockfile, 'parse', originalLockfileParseDescriptor));
|
|
|
|
|
|
|
|
it('should parse the specified lockfile', () => {
|
|
|
|
installer._parseLockfile('/foo/bar/yarn.lock');
|
|
|
|
expect(fs.readFileSync).toHaveBeenCalledWith('/foo/bar/yarn.lock', 'utf8');
|
|
|
|
expect(lockfile.parse).toHaveBeenCalledWith('mock content');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw if parsing the lockfile fails', () => {
|
|
|
|
lockfile.parse.and.returnValue({type: 'not success'});
|
|
|
|
expect(() => installer._parseLockfile('/foo/bar/yarn.lock')).toThrowError(
|
|
|
|
'[NgPackagesInstaller]: Error parsing lockfile \'/foo/bar/yarn.lock\' (result type: not success).');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return the parsed lockfile content as an object', () => {
|
|
|
|
const parsed = installer._parseLockfile('/foo/bar/yarn.lock');
|
|
|
|
expect(parsed).toEqual({foo: {version: 'bar'}});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-09 06:11:13 -04:00
|
|
|
describe('_printWarning()', () => {
|
2017-10-06 05:48:18 -04:00
|
|
|
it('should mention the message passed in the warning', () => {
|
|
|
|
installer._printWarning();
|
|
|
|
expect(console.warn.calls.argsFor(0)[0]).toContain('is running against the local Angular build');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should mention the command to restore the Angular packages in any warning', () => {
|
|
|
|
// When run for the current working directory...
|
|
|
|
const dir1 = '.';
|
|
|
|
const restoreCmdRe1 = RegExp('\\bnode .*?ng-packages-installer/index restore ' + path.resolve(dir1));
|
|
|
|
installer = new NgPackagesInstaller(dir1);
|
|
|
|
installer._printWarning('');
|
|
|
|
expect(console.warn.calls.argsFor(0)[0]).toMatch(restoreCmdRe1);
|
|
|
|
|
|
|
|
// When run for a different directory...
|
|
|
|
const dir2 = rootDir;
|
|
|
|
const restoreCmdRe2 = RegExp(`\\bnode .*?ng-packages-installer/index restore .*?${path.resolve(dir1)}\\b`);
|
|
|
|
installer = new NgPackagesInstaller(dir2);
|
|
|
|
installer._printWarning('');
|
|
|
|
expect(console.warn.calls.argsFor(1)[0]).toMatch(restoreCmdRe2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-09 06:11:13 -04:00
|
|
|
describe('_installDeps()', () => {
|
2017-10-06 05:48:18 -04:00
|
|
|
it('should run yarn install with the given options', () => {
|
|
|
|
installer._installDeps('option-1', 'option-2');
|
|
|
|
expect(shelljs.exec).toHaveBeenCalledWith('yarn install option-1 option-2', { cwd: absoluteRootDir });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('local marker helpers', () => {
|
|
|
|
let installer;
|
|
|
|
beforeEach(() => {
|
|
|
|
installer = new NgPackagesInstaller(rootDir);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('_checkLocalMarker', () => {
|
|
|
|
it ('should return true if the local marker file exists', () => {
|
|
|
|
fs.existsSync.and.returnValue(true);
|
|
|
|
expect(installer._checkLocalMarker()).toEqual(true);
|
|
|
|
expect(fs.existsSync).toHaveBeenCalledWith(path.resolve(nodeModulesDir, '_local_.json'));
|
|
|
|
fs.existsSync.calls.reset();
|
|
|
|
|
|
|
|
fs.existsSync.and.returnValue(false);
|
|
|
|
expect(installer._checkLocalMarker()).toEqual(false);
|
|
|
|
expect(fs.existsSync).toHaveBeenCalledWith(path.resolve(nodeModulesDir, '_local_.json'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('_setLocalMarker', () => {
|
|
|
|
it('should create a local marker file', () => {
|
|
|
|
installer._setLocalMarker('test contents');
|
|
|
|
expect(fs.writeFileSync).toHaveBeenCalledWith(path.resolve(nodeModulesDir, '_local_.json'), 'test contents');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|