forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannotate.js
More file actions
82 lines (71 loc) · 2.6 KB
/
Copy pathannotate.js
File metadata and controls
82 lines (71 loc) · 2.6 KB
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
import { describe, expect, test } from 'vitest'
import cheerio from 'cheerio'
import { renderContent } from '#src/content-render/index.js'
const example = `
\`\`\`yaml annotate
# The name of the workflow as it will appear in the "Actions" tab of the GitHub repository.
name: Post welcome comment
# Add the \`pull_request\` event, so that the workflow runs automatically
# every time a pull request is created.
on:
pull_request:
types: [opened]
\`\`\`
`
describe('annotate', () => {
test('renders annotations', async () => {
// We don't normally use snapshots,
// but in this case its a short and concise example
// that won't change regularly.
// If it fails, study the output and make sure it's correct.
// If it is indeed correct, run `vitest --updateSnapshot` to update it.
expect(await renderContent(example)).toMatchSnapshot()
})
test('renders bash with hash bang annotations', async () => {
const example = `
\`\`\`bash annotate
# The next line is the hash bang
#!/usr/bin/env bash
# Sample comment
echo "Hello, world!"
\`\`\`
`.trim()
const res = await renderContent(example)
const $ = cheerio.load(res)
const headerCode = $('header pre').text()
expect(headerCode).toMatch(example.split('\n').slice(1, -1).join('\n'))
const rows = $('.annotate-row')
const notes = $('.annotate-note p', rows)
const noteTexts = notes.map((i, el) => $(el).text()).get()
expect(noteTexts).toEqual(['The next line is the hash bang', 'Sample comment'])
const codes = $('.annotate-code pre', rows)
const codeTexts = codes.map((i, el) => $(el).text()).get()
expect(codeTexts).toEqual(['#!/usr/bin/env bash', 'echo "Hello, world!"'])
})
test("doesn't complain if the first comment is empty", async () => {
const example = `
\`\`\`yaml annotate copy
#
name: Create and publish a Docker image
# Configures this workflow to run every time...
on:
push:
branches: ['release']
\`\`\`
`.trim()
const res = await renderContent(example)
const $ = cheerio.load(res)
const headerCode = $('header pre').text()
expect(headerCode).toMatch(example.split('\n').slice(1, -1).join('\n'))
const rows = $('.annotate-row')
const notes = $('.annotate-note p', rows)
const noteTexts = notes.map((i, el) => $(el).text()).get()
expect(noteTexts).toEqual(['Configures this workflow to run every time...'])
const codes = $('.annotate-code pre', rows)
const codeTexts = codes.map((i, el) => $(el).text()).get()
expect(codeTexts).toEqual([
'name: Create and publish a Docker image',
"on:\n push:\n branches: ['release']",
])
})
})