@teambit/legacy-bit-id 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/bit-id.d.ts +7 -5
  2. package/dist/bit-id.js +344 -291
  3. package/dist/bit-id.js.map +1 -1
  4. package/dist/bit-id.spec.js +349 -224
  5. package/dist/bit-id.spec.js.map +1 -1
  6. package/dist/exceptions/index.js +71 -15
  7. package/dist/exceptions/index.js.map +1 -1
  8. package/dist/exceptions/invalid-bit-id.js +21 -6
  9. package/dist/exceptions/invalid-bit-id.js.map +1 -1
  10. package/dist/exceptions/invalid-id-chunk.js +21 -6
  11. package/dist/exceptions/invalid-id-chunk.js.map +1 -1
  12. package/dist/exceptions/invalid-name.js +21 -6
  13. package/dist/exceptions/invalid-name.js.map +1 -1
  14. package/dist/exceptions/invalid-scope-name-from-remote.js +17 -6
  15. package/dist/exceptions/invalid-scope-name-from-remote.js.map +1 -1
  16. package/dist/exceptions/invalid-scope-name.js +23 -7
  17. package/dist/exceptions/invalid-scope-name.js.map +1 -1
  18. package/dist/index.js +90 -39
  19. package/dist/index.js.map +1 -1
  20. package/dist/utils/is-valid-id-chunk.js +10 -8
  21. package/dist/utils/is-valid-id-chunk.js.map +1 -1
  22. package/dist/utils/is-valid-id-chunk.spec.js +32 -21
  23. package/dist/utils/is-valid-id-chunk.spec.js.map +1 -1
  24. package/dist/utils/is-valid-scope-name.js +8 -5
  25. package/dist/utils/is-valid-scope-name.js.map +1 -1
  26. package/package.json +17 -8
  27. package/tsconfig.json +10 -2
  28. package/.bit-capsule-ready +0 -0
  29. package/bit-id.spec.ts +0 -225
  30. package/bit-id.ts +0 -313
  31. package/dist/tsconfig.json +0 -32
  32. package/index.ts +0 -16
  33. package/package-tar/teambit-legacy-bit-id-1.0.1.tgz +0 -0
  34. /package/dist/{preview-1691932590750.js → preview-1697512701410.js} +0 -0
@@ -1,25 +1,36 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const chai_1 = require("chai");
7
- const is_valid_id_chunk_1 = __importDefault(require("./is-valid-id-chunk"));
2
+
3
+ function _chai() {
4
+ const data = require("chai");
5
+ _chai = function () {
6
+ return data;
7
+ };
8
+ return data;
9
+ }
10
+ function _isValidIdChunk() {
11
+ const data = _interopRequireDefault(require("./is-valid-id-chunk"));
12
+ _isValidIdChunk = function () {
13
+ return data;
14
+ };
15
+ return data;
16
+ }
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
18
  describe('isValidIdChunk', () => {
9
- it('should disallow non string inputs', () => {
10
- (0, chai_1.expect)((0, is_valid_id_chunk_1.default)(123)).to.be.false;
11
- (0, chai_1.expect)((0, is_valid_id_chunk_1.default)(123, true)).to.be.false;
12
- });
13
- it('should allow a string that consist of small letters', () => {
14
- (0, chai_1.expect)((0, is_valid_id_chunk_1.default)('abc')).to.be.true;
15
- (0, chai_1.expect)((0, is_valid_id_chunk_1.default)('abc', true)).to.be.true;
16
- });
17
- it('should disallow a string that has a capital letter', () => {
18
- (0, chai_1.expect)((0, is_valid_id_chunk_1.default)('Abc')).to.be.false;
19
- (0, chai_1.expect)((0, is_valid_id_chunk_1.default)('Abc', true)).to.be.false;
20
- });
21
- it('should disallow a string that has two slashes one after another', () => {
22
- (0, chai_1.expect)((0, is_valid_id_chunk_1.default)('abc//', true)).to.be.false;
23
- });
19
+ it('should disallow non string inputs', () => {
20
+ (0, _chai().expect)((0, _isValidIdChunk().default)(123)).to.be.false;
21
+ (0, _chai().expect)((0, _isValidIdChunk().default)(123, true)).to.be.false;
22
+ });
23
+ it('should allow a string that consist of small letters', () => {
24
+ (0, _chai().expect)((0, _isValidIdChunk().default)('abc')).to.be.true;
25
+ (0, _chai().expect)((0, _isValidIdChunk().default)('abc', true)).to.be.true;
26
+ });
27
+ it('should disallow a string that has a capital letter', () => {
28
+ (0, _chai().expect)((0, _isValidIdChunk().default)('Abc')).to.be.false;
29
+ (0, _chai().expect)((0, _isValidIdChunk().default)('Abc', true)).to.be.false;
30
+ });
31
+ it('should disallow a string that has two slashes one after another', () => {
32
+ (0, _chai().expect)((0, _isValidIdChunk().default)('abc//', true)).to.be.false;
33
+ });
24
34
  });
35
+
25
36
  //# sourceMappingURL=is-valid-id-chunk.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-valid-id-chunk.spec.js","sourceRoot":"","sources":["../../utils/is-valid-id-chunk.spec.ts"],"names":[],"mappings":";;;;;AAAA,+BAA8B;AAE9B,4EAAiD;AAEjD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QAC3C,IAAA,aAAM,EAAC,IAAA,2BAAc,EAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;QACxC,IAAA,aAAM,EAAC,IAAA,2BAAc,EAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;IAChD,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAC7D,IAAA,aAAM,EAAC,IAAA,2BAAc,EAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;QACzC,IAAA,aAAM,EAAC,IAAA,2BAAc,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IACjD,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;QAC5D,IAAA,aAAM,EAAC,IAAA,2BAAc,EAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;QAC1C,IAAA,aAAM,EAAC,IAAA,2BAAc,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;IAClD,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;QACzE,IAAA,aAAM,EAAC,IAAA,2BAAc,EAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
1
+ {"version":3,"names":["_chai","data","require","_isValidIdChunk","_interopRequireDefault","obj","__esModule","default","describe","it","expect","isValidIdChunk","to","be","false","true"],"sources":["is-valid-id-chunk.spec.ts"],"sourcesContent":["import { expect } from 'chai';\n\nimport isValidIdChunk from './is-valid-id-chunk';\n\ndescribe('isValidIdChunk', () => {\n it('should disallow non string inputs', () => {\n expect(isValidIdChunk(123)).to.be.false;\n expect(isValidIdChunk(123, true)).to.be.false;\n });\n it('should allow a string that consist of small letters', () => {\n expect(isValidIdChunk('abc')).to.be.true;\n expect(isValidIdChunk('abc', true)).to.be.true;\n });\n it('should disallow a string that has a capital letter', () => {\n expect(isValidIdChunk('Abc')).to.be.false;\n expect(isValidIdChunk('Abc', true)).to.be.false;\n });\n it('should disallow a string that has two slashes one after another', () => {\n expect(isValidIdChunk('abc//', true)).to.be.false;\n });\n});\n"],"mappings":";;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAE,gBAAA;EAAA,MAAAF,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAC,eAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAiD,SAAAG,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEjDG,QAAQ,CAAC,gBAAgB,EAAE,MAAM;EAC/BC,EAAE,CAAC,mCAAmC,EAAE,MAAM;IAC5C,IAAAC,cAAM,EAAC,IAAAC,yBAAc,EAAC,GAAG,CAAC,CAAC,CAACC,EAAE,CAACC,EAAE,CAACC,KAAK;IACvC,IAAAJ,cAAM,EAAC,IAAAC,yBAAc,EAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAACC,EAAE,CAACC,EAAE,CAACC,KAAK;EAC/C,CAAC,CAAC;EACFL,EAAE,CAAC,qDAAqD,EAAE,MAAM;IAC9D,IAAAC,cAAM,EAAC,IAAAC,yBAAc,EAAC,KAAK,CAAC,CAAC,CAACC,EAAE,CAACC,EAAE,CAACE,IAAI;IACxC,IAAAL,cAAM,EAAC,IAAAC,yBAAc,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAACC,EAAE,CAACC,EAAE,CAACE,IAAI;EAChD,CAAC,CAAC;EACFN,EAAE,CAAC,oDAAoD,EAAE,MAAM;IAC7D,IAAAC,cAAM,EAAC,IAAAC,yBAAc,EAAC,KAAK,CAAC,CAAC,CAACC,EAAE,CAACC,EAAE,CAACC,KAAK;IACzC,IAAAJ,cAAM,EAAC,IAAAC,yBAAc,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAACC,EAAE,CAACC,EAAE,CAACC,KAAK;EACjD,CAAC,CAAC;EACFL,EAAE,CAAC,iEAAiE,EAAE,MAAM;IAC1E,IAAAC,cAAM,EAAC,IAAAC,yBAAc,EAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAACC,EAAE,CAACC,EAAE,CAACC,KAAK;EACnD,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -1,11 +1,14 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isValidScopeName;
3
7
  // the '.' can be in the middle, not at the beginning and not at the end and only once.
4
8
  const validationRegExp = /^[$\-_!a-z0-9]+[.]?[$\-_!a-z0-9]+$/;
5
9
  function isValidScopeName(val) {
6
- if (typeof val !== 'string')
7
- return false;
8
- return validationRegExp.test(val);
10
+ if (typeof val !== 'string') return false;
11
+ return validationRegExp.test(val);
9
12
  }
10
- exports.default = isValidScopeName;
13
+
11
14
  //# sourceMappingURL=is-valid-scope-name.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-valid-scope-name.js","sourceRoot":"","sources":["../../utils/is-valid-scope-name.ts"],"names":[],"mappings":";;AAAA,uFAAuF;AACvF,MAAM,gBAAgB,GAAG,oCAAoC,CAAC;AAE9D,SAAwB,gBAAgB,CAAC,GAAQ;IAC/C,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC1C,OAAO,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACpC,CAAC;AAHD,mCAGC"}
1
+ {"version":3,"names":["validationRegExp","isValidScopeName","val","test"],"sources":["is-valid-scope-name.ts"],"sourcesContent":["// the '.' can be in the middle, not at the beginning and not at the end and only once.\nconst validationRegExp = /^[$\\-_!a-z0-9]+[.]?[$\\-_!a-z0-9]+$/;\n\nexport default function isValidScopeName(val: any): boolean {\n if (typeof val !== 'string') return false;\n return validationRegExp.test(val);\n}\n"],"mappings":";;;;;;AAAA;AACA,MAAMA,gBAAgB,GAAG,oCAAoC;AAE9C,SAASC,gBAAgBA,CAACC,GAAQ,EAAW;EAC1D,IAAI,OAAOA,GAAG,KAAK,QAAQ,EAAE,OAAO,KAAK;EACzC,OAAOF,gBAAgB,CAACG,IAAI,CAACD,GAAG,CAAC;AACnC"}
package/package.json CHANGED
@@ -1,30 +1,39 @@
1
1
  {
2
2
  "name": "@teambit/legacy-bit-id",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "homepage": "https://bit.cloud/teambit/component/legacy-bit-id",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.component",
8
8
  "name": "legacy-bit-id",
9
- "version": "1.0.1"
9
+ "version": "1.0.3"
10
10
  },
11
11
  "dependencies": {
12
12
  "decamelize": "1.2.0",
13
13
  "lodash": "4.17.21",
14
- "semver": "7.3.4",
15
- "@teambit/bit-error": "0.0.402",
16
- "@teambit/component-version": "1.0.0"
14
+ "semver": "7.5.2",
15
+ "core-js": "^3.0.0",
16
+ "@babel/runtime": "7.20.0",
17
+ "@teambit/component-version": "1.0.3",
18
+ "@teambit/bit-error": "0.0.404"
17
19
  },
18
20
  "devDependencies": {
19
21
  "@types/chai": "4.2.15",
20
22
  "chai": "4.3.0",
21
23
  "@types/lodash": "4.14.165",
22
24
  "@types/semver": "7.3.4",
23
- "@types/jest": "26.0.20",
25
+ "@types/mocha": "9.1.0",
24
26
  "@types/node": "12.20.4",
25
- "@babel/runtime": "7.20.0"
27
+ "@types/react": "^17.0.8",
28
+ "@types/react-dom": "^17.0.5",
29
+ "@types/jest": "^26.0.0",
30
+ "@types/testing-library__jest-dom": "5.9.5"
31
+ },
32
+ "peerDependencies": {
33
+ "@teambit/legacy": "1.0.578",
34
+ "react": "^16.8.0 || ^17.0.0",
35
+ "react-dom": "^16.8.0 || ^17.0.0"
26
36
  },
27
- "peerDependencies": {},
28
37
  "license": "Apache-2.0",
29
38
  "private": false,
30
39
  "engines": {
package/tsconfig.json CHANGED
@@ -4,7 +4,8 @@
4
4
  "es2019",
5
5
  "DOM",
6
6
  "ES6",
7
- "DOM.Iterable"
7
+ "DOM.Iterable",
8
+ "ScriptHost"
8
9
  ],
9
10
  "target": "es2015",
10
11
  "module": "CommonJS",
@@ -19,7 +20,14 @@
19
20
  "moduleResolution": "node",
20
21
  "esModuleInterop": true,
21
22
  "rootDir": ".",
22
- "resolveJsonModule": true
23
+ "resolveJsonModule": true,
24
+ "emitDeclarationOnly": true,
25
+ "emitDecoratorMetadata": true,
26
+ "allowSyntheticDefaultImports": true,
27
+ "strictPropertyInitialization": false,
28
+ "strict": true,
29
+ "noImplicitAny": false,
30
+ "preserveConstEnums": true
23
31
  },
24
32
  "exclude": [
25
33
  "dist",
File without changes
package/bit-id.spec.ts DELETED
@@ -1,225 +0,0 @@
1
- import { expect } from 'chai';
2
-
3
- import BitId from './bit-id';
4
- import { InvalidName, InvalidScopeName } from './exceptions';
5
-
6
- describe('Bit-id', () => {
7
- // TODO: those tests are now verified by TS compiler, I think we can remove them
8
- it('should be frozen', () => {
9
- const bitId = new BitId({ name: 'my-name' });
10
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
11
- expect(() => (bitId.scope = 'name')).to.throw();
12
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
13
- expect(() => (bitId.name = 'name')).to.throw();
14
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
15
- expect(() => (bitId.version = 'name')).to.throw();
16
- });
17
- describe('constructor', () => {
18
- it('should not throw for an invalid scope as it hurts performance (it is done on .parse() instead)', () => {
19
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
20
- const invalidScope = () => new BitId({ scope: 123, name: 'my-name' });
21
- expect(invalidScope).to.not.throw(InvalidScopeName);
22
- });
23
- it('should not throw for an invalid name as it hurts performance (it is done on .parse() instead)', () => {
24
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
25
- const invalidName = () => new BitId({ name: ['a', 'b'] });
26
- expect(invalidName).to.not.throw(InvalidName);
27
- });
28
- it('should accept an empty scope', () => {
29
- const invalidScope = () => new BitId({ scope: null, name: 'my-name' });
30
- expect(invalidScope).to.not.throw();
31
- });
32
- it('should not accept an empty name', () => {
33
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
34
- expect(() => new BitId({ scope: 'my-scope', name: null })).to.throw(InvalidName);
35
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
36
- expect(() => new BitId({ scope: 'my-scope', name: undefined })).to.throw(InvalidName);
37
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
38
- expect(() => new BitId({ scope: 'my-scope' })).to.throw(InvalidName);
39
- });
40
- });
41
- describe('changeScope', () => {
42
- it('should return a new BitId with different scope', () => {
43
- const bitId = new BitId({ name: 'my-name' });
44
- expect(bitId.changeScope('my-scope')).to.have.property('scope').that.equal('my-scope');
45
- });
46
- it('should accept an empty parameter to remove the scope', () => {
47
- const bitId = new BitId({ scope: 'my-scope', name: 'my-name' });
48
- expect(bitId.changeScope()).to.have.property('scope').that.is.null;
49
- });
50
- });
51
- describe('changeVersion', () => {
52
- it('should return a new BitId with different version', () => {
53
- const bitId = new BitId({ name: 'my-name' });
54
- expect(bitId.changeVersion('0.0.1')).to.have.property('version').that.equal('0.0.1');
55
- });
56
- it('should accept an empty parameter to remove the version', () => {
57
- const bitId = new BitId({ scope: 'my-scope', name: 'my-name', version: '0.0.1' });
58
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
59
- expect(bitId.changeVersion()).to.have.property('version').that.is.undefined;
60
- });
61
- });
62
- describe('hasScope', () => {
63
- it('should return false when there is no scope', () => {
64
- const bitId = new BitId({ name: 'my-name' });
65
- expect(bitId.hasScope()).to.be.false;
66
- });
67
- it('should return true when there is scope', () => {
68
- const bitId = new BitId({ scope: 'my-scope', name: 'my-name' });
69
- expect(bitId.hasScope()).to.be.true;
70
- });
71
- });
72
- describe('getValidBitId', () => {
73
- it('should convert CSSComp to css-comp', () => {
74
- const bitName = 'CSSComp';
75
- expect(BitId.getValidBitId('global', bitName).toString()).to.equal('global/css-comp');
76
- // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
77
- });
78
- it('should convert EN-US to en-us', () => {
79
- const bitName = 'EN-US';
80
- expect(BitId.getValidBitId('global', bitName).toString()).to.equal('global/en-us');
81
- });
82
- it('should convert AppBar to app-bar', () => {
83
- const bitName = 'AppBar';
84
- expect(BitId.getValidBitId('global', bitName).toString()).to.equal('global/app-bar');
85
- });
86
- it('should convert app-bar to app-bar', () => {
87
- const bitName = 'app-bar';
88
- expect(BitId.getValidBitId('global', bitName).toString()).to.equal('global/app-bar');
89
- });
90
- it('should convert app-Bar to app-bar', () => {
91
- const bitName = 'app-Bar';
92
- expect(BitId.getValidBitId('global', bitName).toString()).to.equal('global/app-bar');
93
- });
94
- it('should convert App-Bar to app-bar', () => {
95
- const bitName = 'App-Bar';
96
- expect(BitId.getValidBitId('global', bitName).toString()).to.equal('global/app-bar');
97
- });
98
- it('should convert CSScomp to cs-scomp ', () => {
99
- const bitName = 'CSScomp';
100
- expect(BitId.getValidBitId('global', bitName).toString()).to.equal('global/cs-scomp');
101
- });
102
- it('should convert CSS@comp/CSScomp to css@comp/cs-scomp ', () => {
103
- const bitName = 'CSScomp';
104
- const global = 'CSS@comp';
105
- expect(BitId.getValidBitId(global, bitName).toString()).to.equal('css@comp/cs-scomp');
106
- });
107
- it('should convert CSS!!####@comp/app-Bar to app-Bar', () => {
108
- const bitName = 'app-Bar';
109
- const global = 'CSS!!####@comp';
110
- expect(BitId.getValidBitId(global, bitName).toString()).to.equal('css!!####@comp/app-bar');
111
- });
112
- it('should convert app bar to app-bar', () => {
113
- const bitName = 'app bar';
114
- expect(BitId.getValidBitId(undefined, bitName).toString()).to.equal('app-bar');
115
- });
116
- });
117
- describe('toString', () => {
118
- it('should not contain the version as latest', () => {
119
- const bitId = BitId.parse('bit.envs/mocha/react@latest');
120
- expect(bitId.toString()).to.equal('bit.envs/mocha/react');
121
- });
122
- });
123
- describe('parse', () => {
124
- it('should parse id with scope correctly', () => {
125
- const bitId = BitId.parse('scope/my/long/comp/id', true);
126
- expect(bitId.scope).to.equal('scope');
127
- expect(bitId.name).to.equal('my/long/comp/id');
128
- expect(bitId.box).to.be.undefined;
129
- expect(bitId.version).to.equal('latest');
130
- });
131
- it('should parse id without scope correctly', () => {
132
- const bitId = BitId.parse('scope/my/long/comp/id', false);
133
- expect(bitId.scope).to.be.null;
134
- expect(bitId.name).to.equal('scope/my/long/comp/id');
135
- expect(bitId.box).to.be.undefined;
136
- expect(bitId.version).to.equal('latest');
137
- });
138
- it('should throw for an invalid id', () => {
139
- const bitId = () => BitId.parse('scope/my/long/co*mp/id', false);
140
- expect(bitId).to.throw();
141
- });
142
- });
143
- describe('hasSameScope', () => {
144
- it('should return true when it has the same scope', () => {
145
- const bitId = new BitId({ scope: 'my-scope', name: 'my-name' });
146
- const anotherId = new BitId({ scope: 'my-scope', name: 'another-name' });
147
- expect(bitId.hasSameScope(anotherId)).to.be.true;
148
- });
149
- it('should return false when it does not the same scope', () => {
150
- const bitId = new BitId({ scope: 'my-scope', name: 'my-name' });
151
- const anotherId = new BitId({ scope: 'another-scope', name: 'my-name' });
152
- expect(bitId.hasSameScope(anotherId)).to.be.false;
153
- });
154
- it('should return true when both scopes are null', () => {
155
- const bitId = new BitId({ scope: null, name: 'my-name' });
156
- const anotherId = new BitId({ scope: null, name: 'my-name' });
157
- expect(bitId.hasSameScope(anotherId)).to.be.true;
158
- });
159
- it('should return false when one of the scope is null', () => {
160
- const bitId = new BitId({ scope: null, name: 'my-name' });
161
- const anotherId = new BitId({ scope: 'another-scope', name: 'my-name' });
162
- expect(bitId.hasSameScope(anotherId)).to.be.false;
163
- });
164
- });
165
- describe('isEqual', () => {
166
- it('should return true for an exact match', () => {
167
- const bitId = new BitId({ scope: 'my-scope', name: 'my-name', version: '0.0.1' });
168
- const anotherId = new BitId({ scope: 'my-scope', name: 'my-name', version: '0.0.1' });
169
- expect(bitId.isEqual(anotherId)).to.be.true;
170
- });
171
- it('should return false for a version mismatch', () => {
172
- const bitId = new BitId({ scope: 'my-scope', name: 'my-name', version: '0.0.1' });
173
- const anotherId = new BitId({ scope: 'my-scope', name: 'my-name', version: '0.0.2' });
174
- expect(bitId.isEqual(anotherId)).to.be.false;
175
- });
176
- it('should return false for a name mismatch', () => {
177
- const bitId = new BitId({ scope: 'my-scope', name: 'my-name', version: '0.0.1' });
178
- const anotherId = new BitId({ scope: 'my-scope', name: 'another-name', version: '0.0.1' });
179
- expect(bitId.isEqual(anotherId)).to.be.false;
180
- });
181
- it('should return false for a scope mismatch', () => {
182
- const bitId = new BitId({ scope: 'my-scope', name: 'my-name', version: '0.0.1' });
183
- const anotherId = new BitId({ scope: 'another-scope', name: 'my-name', version: '0.0.1' });
184
- expect(bitId.isEqual(anotherId)).to.be.false;
185
- });
186
- });
187
- describe('serialize', () => {
188
- it('should delete the scope property if not set', () => {
189
- const bitId = new BitId({ name: 'my-name', version: '0.0.1' });
190
- expect(bitId.serialize()).to.not.have.property('scope');
191
- });
192
- it('should delete the version property if not set', () => {
193
- const bitId = new BitId({ name: 'my-name' });
194
- expect(bitId.serialize()).to.not.have.property('version');
195
- });
196
- it('should include all properties if they are all set', () => {
197
- const bitId = new BitId({ scope: 'my-scope', name: 'my-name', version: '0.0.1' });
198
- expect(bitId.serialize()).to.have.property('name');
199
- expect(bitId.serialize()).to.have.property('scope');
200
- expect(bitId.serialize()).to.have.property('version');
201
- });
202
- it('should not be an instance of BitId', () => {
203
- const bitId = new BitId({ scope: 'my-scope', name: 'my-name', version: '0.0.1' });
204
- expect(bitId.serialize()).to.not.be.an.instanceof(BitId);
205
- });
206
- });
207
- describe('parseBackwardCompatible', () => {
208
- it('should parse the new format, which is an object', () => {
209
- const bitIdObj = new BitId({ scope: 'my-scope', name: 'my-name', version: '0.0.1' }).serialize();
210
- const bitId = BitId.parseBackwardCompatible(bitIdObj);
211
- expect(bitId).to.be.an.instanceof(BitId);
212
- expect(bitId.name).to.equal('my-name');
213
- expect(bitId.scope).to.equal('my-scope');
214
- expect(bitId.version).to.equal('0.0.1');
215
- });
216
- it('should parse the old format, which is a string', () => {
217
- const bitIdStr = 'my-scope/my-box/my-name@0.0.1';
218
- const bitId = BitId.parseBackwardCompatible(bitIdStr);
219
- expect(bitId).to.be.an.instanceof(BitId);
220
- expect(bitId.name).to.equal('my-box/my-name');
221
- expect(bitId.scope).to.equal('my-scope');
222
- expect(bitId.version).to.equal('0.0.1');
223
- });
224
- });
225
- });