mirror of
https://github.com/actions/toolkit
synced 2025-05-10 17:12:54 +00:00
summary: additional check for max size limit
This commit is contained in:
parent
302a5b31d8
commit
ec5c955c0a
2 changed files with 79 additions and 14 deletions
|
@ -1,7 +1,11 @@
|
|||
import * as fs from 'fs'
|
||||
import * as os from 'os'
|
||||
import path from 'path'
|
||||
import {markdownSummary, SUMMARY_ENV_VAR} from '../src/markdown-summary'
|
||||
import {
|
||||
markdownSummary,
|
||||
SUMMARY_ENV_VAR,
|
||||
SUMMARY_LIMIT_BYTES
|
||||
} from '../src/markdown-summary'
|
||||
|
||||
const testFilePath = path.join(__dirname, 'test', 'test-summary.md')
|
||||
|
||||
|
@ -68,18 +72,37 @@ const fixtures = {
|
|||
}
|
||||
|
||||
describe('@actions/core/src/markdown-summary', () => {
|
||||
beforeAll(() => {
|
||||
process.env[SUMMARY_ENV_VAR] = testFilePath
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
process.env[SUMMARY_ENV_VAR] = testFilePath
|
||||
await fs.promises.writeFile(testFilePath, '', {encoding: 'utf8'})
|
||||
markdownSummary.emptyBuffer()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await fs.promises.unlink(testFilePath)
|
||||
})
|
||||
|
||||
it('throws if summary env var is undefined', async () => {
|
||||
process.env[SUMMARY_ENV_VAR] = undefined
|
||||
const write = markdownSummary.add(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()
|
||||
|
||||
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()
|
||||
|
||||
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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue