-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Escape
testFailed
service message parameters only once (#298)
* fix: do not escape testFailed parameters * fix: do not escape test name as it is passed as message parameters to the escape function as well * test: add test suite on escaping messages
- Loading branch information
Showing
2 changed files
with
72 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { describe, it, expect, type Test } from 'vitest' | ||
import { escape } from '../app/escape' | ||
import { SuitMessage } from '../app/messages/suite-message' | ||
import { TestMessage } from '../app/messages/test-message' | ||
|
||
const escapeMap = { | ||
'\x1B1m': '', | ||
'|': '||', | ||
'\n': '|n', | ||
'\r': '|r', | ||
'[': '|[', | ||
']': '|]', | ||
'\u0085': '|x', | ||
'\u2028': '|l', | ||
'\u2029': '|p', | ||
"'": "|'", | ||
} | ||
|
||
const testNumber = Math.random() | ||
const expectedNumber = testNumber.toString() | ||
|
||
const testString = Object.keys(escapeMap).join('') | ||
const expectedString = Object.values(escapeMap).join('') | ||
|
||
describe('Checking message escaping functionality', () => { | ||
it('escaping of simple string or number is correct', () => { | ||
const escapedString = escape(testString) | ||
expect(escapedString).toStrictEqual(expectedString) | ||
|
||
const escapedNumber = escape(testNumber) | ||
expect(escapedNumber).toStrictEqual(expectedNumber) | ||
}) | ||
|
||
it('suite message parameters are correctly escaped', () => { | ||
const messageId = 'messageId' | ||
const messageName = 'messageName' | ||
const messageType = 'messageType' | ||
|
||
const message = new SuitMessage(messageId, messageName) | ||
|
||
const escapedParameters = message.generate(messageType, { | ||
testString, | ||
testNumber, | ||
}) | ||
|
||
expect(escapedParameters).toStrictEqual( | ||
`##teamcity[${messageType} flowId='${messageId}' testString='${expectedString}' testNumber='${expectedNumber}' name='${messageName}']` | ||
) | ||
}) | ||
|
||
it('test name is correctly escaped', () => { | ||
const testName = testString | ||
const fileId = 'fileId' | ||
|
||
const test = new TestMessage({ | ||
name: testName, | ||
file: { | ||
id: fileId, | ||
}, | ||
type: 'test', | ||
} as unknown as Test) | ||
|
||
const escapedMessage = test.started() | ||
expect(escapedMessage).toStrictEqual(`##teamcity[testStarted flowId='${fileId}' name='${expectedString}']`) | ||
}) | ||
}) |