2019-05-25 16:34:40 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2019-05-25 16:34:40 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
import {absoluteFrom} from '../../../src/ngtsc/file_system';
|
|
|
|
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
|
|
|
import {isWithinPackage} from '../../src/analysis/util';
|
|
|
|
|
|
|
|
runInEachFileSystem(() => {
|
|
|
|
describe('isWithinPackage', () => {
|
2020-04-10 08:13:20 -04:00
|
|
|
let _: typeof absoluteFrom;
|
|
|
|
|
|
|
|
beforeEach(() => _ = absoluteFrom);
|
|
|
|
|
2019-05-25 16:34:40 -04:00
|
|
|
it('should return true if the source-file is contained in the package', () => {
|
2020-04-10 08:13:20 -04:00
|
|
|
const packagePath = _('/node_modules/test');
|
2020-06-23 16:12:32 -04:00
|
|
|
const file = _('/node_modules/test/src/index.js');
|
2019-05-25 16:34:40 -04:00
|
|
|
expect(isWithinPackage(packagePath, file)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false if the source-file is not contained in the package', () => {
|
2020-04-10 08:13:20 -04:00
|
|
|
const packagePath = _('/node_modules/test');
|
2020-06-23 16:12:32 -04:00
|
|
|
const file = _('/node_modules/other/src/index.js');
|
2019-05-25 16:34:40 -04:00
|
|
|
expect(isWithinPackage(packagePath, file)).toBe(false);
|
|
|
|
});
|
2020-04-10 08:13:20 -04:00
|
|
|
|
|
|
|
it('should return false if the source-file is inside the package\'s `node_modules/`', () => {
|
|
|
|
const packagePath = _('/node_modules/test');
|
|
|
|
|
|
|
|
// An external file inside the package's `node_modules/`.
|
2020-06-23 16:12:32 -04:00
|
|
|
const file1 = _('/node_modules/test/node_modules/other/src/index.js');
|
2020-04-10 08:13:20 -04:00
|
|
|
expect(isWithinPackage(packagePath, file1)).toBe(false);
|
|
|
|
|
|
|
|
// An internal file starting with `node_modules`.
|
2020-06-23 16:12:32 -04:00
|
|
|
const file2 = _('/node_modules/test/node_modules_optimizer.js');
|
2020-04-10 08:13:20 -04:00
|
|
|
expect(isWithinPackage(packagePath, file2)).toBe(true);
|
|
|
|
});
|
2019-05-25 16:34:40 -04:00
|
|
|
});
|
|
|
|
});
|