mirror of https://github.com/actions/toolkit
add -> addRaw
parent
ec5c955c0a
commit
d27bf857e6
|
@ -84,61 +84,67 @@ describe('@actions/core/src/markdown-summary', () => {
|
|||
|
||||
it('throws if summary env var is undefined', async () => {
|
||||
process.env[SUMMARY_ENV_VAR] = undefined
|
||||
const write = markdownSummary.add(fixtures.text).write()
|
||||
const write = markdownSummary.addRaw(fixtures.text).write()
|
||||
|
||||
await expect(write).rejects.toThrow()
|
||||
})
|
||||
|
||||
it('throws if summary file does not exist', async () => {
|
||||
await fs.promises.unlink(testFilePath)
|
||||
const write = markdownSummary.add(fixtures.text).write()
|
||||
const write = markdownSummary.addRaw(fixtures.text).write()
|
||||
|
||||
await expect(write).rejects.toThrow()
|
||||
})
|
||||
|
||||
it('throws if write will exceed file limit', async () => {
|
||||
const aaa = 'a'.repeat(SUMMARY_LIMIT_BYTES + 1)
|
||||
const write = markdownSummary.add(aaa).write()
|
||||
const write = markdownSummary.addRaw(aaa).write()
|
||||
|
||||
await expect(write).rejects.toThrow()
|
||||
})
|
||||
|
||||
it('appends text to summary file', async () => {
|
||||
await fs.promises.writeFile(testFilePath, '# ', {encoding: 'utf8'})
|
||||
await markdownSummary.add(fixtures.text).write()
|
||||
await markdownSummary.addRaw(fixtures.text).write()
|
||||
await assertSummary(`# ${fixtures.text}`)
|
||||
})
|
||||
|
||||
it('overwrites text to summary file', async () => {
|
||||
await fs.promises.writeFile(testFilePath, 'overwrite', {encoding: 'utf8'})
|
||||
await markdownSummary.add(fixtures.text).write(true)
|
||||
await markdownSummary.addRaw(fixtures.text).write(true)
|
||||
await assertSummary(fixtures.text)
|
||||
})
|
||||
|
||||
it('appends text with EOL to summary file', async () => {
|
||||
await fs.promises.writeFile(testFilePath, '# ', {encoding: 'utf8'})
|
||||
await markdownSummary.addRaw(fixtures.text, true).write()
|
||||
await assertSummary(`# ${fixtures.text}${os.EOL}`)
|
||||
})
|
||||
|
||||
it('chains appends text to summary file', async () => {
|
||||
await fs.promises.writeFile(testFilePath, '', {encoding: 'utf8'})
|
||||
await markdownSummary
|
||||
.add(fixtures.text)
|
||||
.add(fixtures.text)
|
||||
.add(fixtures.text)
|
||||
.addRaw(fixtures.text)
|
||||
.addRaw(fixtures.text)
|
||||
.addRaw(fixtures.text)
|
||||
.write()
|
||||
await assertSummary([fixtures.text, fixtures.text, fixtures.text].join(''))
|
||||
})
|
||||
|
||||
it('empties buffer after write', async () => {
|
||||
await fs.promises.writeFile(testFilePath, '', {encoding: 'utf8'})
|
||||
await markdownSummary.add(fixtures.text).write()
|
||||
await markdownSummary.addRaw(fixtures.text).write()
|
||||
await assertSummary(fixtures.text)
|
||||
expect(markdownSummary.isEmptyBuffer()).toBe(true)
|
||||
})
|
||||
|
||||
it('returns summary buffer as string', () => {
|
||||
markdownSummary.add(fixtures.text)
|
||||
markdownSummary.addRaw(fixtures.text)
|
||||
expect(markdownSummary.stringify()).toEqual(fixtures.text)
|
||||
})
|
||||
|
||||
it('return correct values for isEmptyBuffer', () => {
|
||||
markdownSummary.add(fixtures.text)
|
||||
markdownSummary.addRaw(fixtures.text)
|
||||
expect(markdownSummary.isEmptyBuffer()).toBe(false)
|
||||
|
||||
markdownSummary.emptyBuffer()
|
||||
|
@ -147,7 +153,7 @@ describe('@actions/core/src/markdown-summary', () => {
|
|||
|
||||
it('adds EOL', async () => {
|
||||
await markdownSummary
|
||||
.add(fixtures.text)
|
||||
.addRaw(fixtures.text)
|
||||
.addEOL()
|
||||
.write()
|
||||
await assertSummary(fixtures.text + os.EOL)
|
||||
|
|
|
@ -183,12 +183,13 @@ class MarkdownSummary {
|
|||
* Adds raw text to the summary buffer
|
||||
*
|
||||
* @param {string} text content to add
|
||||
* @param {boolean} [addEOL=false] (optional) append an EOL to the raw text (default: false)
|
||||
*
|
||||
* @returns {MarkdownSummary} markdown summary instance
|
||||
*/
|
||||
add(text: string): MarkdownSummary {
|
||||
addRaw(text: string, addEOL = false): MarkdownSummary {
|
||||
this._buffer += text
|
||||
return this
|
||||
return addEOL ? this.addEOL() : this
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,7 +198,7 @@ class MarkdownSummary {
|
|||
* @returns {MarkdownSummary} markdown summary instance
|
||||
*/
|
||||
addEOL(): MarkdownSummary {
|
||||
return this.add(EOL)
|
||||
return this.addRaw(EOL)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -213,14 +214,14 @@ class MarkdownSummary {
|
|||
...(lang && {lang})
|
||||
}
|
||||
const element = this.wrap('pre', this.wrap('code', code), attrs)
|
||||
return this.add(element).addEOL()
|
||||
return this.addRaw(element).addEOL()
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an HTML list to the summary buffer
|
||||
*
|
||||
* @param {string[]} items list of items to render
|
||||
* @param {boolean} [ordered=false] if the rendered list should be ordered or not (default: false)
|
||||
* @param {boolean} [ordered=false] (optional) if the rendered list should be ordered or not (default: false)
|
||||
*
|
||||
* @returns {MarkdownSummary} markdown summary instance
|
||||
*/
|
||||
|
@ -228,7 +229,7 @@ class MarkdownSummary {
|
|||
const tag = ordered ? 'ol' : 'ul'
|
||||
const listItems = items.map(item => this.wrap('li', item)).join('')
|
||||
const element = this.wrap(tag, listItems)
|
||||
return this.add(element).addEOL()
|
||||
return this.addRaw(element).addEOL()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -263,7 +264,7 @@ class MarkdownSummary {
|
|||
.join('')
|
||||
|
||||
const element = this.wrap('table', tableBody)
|
||||
return this.add(element).addEOL()
|
||||
return this.addRaw(element).addEOL()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -276,7 +277,7 @@ class MarkdownSummary {
|
|||
*/
|
||||
addDetails(label: string, content: string): MarkdownSummary {
|
||||
const element = this.wrap('details', this.wrap('summary', label) + content)
|
||||
return this.add(element).addEOL()
|
||||
return this.addRaw(element).addEOL()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -284,7 +285,7 @@ class MarkdownSummary {
|
|||
*
|
||||
* @param {string} src path to the image you to embed
|
||||
* @param {string} alt text description of the image
|
||||
* @param {SummaryImageOptions} options addition image attributes
|
||||
* @param {SummaryImageOptions} options (optional) addition image attributes
|
||||
*
|
||||
* @returns {MarkdownSummary} markdown summary instance
|
||||
*/
|
||||
|
@ -300,7 +301,7 @@ class MarkdownSummary {
|
|||
}
|
||||
|
||||
const element = this.wrap('img', null, {src, alt, ...attrs})
|
||||
return this.add(element).addEOL()
|
||||
return this.addRaw(element).addEOL()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -317,7 +318,7 @@ class MarkdownSummary {
|
|||
? tag
|
||||
: 'h1'
|
||||
const element = this.wrap(allowedTag, text)
|
||||
return this.add(element).addEOL()
|
||||
return this.addRaw(element).addEOL()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -327,7 +328,7 @@ class MarkdownSummary {
|
|||
*/
|
||||
addSeparator(): MarkdownSummary {
|
||||
const element = this.wrap('hr', null)
|
||||
return this.add(element).addEOL()
|
||||
return this.addRaw(element).addEOL()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -337,7 +338,7 @@ class MarkdownSummary {
|
|||
*/
|
||||
addBreak(): MarkdownSummary {
|
||||
const element = this.wrap('br', null)
|
||||
return this.add(element).addEOL()
|
||||
return this.addRaw(element).addEOL()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -353,7 +354,7 @@ class MarkdownSummary {
|
|||
...(cite && {cite})
|
||||
}
|
||||
const element = this.wrap('blockquote', text, attrs)
|
||||
return this.add(element).addEOL()
|
||||
return this.addRaw(element).addEOL()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -366,7 +367,7 @@ class MarkdownSummary {
|
|||
*/
|
||||
addLink(text: string, href: string): MarkdownSummary {
|
||||
const element = this.wrap('a', text, {href})
|
||||
return this.add(element).addEOL()
|
||||
return this.addRaw(element).addEOL()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue