|
1 | 1 | import { describe, expect, test, vi } from "vitest"; |
2 | 2 |
|
3 | | -import { endsWith, guid, isEmpty, isMatch, parseVersion, prune, randomNumber, startsWith, stringify, toBoolean } from "../src/Utils.js"; |
| 3 | +import { endsWith, guid, isEmpty, isMatch, normalizeEnvironment, parseVersion, prune, randomNumber, startsWith, stringify, toBoolean } from "../src/Utils.js"; |
4 | 4 |
|
5 | 5 | describe("Utils", () => { |
6 | 6 | function getObjectWithInheritedProperties(): unknown { |
@@ -1237,4 +1237,48 @@ describe("Utils", () => { |
1237 | 1237 | expect(toBoolean(true)).toBe(true); |
1238 | 1238 | }); |
1239 | 1239 | }); |
| 1240 | + |
| 1241 | + describe("normalizeEnvironment", () => { |
| 1242 | + test.each([ |
| 1243 | + ["production", "production"], |
| 1244 | + ["Staging-EU", "Staging-EU"], |
| 1245 | + ["qa.2", "qa.2"], |
| 1246 | + ["dev_local", "dev_local"], |
| 1247 | + ["a", "a"], |
| 1248 | + ["0", "0"], |
| 1249 | + [" Production \t", "Production"], |
| 1250 | + ["\u00a0Production\u2003", "Production"], |
| 1251 | + ["a" + "b".repeat(63), "a" + "b".repeat(63)], |
| 1252 | + [" " + "a".repeat(64) + " ", "a".repeat(64)] |
| 1253 | + ])("should accept %j", (value, expected) => { |
| 1254 | + expect(normalizeEnvironment(value)).toBe(expected); |
| 1255 | + }); |
| 1256 | + |
| 1257 | + test.each([ |
| 1258 | + null, |
| 1259 | + undefined, |
| 1260 | + "", |
| 1261 | + " ", |
| 1262 | + " \t\r\n ", |
| 1263 | + "Staging West", |
| 1264 | + "prod/eu", |
| 1265 | + "prod:eu", |
| 1266 | + "-prod", |
| 1267 | + ".prod", |
| 1268 | + "_prod", |
| 1269 | + "produção", |
| 1270 | + "İ".repeat(64), |
| 1271 | + "a".repeat(65), |
| 1272 | + " " + "a".repeat(65) + " ", |
| 1273 | + "prod\ninvalid", |
| 1274 | + "prod\tinvalid", |
| 1275 | + "pro\u0000d", |
| 1276 | + "prod\u007f", |
| 1277 | + "pro\u0085d", |
| 1278 | + "prod\u200b", |
| 1279 | + "prod\n\u2028x" |
| 1280 | + ])("should reject %j", (value) => { |
| 1281 | + expect(normalizeEnvironment(value)).toBeUndefined(); |
| 1282 | + }); |
| 1283 | + }); |
1240 | 1284 | }); |
0 commit comments