Skip to content

Commit 63aa518

Browse files
authored
Complete TypeScript conversion of src/fixtures directory (#56399)
1 parent 97ef591 commit 63aa518

22 files changed

+278
-203
lines changed

src/fixtures/fixtures/data/allowed-topics.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/fixtures/tests/annotations.js renamed to src/fixtures/tests/annotations.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { describe, expect, test } from 'vitest'
2+
import cheerio from 'cheerio'
23

3-
import { getDOM } from '#src/tests/helpers/e2etest.js'
4+
import { getDOM } from '@/tests/helpers/e2etest'
45

56
describe('annotations', () => {
67
test('code-snippet-with-hashbang', async () => {
7-
const $ = await getDOM('/get-started/foo/code-snippet-with-hashbang')
8+
const $: cheerio.Root = await getDOM('/get-started/foo/code-snippet-with-hashbang')
89
const annotations = $('#article-contents .annotate')
910

1011
// Check http://localhost:4000/en/get-started/foo/code-snippet-with-hashbang
@@ -21,7 +22,7 @@ describe('annotations', () => {
2122
expect(annotation.find('.annotate-inline').length).toBe(1)
2223
expect(annotation.find('.annotate-row').length).toBe(3)
2324
const notes = $('.annotate-row .annotate-note p', annotation)
24-
const noteTexts = notes.map((i, el) => $(el).text()).get()
25+
const noteTexts = notes.map((i: number, el: any) => $(el).text()).get()
2526
expect(noteTexts).toEqual(["Let's get started", 'This is just a sample', 'End of the script'])
2627
}
2728
// Second code snippet block
@@ -32,7 +33,7 @@ describe('annotations', () => {
3233
expect(annotation.find('.annotate-inline').length).toBe(1)
3334
expect(annotation.find('.annotate-row').length).toBe(2)
3435
const notes = $('.annotate-row .annotate-note p', annotation)
35-
const noteTexts = notes.map((i, el) => $(el).text()).get()
36+
const noteTexts = notes.map((i: number, el: any) => $(el).text()).get()
3637
expect(noteTexts).toEqual(['Has to start with a comment.', 'This is the if statement'])
3738
}
3839
// Yaml code snippet that starts with an empty comment
@@ -43,7 +44,7 @@ describe('annotations', () => {
4344
expect(annotation.find('.annotate-inline').length).toBe(1)
4445
expect(annotation.find('.annotate-row').length).toBe(3)
4546
const notes = $('.annotate-row .annotate-note p', annotation)
46-
const noteTexts = notes.map((i, el) => $(el).text()).get()
47+
const noteTexts = notes.map((i: number, el: any) => $(el).text()).get()
4748
expect(noteTexts).toEqual([
4849
'Configures this workflow to run every time a change is pushed to the branch called release.',
4950
'This job checks out the repository contents ...\n' + "And here's the second comment line.",

src/fixtures/tests/bad-urls.js renamed to src/fixtures/tests/bad-urls.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, test } from 'vitest'
22

3-
import { head } from '#src/tests/helpers/e2etest.js'
3+
import { head } from '@/tests/helpers/e2etest'
44

55
describe('bad URLs', () => {
66
test('any URL with /index.md suffix redirects to be without suffix', async () => {
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
import { describe, expect, test } from 'vitest'
2+
import cheerio from 'cheerio'
23

3-
import { getDOM, head } from '#src/tests/helpers/e2etest.js'
4+
import { getDOM, head } from '@/tests/helpers/e2etest'
45

56
describe('subcategories', () => {
67
test('get-started/start-your-journey subcategory', async () => {
7-
const $ = await getDOM('/get-started/start-your-journey')
8+
const $: cheerio.Root = await getDOM('/get-started/start-your-journey')
89
const lead = $('[data-search=lead]').text()
910
expect(lead).toMatch('Get started using HubGit to manage Git repositories')
1011

1112
const links = $('[data-testid=table-of-contents] a[href]')
1213
expect(links.length).toBeGreaterThan(0)
1314
// They all have the same prefix
14-
const hrefs = links.map((i, el) => $(el).attr('href')).get()
15+
const hrefs = links.map((i: number, el: any) => $(el).attr('href')).get()
1516
expect(
16-
hrefs.every((href) => href.startsWith('/en/get-started/start-your-journey/')),
17+
hrefs.every((href: string) => href.startsWith('/en/get-started/start-your-journey/')),
1718
).toBeTruthy()
1819
// The all resolve to a 200 OK without redirects
19-
const responses = await Promise.all(hrefs.map((href) => head(href)))
20-
expect(responses.every((r) => r.statusCode === 200)).toBeTruthy()
20+
const responses = await Promise.all(hrefs.map((href: string) => head(href)))
21+
expect(responses.every((r: any) => r.statusCode === 200)).toBeTruthy()
2122
})
2223

2324
test('actions/category/subcategory subcategory has its articles intro', async () => {
24-
const $ = await getDOM('/actions/category/subcategory')
25+
const $: cheerio.Root = await getDOM('/actions/category/subcategory')
2526
const lead = $('[data-search=lead]').text()
2627
expect(lead).toMatch("Here's the intro for HubGit Actions.")
2728

2829
const links = $('[data-testid=table-of-contents] a[href]')
29-
const hrefs = links.map((i, el) => $(el).attr('href')).get()
30-
expect(hrefs.every((href) => href.startsWith('/en/actions/category/'))).toBeTruthy()
30+
const hrefs = links.map((i: number, el: any) => $(el).attr('href')).get()
31+
expect(hrefs.every((href: string) => href.startsWith('/en/actions/category/'))).toBeTruthy()
3132

3233
const firstArticleH2 = $('[data-testid=table-of-contents] h2').first()
3334
expect(firstArticleH2.text()).toMatch('Article title')
@@ -42,17 +43,17 @@ describe('subcategories', () => {
4243

4344
describe('categories', () => {
4445
test('actions/category subcategory', async () => {
45-
const $ = await getDOM('/actions/category')
46+
const $: cheerio.Root = await getDOM('/actions/category')
4647
const lead = $('[data-search=lead]').text()
4748
expect(lead).toMatch('Learn how to migrate your existing CI/CD')
4849

4950
const links = $('[data-testid=table-of-contents] a[href]')
5051
expect(links.length).toBeGreaterThan(0)
5152
// They all have the same prefix
52-
const hrefs = links.map((i, el) => $(el).attr('href')).get()
53-
expect(hrefs.every((href) => href.startsWith('/en/actions/category/'))).toBeTruthy()
53+
const hrefs = links.map((i: number, el: any) => $(el).attr('href')).get()
54+
expect(hrefs.every((href: string) => href.startsWith('/en/actions/category/'))).toBeTruthy()
5455
// The all resolve to a 200 OK without redirects
55-
const responses = await Promise.all(hrefs.map((href) => head(href)))
56-
expect(responses.every((r) => r.statusCode === 200)).toBeTruthy()
56+
const responses = await Promise.all(hrefs.map((href: string) => head(href)))
57+
expect(responses.every((r: any) => r.statusCode === 200)).toBeTruthy()
5758
})
5859
})

src/fixtures/tests/footer.js renamed to src/fixtures/tests/footer.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { describe, expect, test } from 'vitest'
2+
import cheerio from 'cheerio'
23

3-
import { getDOM } from '#src/tests/helpers/e2etest.js'
4-
import nonEnterpriseDefaultVersion from '#src/versions/lib/non-enterprise-default-version.js'
4+
import { getDOM } from '@/tests/helpers/e2etest'
5+
import nonEnterpriseDefaultVersion from '@/versions/lib/non-enterprise-default-version'
56

67
describe('footer', () => {
78
describe('"contact us" link', () => {
89
test('leads to support from articles', async () => {
9-
const $ = await getDOM(
10+
const $: cheerio.Root = await getDOM(
1011
`/en/${nonEnterpriseDefaultVersion}/get-started/start-your-journey/hello-world`,
1112
)
1213
expect($('a#support').attr('href')).toBe('https://support.github.com')
@@ -15,21 +16,21 @@ describe('footer', () => {
1516
test('leads to support on 404 pages', async () => {
1617
// Important to use the prefix /en/ on the failing URL or else
1718
// it will render a very basic plain text 404 response.
18-
const $ = await getDOM('/en/delicious-snacks/donuts.php', { allow404: true })
19+
const $: cheerio.Root = await getDOM('/en/delicious-snacks/donuts.php', { allow404: true })
1920
expect($('a#support').attr('href')).toBe('https://support.github.com')
2021
})
2122
})
2223

2324
describe('"support" link with nextjs', () => {
2425
test('leads to support from articles', async () => {
25-
const $ = await getDOM(`/en/${nonEnterpriseDefaultVersion}/get-started?nextjs=`)
26+
const $: cheerio.Root = await getDOM(`/en/${nonEnterpriseDefaultVersion}/get-started?nextjs=`)
2627
expect($('a#support').attr('href')).toBe('https://support.github.com')
2728
})
2829
})
2930

3031
describe('test redirects for product landing community links pages', () => {
3132
test('codespaces product landing page leads to discussions page', async () => {
32-
const $ = await getDOM('/en/get-started')
33+
const $: cheerio.Root = await getDOM('/en/get-started')
3334
expect($('a#ask-community').attr('href')).toBe(
3435
'https://hubgit.com/orgs/community/discussions/categories/get-started',
3536
)
@@ -38,7 +39,7 @@ describe('footer', () => {
3839

3940
describe('test redirects for non-product landing community links pages', () => {
4041
test('leads to https://github.community/ when clicking on the community link', async () => {
41-
const $ = await getDOM(`/en/get-started/start-your-journey/hello-world`)
42+
const $: cheerio.Root = await getDOM(`/en/get-started/start-your-journey/hello-world`)
4243
expect($('a#ask-community').attr('href')).toBe(
4344
'https://github.com/orgs/community/discussions',
4445
)

src/fixtures/tests/glossary.js renamed to src/fixtures/tests/glossary.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,53 @@
11
import { describe, expect, test } from 'vitest'
2+
import cheerio from 'cheerio'
23

3-
import { getDOMCached as getDOM } from '#src/tests/helpers/e2etest.js'
4+
import { getDOMCached as getDOM } from '@/tests/helpers/e2etest'
45

56
describe('glossary', () => {
67
test('headings are sorted alphabetically', async () => {
7-
const $ = await getDOM('/get-started/learning-about-github/github-glossary')
8+
const $: cheerio.Root = await getDOM('/get-started/learning-about-github/github-glossary')
89
const headings = $('#article-contents h2')
9-
const headingTexts = headings.map((_, el) => $(el).text()).get()
10-
const cloned = [...headingTexts].sort((a, b) => a.localeCompare(b))
11-
const equalStringArray = (a, b) => a.length === b.length && a.every((v, i) => v === b[i])
10+
const headingTexts = headings.map((_: number, el: any) => $(el).text()).get()
11+
const cloned = [...headingTexts].sort((a: string, b: string) => a.localeCompare(b))
12+
const equalStringArray = (a: string[], b: string[]) =>
13+
a.length === b.length && a.every((v, i) => v === b[i])
1214
expect(equalStringArray(headingTexts, cloned)).toBe(true)
1315
})
1416
test('Markdown links are correct', async () => {
15-
const $ = await getDOM('/get-started/learning-about-github/github-glossary')
17+
const $: cheerio.Root = await getDOM('/get-started/learning-about-github/github-glossary')
1618
const internalLink = $('#article-contents a[href="/en/get-started/foo"]')
1719
expect(internalLink.length).toBe(1)
1820
// That link used AUTOTITLE so it should be "expanded"
1921
expect(internalLink.text()).toBe('Fooing Around')
2022
})
2123

2224
test('all Liquid is evaluated', async () => {
23-
const $ = await getDOM('/get-started/learning-about-github/github-glossary')
25+
const $: cheerio.Root = await getDOM('/get-started/learning-about-github/github-glossary')
2426
const paragraphs = $('#article-contents p')
25-
const paragraphTexts = paragraphs.map((_, el) => $(el).text()).get()
26-
expect(paragraphTexts.find((text) => text.includes('{%'))).toBe(undefined)
27+
const paragraphTexts = paragraphs.map((_: number, el: any) => $(el).text()).get()
28+
expect(paragraphTexts.find((text: string) => text.includes('{%'))).toBe(undefined)
2729
})
2830

2931
test('liquid in one of the description depends on version', async () => {
3032
// fpt
3133
{
32-
const $ = await getDOM('/get-started/learning-about-github/github-glossary')
34+
const $: cheerio.Root = await getDOM('/get-started/learning-about-github/github-glossary')
3335
const paragraphs = $('#article-contents p')
3436
const paragraphTexts = paragraphs
35-
.map((_, el) => $(el).text())
37+
.map((_: number, el: any) => $(el).text())
3638
.get()
3739
.join('\n')
3840
expect(paragraphTexts).toContain('status check on HubGit.')
3941
}
4042

4143
// ghes
4244
{
43-
const $ = await getDOM(
45+
const $: cheerio.Root = await getDOM(
4446
'/enterprise-server@latest/get-started/learning-about-github/github-glossary',
4547
)
4648
const paragraphs = $('#article-contents p')
4749
const paragraphTexts = paragraphs
48-
.map((_, el) => $(el).text())
50+
.map((_: number, el: any) => $(el).text())
4951
.get()
5052
.join('\n')
5153
expect(paragraphTexts).toContain('status check on HubGit Enterprise Server.')

src/fixtures/tests/guides.js renamed to src/fixtures/tests/guides.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { describe, expect, test } from 'vitest'
2+
import cheerio from 'cheerio'
23

3-
import { get, getDOMCached as getDOM } from '#src/tests/helpers/e2etest.js'
4+
import { get, getDOMCached as getDOM } from '@/tests/helpers/e2etest'
45

56
describe('guides', () => {
67
test("page's title should be document title", async () => {
7-
const $ = await getDOM('/code-security/guides')
8+
const $: cheerio.Root = await getDOM('/code-security/guides')
89
// This is what you'd find in src/fixtures/fixtures/content/code-security/guides.md
910
const title = 'Guides for cool security'
1011
expect($('title').text()).toMatch(title)
@@ -18,24 +19,28 @@ describe('guides', () => {
1819

1920
describe('learning tracks', () => {
2021
test('start the first learning track and come back via the navigation banner', async () => {
21-
const $ = await getDOM('/code-security/guides')
22+
const $: cheerio.Root = await getDOM('/code-security/guides')
2223
const links = $('[data-testid=learning-track] a')
23-
const link = links.filter((_, el) => $(el).text() === 'Start learning path').first()
24+
const link = links
25+
.filter((_: number, el: any) => $(el).text() === 'Start learning path')
26+
.first()
2427
expect(link.attr('href')).toMatch('learn=foo_bar')
2528
expect(link.attr('href')).toMatch('learnProduct=code-security')
2629

2730
// Go the first "Start learning path" link
28-
const $2 = await getDOM(link.attr('href'))
31+
const $2: cheerio.Root = await getDOM(link.attr('href')!)
2932
const card2 = $2('[data-testid=learning-track-card]')
3033
// The card has 2 links. One to go back to the guide page
3134
// whose title is the name of the learning track
3235
const backLink = card2.find('a').first()
3336
expect(backLink.attr('href')).toBe('/en/code-security/guides')
3437
expect(backLink.text()).toBe('Fix the plumbing')
3538
// Underneath it says "1 of in learning path"
36-
const span = card2.find('span').filter((_, el) => $(el).text().includes('1 of 2'))
39+
const span = card2.find('span').filter((_: number, el: any) => $(el).text().includes('1 of 2'))
3740
expect(span.text()).toBe('1 of 2 in learning path')
38-
const nextWrapper = card2.find('span').filter((_, el) => $(el).text().includes('Next'))
41+
const nextWrapper = card2
42+
.find('span')
43+
.filter((_: number, el: any) => $(el).text().includes('Next'))
3944
expect(nextWrapper.length).toBe(1)
4045
const nextLink = nextWrapper.find('a').first()
4146
expect(nextLink.attr('href')).toMatch(
@@ -52,14 +57,18 @@ describe('learning tracks', () => {
5257
expect(navNextLink.text()).toBe('Securing your organization')
5358

5459
// Go to the next (last) page
55-
const $3 = await getDOM(nextLink.attr('href'))
60+
const $3: cheerio.Root = await getDOM(nextLink.attr('href')!)
5661
const card3 = $3('[data-testid=learning-track-card]')
57-
const span3 = card3.find('span').filter((_, el) => $(el).text().includes('2 of 2'))
62+
const span3 = card3.find('span').filter((_: number, el: any) => $(el).text().includes('2 of 2'))
5863
expect(span3.text()).toBe('2 of 2 in learning path')
5964
// No "Next:" link now
60-
const nextWrapper3 = card3.find('span').filter((_, el) => $(el).text().includes('Next'))
65+
const nextWrapper3 = card3
66+
.find('span')
67+
.filter((_: number, el: any) => $(el).text().includes('Next'))
6168
expect(nextWrapper3.length).toBe(0)
62-
const moreGuidesLink = card3.find('a').filter((_, el) => $(el).text().includes('More guides'))
69+
const moreGuidesLink = card3
70+
.find('a')
71+
.filter((_: number, el: any) => $(el).text().includes('More guides'))
6372
expect(moreGuidesLink.attr('href')).toBe('/en/code-security/guides')
6473

6574
// On this last page, the nav will link to the previous page
@@ -73,25 +82,29 @@ describe('learning tracks', () => {
7382
test('with and without a valid ?learn= query string', async () => {
7483
// Valid
7584
{
76-
const $ = await getDOM('/code-security/getting-started/quickstart?learn=foo_bar')
85+
const $: cheerio.Root = await getDOM(
86+
'/code-security/getting-started/quickstart?learn=foo_bar',
87+
)
7788
expect($('[data-testid=learning-track-card]').length).toBe(1)
7889
expect($('[data-testid=learning-track-nav]').length).toBe(1)
7990
}
8091
// Invalid
8192
{
82-
const $ = await getDOM('/code-security/getting-started/quickstart?learn=blablainvalid')
93+
const $: cheerio.Root = await getDOM(
94+
'/code-security/getting-started/quickstart?learn=blablainvalid',
95+
)
8396
expect($('[data-testid=learning-track-card]').length).toBe(0)
8497
expect($('[data-testid=learning-track-nav]').length).toBe(0)
8598
}
8699
// Empty
87100
{
88-
const $ = await getDOM('/code-security/getting-started/quickstart?learn=')
101+
const $: cheerio.Root = await getDOM('/code-security/getting-started/quickstart?learn=')
89102
expect($('[data-testid=learning-track-card]').length).toBe(0)
90103
expect($('[data-testid=learning-track-nav]').length).toBe(0)
91104
}
92105
// Missing
93106
{
94-
const $ = await getDOM('/code-security/getting-started/quickstart')
107+
const $: cheerio.Root = await getDOM('/code-security/getting-started/quickstart')
95108
expect($('[data-testid=learning-track-card]').length).toBe(0)
96109
expect($('[data-testid=learning-track-nav]').length).toBe(0)
97110
}

src/fixtures/tests/head.js renamed to src/fixtures/tests/head.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { describe, expect, test } from 'vitest'
2+
import cheerio from 'cheerio'
23

3-
import { getDOM } from '#src/tests/helpers/e2etest.js'
4+
import { getDOM } from '@/tests/helpers/e2etest'
45

56
describe('<head>', () => {
67
test('includes page intro in `description` meta tag', async () => {
7-
const $ = await getDOM('/get-started/markdown/intro')
8+
const $: cheerio.Root = await getDOM('/get-started/markdown/intro')
89
// The intro has Markdown syntax which becomes HTML encoded in the lead element.
910
const lead = $('[data-testid="lead"] p')
1011
expect(lead.html()).toMatch('<code>syntax</code>')

src/fixtures/tests/homepage.js renamed to src/fixtures/tests/homepage.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
import { describe, expect, test } from 'vitest'
2+
import cheerio from 'cheerio'
23

3-
import { get, getDOM } from '#src/tests/helpers/e2etest.js'
4+
import { get, getDOM } from '@/tests/helpers/e2etest'
45

56
describe('home page', () => {
67
test('landing area', async () => {
7-
const $ = await getDOM('/')
8+
const $: cheerio.Root = await getDOM('/')
89
const container = $('#landing')
910
expect(container.length).toBe(1)
1011
expect(container.find('h1').text()).toBe('GitHub Docs')
1112
expect(container.find('p').text()).toMatch('Help for wherever you are on your GitHub journey')
1213
})
1314

1415
test('product groups can use Liquid', async () => {
15-
const $ = await getDOM('/')
16+
const $: cheerio.Root = await getDOM('/')
1617
const main = $('[data-testid="product"]')
1718
const links = main.find('a[href*="/"]')
18-
const hrefs = links.map((i, link) => $(link)).get()
19+
const hrefs = links.map((i: number, link: any) => $(link)).get()
1920
let externalLinks = 0
2021
for (const href of hrefs) {
21-
if (!href.attr('href').startsWith('https://')) {
22-
const res = await get(href.attr('href'))
22+
if (!href.attr('href')?.startsWith('https://')) {
23+
const res = await get(href.attr('href')!)
2324
expect(res.statusCode).toBe(200) // Not needing to redirect
2425
expect(href.text().includes('{%')).toBe(false)
2526
} else {

0 commit comments

Comments
 (0)