UNPKG

bit-bin

Version:

<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b

56 lines (48 loc) 2.54 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); function _chai() { const data = require("chai"); _chai = function () { return data; }; return data; } function _replacePackageName() { const data = _interopRequireDefault(require("./replace-package-name")); _replacePackageName = function () { return data; }; return data; } describe('replacePackageName', () => { it('should replace package surrounded with single quotes', () => { const str = "require('@bit/old-scope.is-string');"; const result = (0, _replacePackageName().default)(str, '@bit/old-scope.is-string', '@bit/new-scope.is-string'); (0, _chai().expect)(result).to.equal("require('@bit/new-scope.is-string');"); }); it('should replace package surrounded with double quotes', () => { const str = 'require("@bit/old-scope.is-string");'; const result = (0, _replacePackageName().default)(str, '@bit/old-scope.is-string', '@bit/new-scope.is-string'); (0, _chai().expect)(result).to.equal('require("@bit/new-scope.is-string");'); }); it('should replace package path consist of an internal path', () => { const str = "require('@bit/old-scope.is-string/some-internal-path');"; const result = (0, _replacePackageName().default)(str, '@bit/old-scope.is-string', '@bit/new-scope.is-string'); (0, _chai().expect)(result).to.equal("require('@bit/new-scope.is-string/some-internal-path');"); }); it('should not replace package when it matches only part of the package-name', () => { const str = "require('@bit/old-scope.is-string-util');"; const result = (0, _replacePackageName().default)(str, '@bit/old-scope.is-string', '@bit/new-scope.is-string'); (0, _chai().expect)(result).to.equal("require('@bit/old-scope.is-string-util');"); }); it('should replace package that its require statement has tilda (~)', () => { const str = "@import '~@bit/old-scope.ui.style/my-style.scss';"; const result = (0, _replacePackageName().default)(str, '@bit/old-scope.ui.style', '@bit/new-scope.ui.style'); (0, _chai().expect)(result).to.equal("@import '~@bit/new-scope.ui.style/my-style.scss';"); }); it('should ignore package that its require statement has other prefixes', () => { const str = "@import '$@bit/old-scope.ui.style';"; const result = (0, _replacePackageName().default)(str, '@bit/old-scope.ui.style', '@bit/new-scope.ui.style'); (0, _chai().expect)(result).to.equal("@import '$@bit/old-scope.ui.style';"); }); });