-
Notifications
You must be signed in to change notification settings - Fork 292
/
Copy pathutils.test.ts
195 lines (157 loc) · 5.89 KB
/
utils.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import { getChangelogEntry, BumpLevels, sortTheThings, extractAuthTokenLine } from "./utils";
let changelog = `# @keystone-alpha/email
## 3.0.1
### Patch Changes
- [19fe6c1b](https://github.com/keystonejs/keystone-5/commit/19fe6c1b):
Move frontmatter in docs into comments
## 3.0.0
### Major Changes
- [2164a779](https://github.com/keystonejs/keystone-5/commit/2164a779):
- Replace jade with pug because Jade was renamed to Pug, and \`jade\` package is outdated
### Patch Changes
- [81dc0be5](https://github.com/keystonejs/keystone-5/commit/81dc0be5):
- Update dependencies
## 2.0.0
- [patch][b69fb9b7](https://github.com/keystonejs/keystone-5/commit/b69fb9b7):
- Update dev devependencies
- [major][f97e4ecf](https://github.com/keystonejs/keystone-5/commit/f97e4ecf):
- Export { emailSender } as the API, rather than a default export
## 1.0.2
- [patch][7417ea3a](https://github.com/keystonejs/keystone-5/commit/7417ea3a):
- Update patch-level dependencies
## 1.0.1
- [patch][1f0bc236](https://github.com/keystonejs/keystone-5/commit/1f0bc236):
- Update the package.json author field to "The Keystone Development Team"
## 1.0.0
- [major] 8b6734ae:
- This is the first release of keystone-alpha (previously voussoir).
All packages in the \`@voussoir\` namespace are now available in the \`@keystone-alpha\` namespace, starting at version \`1.0.0\`.
To upgrade your project you must update any \`@voussoir/<foo>\` dependencies in \`package.json\` to point to \`@keystone-alpha/<foo>: "^1.0.0"\` and update any \`require\`/\`import\` statements in your code.
# @voussoir/email
## 0.0.2
- [patch] 113e16d4:
- Remove unused dependencies
- [patch] 625c1a6d:
- Update mjml-dependency
`;
test("it works", () => {
let entry = getChangelogEntry(changelog, "3.0.0");
expect(entry.content).toMatchSnapshot();
expect(entry.highestLevel).toBe(BumpLevels.major);
});
test("it works", () => {
let entry = getChangelogEntry(changelog, "3.0.1");
expect(entry.content).toMatchSnapshot();
expect(entry.highestLevel).toBe(BumpLevels.patch);
});
test("it sorts the things right", () => {
let things = [
{
name: "a",
highestLevel: BumpLevels.major,
private: true,
},
{
name: "b",
highestLevel: BumpLevels.patch,
private: false,
},
{
name: "c",
highestLevel: BumpLevels.major,
private: false,
},
];
expect(things.sort(sortTheThings)).toMatchSnapshot();
});
/**
* Test the extractAuthTokenLine function for various registries.
*/
describe("extractAuthTokenLine", () => {
it("should correctly find the auth token line for multiple registries", () => {
const testCases = [
{
name: "Custom private registry with _authToken",
npmrc: `
registry=https://custom.private-registry.com/api/npm/npm/
//custom.private-registry.com/api/npm/npm/:_authToken=abcd1234
always-auth=true
`,
expected: "//custom.private-registry.com/api/npm/npm/:_authToken=abcd1234",
},
{
name: "Custom private registry with _auth",
npmrc: `
registry=https://custom.private-registry.com/api/npm/npm/
//custom.private-registry.com/api/npm/npm/:_auth=abcd1234
always-auth=true
`,
expected: "//custom.private-registry.com/api/npm/npm/:_auth=abcd1234",
},
{
name: "NPM default registry with _authToken",
npmrc: `
registry=https://registry.npmjs.org/
//registry.npmjs.org/:_authToken=efgh5678
`,
expected: "//registry.npmjs.org/:_authToken=efgh5678",
},
{
name: "NPM default registry with _auth",
npmrc: `
registry=https://registry.npmjs.org/
//registry.npmjs.org/:_auth=efgh5678
`,
expected: "//registry.npmjs.org/:_auth=efgh5678",
},
{
name: "AWS CodeArtifact registry with _authToken",
npmrc: `
registry=https://mydomain-111122223333.d.codeartifact.us-east-1.amazonaws.com/npm/repository-name/
//mydomain-111122223333.d.codeartifact.us-east-1.amazonaws.com/npm/repository-name/:_authToken=ijkl9012
`,
expected:
"//mydomain-111122223333.d.codeartifact.us-east-1.amazonaws.com/npm/repository-name/:_authToken=ijkl9012",
},
{
name: "AWS CodeArtifact registry with _auth",
npmrc: `
registry=https://mydomain-111122223333.d.codeartifact.us-east-1.amazonaws.com/npm/repository-name/
//mydomain-111122223333.d.codeartifact.us-east-1.amazonaws.com/npm/repository-name/:_auth=ijkl9012
`,
expected:
"//mydomain-111122223333.d.codeartifact.us-east-1.amazonaws.com/npm/repository-name/:_auth=ijkl9012",
},
{
name: "Azure DevOps registry with _authToken",
npmrc: `
registry=https://pkgs.dev.azure.com/myorg/_packaging/myfeed/npm/registry/
//pkgs.dev.azure.com/myorg/_packaging/myfeed/npm/registry/:_authToken=mnop3456
`,
expected:
"//pkgs.dev.azure.com/myorg/_packaging/myfeed/npm/registry/:_authToken=mnop3456",
},
{
name: "Azure DevOps registry with _auth",
npmrc: `
registry=https://pkgs.dev.azure.com/myorg/_packaging/myfeed/npm/registry/
//pkgs.dev.azure.com/myorg/_packaging/myfeed/npm/registry/:_auth=mnop3456
`,
expected:
"//pkgs.dev.azure.com/myorg/_packaging/myfeed/npm/registry/:_auth=mnop3456",
},
];
testCases.forEach(({ name, npmrc, expected }) => {
const result = extractAuthTokenLine(npmrc);
expect(result).toBe(expected);
});
});
it("should return undefined if no auth token line is present", () => {
const npmrcContent = `
registry=https://custom.private-registry.com/api/npm/npm/
always-auth=true
`;
const result = extractAuthTokenLine(npmrcContent);
expect(result).toBeUndefined();
});
});