Skip to content

Commit

Permalink
feat: Add testcase.status
Browse files Browse the repository at this point in the history
  • Loading branch information
Kesin11 committed Jul 29, 2020
1 parent 4b28ce1 commit 4b1b66c
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 14 deletions.
121 changes: 109 additions & 12 deletions __tests__/analyzer/analyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,13 @@ describe('Analyzer', () => {
}
const expected = JSON.parse(JSON.stringify(testSuites))
expected.testsuite[0].testcase[0].successCount = expect.anything()
expected.testsuite[0].testcase[0].status = expect.anything()

expect(convertToReportTestSuites(testSuites)).toStrictEqual(expected)
})
})

describe('Add some properties', () => {
describe('Add testcase.successCount', () => {
it('successCount = 1 when testcase is success', async () => {
const testSuites: TestSuites = {
tests: 1,
Expand All @@ -156,10 +157,9 @@ describe('Analyzer', () => {
}]
}]
}
const expected = JSON.parse(JSON.stringify(testSuites))
expected.testsuite[0].testcase[0].successCount = 1

expect(convertToReportTestSuites(testSuites)).toStrictEqual(expected)
const actual = convertToReportTestSuites(testSuites).testsuite[0].testcase[0].successCount
expect(actual).toEqual(1)
})

it('successCount = 0 when testcase is failed', async () => {
Expand All @@ -179,11 +179,9 @@ describe('Analyzer', () => {
}]
}]
}
const expected = JSON.parse(JSON.stringify(testSuites))
delete expected.testsuite[0].testcase[0].failure
expected.testsuite[0].testcase[0].successCount = 0

expect(convertToReportTestSuites(testSuites)).toStrictEqual(expected)
const actual = convertToReportTestSuites(testSuites).testsuite[0].testcase[0].successCount
expect(actual).toEqual(0)
})

it('successCount = 0 when testcase is error', async () => {
Expand All @@ -203,11 +201,110 @@ describe('Analyzer', () => {
}]
}]
}
const expected = JSON.parse(JSON.stringify(testSuites))
delete expected.testsuite[0].testcase[0].error
expected.testsuite[0].testcase[0].successCount = 0

expect(convertToReportTestSuites(testSuites)).toStrictEqual(expected)
const actual = convertToReportTestSuites(testSuites).testsuite[0].testcase[0].successCount
expect(actual).toEqual(0)
})

it('successCount = 0 when testcase is skipped', async () => {
const testSuites: TestSuites = {
tests: 1,
failures: 1,
testsuite: [{
name: 'testsuite',
tests: 1,
failures: 1,
testcase: [{
name: 'testcase',
classname: 'test',
skipped: [{
message: 'test skip: reason xxx'
}]
}]
}]
}

const actual = convertToReportTestSuites(testSuites).testsuite[0].testcase[0].successCount
expect(actual).toEqual(0)
})
})

describe('Add testcase.status', () => {
it('when testcase is success', async () => {
const testSuites: TestSuites = {
tests: 1,
testsuite: [{
name: 'testsuite',
tests: 1,
testcase: [{
name: 'testcase',
classname: 'test',
}]
}]
}

const actual = convertToReportTestSuites(testSuites).testsuite[0].testcase[0].status
expect(actual).toEqual('SUCCESS')
})

it('when testcase is failure', async () => {
const testSuites: TestSuites = {
tests: 1,
testsuite: [{
name: 'testsuite',
tests: 1,
testcase: [{
name: 'testcase',
classname: 'test',
failure: [{
inner: 'assert xxx',
}]
}]
}]
}

const actual = convertToReportTestSuites(testSuites).testsuite[0].testcase[0].status
expect(actual).toEqual('FAILURE')
})

it('when testcase is error', async () => {
const testSuites: TestSuites = {
tests: 1,
testsuite: [{
name: 'testsuite',
tests: 1,
testcase: [{
name: 'testcase',
classname: 'test',
error: [{
inner: 'assert xxx',
}]
}]
}]
}

const actual = convertToReportTestSuites(testSuites).testsuite[0].testcase[0].status
expect(actual).toEqual('ERROR')
})

it('when testcase is skipped', async () => {
const testSuites: TestSuites = {
tests: 1,
testsuite: [{
name: 'testsuite',
tests: 1,
testcase: [{
name: 'testcase',
classname: 'test',
skipped: [{
message: 'test skip: reason xxx',
}]
}]
}]
}

const actual = convertToReportTestSuites(testSuites).testsuite[0].testcase[0].status
expect(actual).toEqual('SKIPPED')
})
})
})
Expand Down
13 changes: 11 additions & 2 deletions src/analyzer/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Overwrite, Assign } from 'utility-types'

export type Status = 'SUCCESS' | 'FAILURE' | 'ABORTED' | 'OTHER'
export type TestStatus = 'SUCCESS' | 'FAILURE'
export type TestCaseStatus = 'SUCCESS' | 'FAILURE' | 'ERROR' | 'SKIPPED'

export type WorkflowReport = {
service: string
Expand Down Expand Up @@ -70,7 +71,10 @@ export type TestReport = {
// Omit properties that may contain free and huge text data.
export type ReportTestSuites = Overwrite<TestSuites, { testsuite: ReportTestSuite[] }>
export type ReportTestSuite = Overwrite<Omit<TestSuite, 'system-out' | 'system-err'>, { testcase: ReportTestCase[] }>
export type ReportTestCase = Assign<Omit<TestCase, 'error' | 'failure' | 'system-out' | 'system-err' | 'skipped'>, { successCount: 0 | 1 }>
export type ReportTestCase = Assign<
Omit<TestCase, 'error' | 'failure' | 'system-out' | 'system-err' | 'skipped'>
,{ successCount: 0 | 1, status: TestCaseStatus }
>

export type WorkflowParams = {
workflowId: string
Expand Down Expand Up @@ -104,7 +108,12 @@ export const convertToReportTestSuites = (testSuites: TestSuites): ReportTestSui
delete testSuite["system-out"]
delete testSuite["system-err"]
testSuite.testcase.forEach((testCase: TestCase) => {
(testCase as any).successCount = (testCase.failure || testCase.error) ? 0 : 1
(testCase as any).successCount = (testCase.failure || testCase.error || testCase.skipped) ? 0 : 1;
(testCase as any).status =
testCase.failure ? 'FAILURE'
: testCase.error ? 'ERROR'
: testCase.skipped ? 'SKIPPED'
: 'SUCCESS'
delete testCase["system-out"]
delete testCase["system-err"]
delete testCase.failure
Expand Down

0 comments on commit 4b1b66c

Please sign in to comment.