|
1 | | -import { getChangelogEntry, BumpLevels, sortTheThings } from "./utils"; |
| 1 | +import { getChangelogEntry, BumpLevels, sortTheThings, extractAuthTokenLine } from "./utils"; |
2 | 2 |
|
3 | 3 | let changelog = `# @keystone-alpha/email |
4 | 4 |
|
@@ -99,3 +99,62 @@ test("it sorts the things right", () => { |
99 | 99 | ]; |
100 | 100 | expect(things.sort(sortTheThings)).toMatchSnapshot(); |
101 | 101 | }); |
| 102 | + |
| 103 | +/** |
| 104 | + * Test the extractAuthTokenLine function for various registries. |
| 105 | + */ |
| 106 | +describe("extractAuthTokenLine", () => { |
| 107 | + it("should correctly find the auth token line for multiple registries", () => { |
| 108 | + const testCases = [ |
| 109 | + { |
| 110 | + name: "Custom private registry", |
| 111 | + npmrc: ` |
| 112 | + registry=https://custom.private-registry.com/api/npm/npm/ |
| 113 | + //custom.private-registry.com/api/npm/npm/:_authToken=abcd1234 |
| 114 | + always-auth=true |
| 115 | + `, |
| 116 | + expected: "//custom.private-registry.com/api/npm/npm/:_authToken=abcd1234", |
| 117 | + }, |
| 118 | + { |
| 119 | + name: "NPM default registry", |
| 120 | + npmrc: ` |
| 121 | + registry=https://registry.npmjs.org/ |
| 122 | + //registry.npmjs.org/:_authToken=efgh5678 |
| 123 | + `, |
| 124 | + expected: "//registry.npmjs.org/:_authToken=efgh5678", |
| 125 | + }, |
| 126 | + { |
| 127 | + name: "AWS CodeArtifact registry", |
| 128 | + npmrc: ` |
| 129 | + registry=https://mydomain-111122223333.d.codeartifact.us-east-1.amazonaws.com/npm/repository-name/ |
| 130 | + //mydomain-111122223333.d.codeartifact.us-east-1.amazonaws.com/npm/repository-name/:_authToken=ijkl9012 |
| 131 | + `, |
| 132 | + expected: |
| 133 | + "//mydomain-111122223333.d.codeartifact.us-east-1.amazonaws.com/npm/repository-name/:_authToken=ijkl9012", |
| 134 | + }, |
| 135 | + { |
| 136 | + name: "Azure DevOps registry", |
| 137 | + npmrc: ` |
| 138 | + registry=https://pkgs.dev.azure.com/myorg/_packaging/myfeed/npm/registry/ |
| 139 | + //pkgs.dev.azure.com/myorg/_packaging/myfeed/npm/registry/:_authToken=mnop3456 |
| 140 | + `, |
| 141 | + expected: |
| 142 | + "//pkgs.dev.azure.com/myorg/_packaging/myfeed/npm/registry/:_authToken=mnop3456", |
| 143 | + }, |
| 144 | + ]; |
| 145 | + |
| 146 | + testCases.forEach(({ name, npmrc, expected }) => { |
| 147 | + const result = extractAuthTokenLine(npmrc); |
| 148 | + expect(result).toBe(expected); |
| 149 | + }); |
| 150 | + }); |
| 151 | + |
| 152 | + it("should return undefined if no auth token line is present", () => { |
| 153 | + const npmrcContent = ` |
| 154 | + registry=https://custom.private-registry.com/api/npm/npm/ |
| 155 | + always-auth=true |
| 156 | + `; |
| 157 | + const result = extractAuthTokenLine(npmrcContent); |
| 158 | + expect(result).toBeUndefined(); |
| 159 | + }); |
| 160 | +}); |
0 commit comments