|
| 1 | +/** |
| 2 | + * @file Unit Tests - PACKAGE_PATH_REGEX |
| 3 | + * @module mlly/internal/tests/unit/PACKAGE_PATH_REGEX |
| 4 | + */ |
| 5 | + |
| 6 | +import TEST_SUBJECT from '../regex-package-path' |
| 7 | + |
| 8 | +describe('unit:internal/PACKAGE_PATH_REGEX', () => { |
| 9 | + it('should match if specifier is valid package path', () => { |
| 10 | + // Arrange |
| 11 | + const cases: [string, Record<string, string | undefined>][] = [ |
| 12 | + [ |
| 13 | + '@flex-development/mlly', |
| 14 | + { |
| 15 | + pkg: '@flex-development/mlly', |
| 16 | + scope: '@flex-development', |
| 17 | + subpath: undefined, |
| 18 | + version: undefined, |
| 19 | + version_prefix: undefined |
| 20 | + } |
| 21 | + ], |
| 22 | + [ |
| 23 | + '@flex-development/mlly@1.0.0-alpha.7', |
| 24 | + { |
| 25 | + pkg: '@flex-development/mlly', |
| 26 | + scope: '@flex-development', |
| 27 | + subpath: undefined, |
| 28 | + version: '1.0.0-alpha.7', |
| 29 | + version_prefix: undefined |
| 30 | + } |
| 31 | + ], |
| 32 | + [ |
| 33 | + '@flex-development/mlly@v1.0.0-alpha.7', |
| 34 | + { |
| 35 | + pkg: '@flex-development/mlly', |
| 36 | + scope: '@flex-development', |
| 37 | + subpath: undefined, |
| 38 | + version: '1.0.0-alpha.7', |
| 39 | + version_prefix: 'v' |
| 40 | + } |
| 41 | + ], |
| 42 | + [ |
| 43 | + '@flex-development/mlly@v1.0.0-alpha.7/dist/index.mjs', |
| 44 | + { |
| 45 | + pkg: '@flex-development/mlly', |
| 46 | + scope: '@flex-development', |
| 47 | + subpath: '/dist/index.mjs', |
| 48 | + version: '1.0.0-alpha.7', |
| 49 | + version_prefix: 'v' |
| 50 | + } |
| 51 | + ], |
| 52 | + [ |
| 53 | + 'mlly', |
| 54 | + { |
| 55 | + pkg: 'mlly', |
| 56 | + scope: undefined, |
| 57 | + subpath: undefined, |
| 58 | + version: undefined, |
| 59 | + version_prefix: undefined |
| 60 | + } |
| 61 | + ] |
| 62 | + ] |
| 63 | + |
| 64 | + // Act + Expect |
| 65 | + cases.forEach(([specifier, groups]) => { |
| 66 | + const match = TEST_SUBJECT.exec(specifier) |
| 67 | + |
| 68 | + expect(match).to.not.be.null |
| 69 | + expect(match?.groups).to.deep.equal(groups) |
| 70 | + }) |
| 71 | + }) |
| 72 | + |
| 73 | + it('should not match if specifier is not valid package path', () => { |
| 74 | + // Arrange |
| 75 | + const cases: string[] = [ |
| 76 | + '#src', |
| 77 | + './package.json', |
| 78 | + '@FLEX-DEVELOPMENT/MLLY', |
| 79 | + 'MLLY', |
| 80 | + 'node:fs', |
| 81 | + 'node_modules/@flex-development/mlly', |
| 82 | + import.meta.url |
| 83 | + ] |
| 84 | + |
| 85 | + // Act + Expect |
| 86 | + cases.forEach(specifier => expect(TEST_SUBJECT.test(specifier)).to.be.false) |
| 87 | + }) |
| 88 | +}) |
0 commit comments