Skip to content

Commit

Permalink
QD-10723 Test summary, comment and push-fixes for azure pipelines (#…
Browse files Browse the repository at this point in the history
…444)

Co-authored-by: Andrei Iurko <[email protected]>
  • Loading branch information
AndreiIurko and Andrei Iurko authored Feb 10, 2025
1 parent fbe40c5 commit f006661
Show file tree
Hide file tree
Showing 28 changed files with 108,623 additions and 1,875 deletions.
8,053 changes: 8,053 additions & 0 deletions common/__tests__/data/empty.sarif.json

Large diffs are not rendered by default.

8,278 changes: 8,278 additions & 0 deletions common/__tests__/data/some.sarif.json

Large diffs are not rendered by default.

113 changes: 113 additions & 0 deletions common/__tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright 2021-2024 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {expect, test} from '@jest/globals'
import {getCoverageFromSarif, QODANA_OPEN_IN_IDE_NAME, QODANA_REPORT_URL_NAME} from "../qodana";
import {
getCoverageStats,
getReportURL
} from "../output";
import * as fs from 'fs'
import * as path from 'path'
import * as os from 'os'

test('test passed coverage output', () => {
const result = getCoverageStats(
getCoverageFromSarif('__tests__/data/some.sarif.json')
)
expect(result).toEqual(passedCoverageFixture())
})

test('test failed coverage output', () => {
const result = getCoverageStats(
getCoverageFromSarif('__tests__/data/empty.sarif.json')
)
expect(result).toEqual(failedCoverageFixture())
})

describe('getReportURL', () => {
let tempDir: string

beforeEach(async () => {
// create a unique temporary directory for each test
tempDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'jest-'))
})

afterEach(async () => {
// cleanup - remove temporary directory
await fs.promises.rm(tempDir, {recursive: true})
})

it('returns cloud URL if open in IDE file exists', async () => {
const url = 'http://cloud.url'
const data = {cloud: {url}}
const filepath = path.join(tempDir, QODANA_OPEN_IN_IDE_NAME)
await fs.promises.writeFile(filepath, JSON.stringify(data))
console.log(JSON.stringify(data))

const result = getReportURL(tempDir)

expect(result).toBe(url)
})

it('returns report URL if open in IDE file does not exist but report file exists', async () => {
const url = 'http://report.url'
const filepath = path.join(tempDir, QODANA_REPORT_URL_NAME)
await fs.promises.writeFile(filepath, url)

const result = getReportURL(tempDir)

expect(result).toBe(url)
})

it('returns empty string if no file exists', () => {
const result = getReportURL(tempDir)

expect(result).toBe('')
})

it('returns empty string if open in IDE file exists but does not contain url', async () => {
const data = {cloud: {}}
const filepath = path.join(tempDir, QODANA_OPEN_IN_IDE_NAME)
await fs.promises.writeFile(filepath, JSON.stringify(data))

const result = getReportURL(tempDir)

expect(result).toBe('')
})
})

function passedCoverageFixture(): string {
return `\`\`\`diff
@@ Code coverage @@
+ 45% total lines covered
124 lines analyzed, 56 lines covered
+ 33% fresh lines covered
9 lines analyzed, 3 lines covered
# Calculated according to the filters of your coverage tool
\`\`\``
}

function failedCoverageFixture(): string {
return `\`\`\`diff
@@ Code coverage @@
- 0% total lines covered
100 lines analyzed, 0 lines covered
- 0% fresh lines covered
100 lines analyzed, 0 lines covered
# Calculated according to the filters of your coverage tool
\`\`\``
}
30 changes: 30 additions & 0 deletions common/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2021-2024 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: false,
testTimeout: 400000,
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts'],
coverageReporters: ['html', ['lcovonly', { projectRoot: '../' }], 'text-summary'],
coveragePathIgnorePatterns: ['node_modules', 'src/utils.ts', 'src/main.ts'],
}
Loading

0 comments on commit f006661

Please sign in to comment.