-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.test.ts
34 lines (27 loc) · 1.5 KB
/
index.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
import { getPreviewUrlFromString } from "./index.utils";
// Change below if you wish to test your pattern.
const regexPattern =
"(?:Preview: \\[?(.*)\\]?|\\[Visit Preview\\]\\(([^\\s]*)\\))";
describe("getPreviewUrlFromStrings tests", () => {
test("should retrieve a preview URL from an input string", () => {
// Invalid preview URL comment
const result1 = getPreviewUrlFromString("random_string", regexPattern);
// Old preview URL comment format
const result2 = getPreviewUrlFromString(
`This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)). To see the status of your deployment, click below or on the icon next to each commit.
mag Inspect: https://vercel.com/123456789-old white_check_mark Preview: https://vercel.com/aaimio/123456789-old
`,
regexPattern
);
// New preview URL comment format
const result3 = getPreviewUrlFromString(
`**The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more)
Name Status Preview Updated
**my-website** white_check_mark Ready ([Inspect](https://vercel.com/123456789-new)) [Visit Preview](https://vercel.com/aaimio/123456789-new) Feb 6, 1993 at 9:50AM (UTC)`,
regexPattern
);
expect(result1).toEqual("");
expect(result2).toEqual("https://vercel.com/aaimio/123456789-old");
expect(result3).toEqual("https://vercel.com/aaimio/123456789-new");
});
});