-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { debug } from 'console' | ||
import { config } from 'dotenv' | ||
|
||
import { GithubMerge } from '../src/github' | ||
|
||
describe('github', () => { | ||
config() | ||
const token = process.env.GITHUB_TOKEN ?? '' | ||
const repo = { | ||
owner: process.env.GITHUB_OWNER ?? '', | ||
repo: process.env.GITHUB_REPO ?? '' | ||
} | ||
// it('reviewComments', async () => { | ||
Check warning on line 13 in __tests__/github.test.ts GitHub Actions / TypeScript Tests
|
||
|
||
// const octokit = github.getOctokit(token) | ||
// const comments = await octokit.rest.pulls.listReviewComments({ | ||
// pull_number: 367, | ||
// ...github.context.repo | ||
// }) | ||
// debug(comments) | ||
// }) | ||
|
||
it('getQualityDiscussion', async () => { | ||
Check warning on line 23 in __tests__/github.test.ts GitHub Actions / TypeScript Tests
|
||
const githubMR = new GithubMerge({ | ||
pull_number: 9, | ||
token: token, | ||
Check failure on line 26 in __tests__/github.test.ts GitHub Actions / TypeScript Tests
|
||
repo: repo | ||
Check failure on line 27 in __tests__/github.test.ts GitHub Actions / TypeScript Tests
|
||
}) | ||
debug(await githubMR.getQualityDiscussion()) | ||
}) | ||
it('getReviews', async () => { | ||
Check warning on line 31 in __tests__/github.test.ts GitHub Actions / TypeScript Tests
|
||
const githubMR = new GithubMerge({ | ||
pull_number: 9, | ||
token: token, | ||
Check failure on line 34 in __tests__/github.test.ts GitHub Actions / TypeScript Tests
|
||
repo: repo | ||
Check failure on line 35 in __tests__/github.test.ts GitHub Actions / TypeScript Tests
|
||
}) | ||
debug(await githubMR.getReviews()) | ||
}) | ||
|
||
it('getReviewComments', async () => { | ||
Check warning on line 40 in __tests__/github.test.ts GitHub Actions / TypeScript Tests
|
||
const githubMR = new GithubMerge({ | ||
pull_number: 9, | ||
token: token, | ||
Check failure on line 43 in __tests__/github.test.ts GitHub Actions / TypeScript Tests
|
||
repo: repo | ||
Check failure on line 44 in __tests__/github.test.ts GitHub Actions / TypeScript Tests
|
||
}) | ||
debug(await githubMR.getReviewComments()) | ||
}) | ||
}) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,23 @@ | ||
/** | ||
* Unit tests for the action's main functionality, src/main.ts | ||
* | ||
* These should be run as if the action was called from a workflow. | ||
* Specifically, the inputs listed in `action.yml` should be set as environment | ||
* variables following the pattern `INPUT_<INPUT_NAME>`. | ||
*/ | ||
|
||
import * as core from '@actions/core' | ||
import * as main from '../src/main' | ||
|
||
// Mock the action's main function | ||
const runMock = jest.spyOn(main, 'run') | ||
|
||
// Other utilities | ||
const timeRegex = /^\d{2}:\d{2}:\d{2}/ | ||
|
||
// Mock the GitHub Actions core library | ||
let debugMock: jest.SpiedFunction<typeof core.debug> | ||
let errorMock: jest.SpiedFunction<typeof core.error> | ||
let getInputMock: jest.SpiedFunction<typeof core.getInput> | ||
let setFailedMock: jest.SpiedFunction<typeof core.setFailed> | ||
let setOutputMock: jest.SpiedFunction<typeof core.setOutput> | ||
|
||
describe('action', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
|
||
debugMock = jest.spyOn(core, 'debug').mockImplementation() | ||
errorMock = jest.spyOn(core, 'error').mockImplementation() | ||
getInputMock = jest.spyOn(core, 'getInput').mockImplementation() | ||
setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation() | ||
setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation() | ||
}) | ||
|
||
it('sets the time output', async () => { | ||
// Set the action's inputs as return values from core.getInput() | ||
getInputMock.mockImplementation(name => { | ||
switch (name) { | ||
case 'milliseconds': | ||
return '500' | ||
default: | ||
return '' | ||
import { config } from 'dotenv' | ||
|
||
import { generateReport } from '../src/main' | ||
|
||
describe('main.ts', () => { | ||
config() | ||
const token = process.env.GITHUB_TOKEN ?? '' | ||
|
||
it('generateReport', async () => { | ||
Check warning on line 9 in __tests__/main.test.ts GitHub Actions / TypeScript Tests
|
||
const args = { | ||
sonarURL: 'https://sonar.openbsl.ru', | ||
sonarProjectKey: 'yaxunit', | ||
sonarBranchPlugin: true, | ||
mergeID: 367, | ||
githubToken: token, | ||
repo: { | ||
owner: 'alkoleft', | ||
repo: 'yaxunit' | ||
} | ||
}) | ||
|
||
await main.run() | ||
expect(runMock).toHaveReturned() | ||
|
||
// Verify that all of the core library functions were called correctly | ||
expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...') | ||
expect(debugMock).toHaveBeenNthCalledWith( | ||
2, | ||
expect.stringMatching(timeRegex) | ||
) | ||
expect(debugMock).toHaveBeenNthCalledWith( | ||
3, | ||
expect.stringMatching(timeRegex) | ||
) | ||
expect(setOutputMock).toHaveBeenNthCalledWith( | ||
1, | ||
'time', | ||
expect.stringMatching(timeRegex) | ||
) | ||
expect(errorMock).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('sets a failed status', async () => { | ||
// Set the action's inputs as return values from core.getInput() | ||
getInputMock.mockImplementation(name => { | ||
switch (name) { | ||
case 'milliseconds': | ||
return 'this is not a number' | ||
default: | ||
return '' | ||
} | ||
}) | ||
|
||
await main.run() | ||
expect(runMock).toHaveReturned() | ||
|
||
// Verify that all of the core library functions were called correctly | ||
expect(setFailedMock).toHaveBeenNthCalledWith( | ||
1, | ||
'milliseconds not a number' | ||
) | ||
expect(errorMock).not.toHaveBeenCalled() | ||
} | ||
generateReport(args) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { config } from 'dotenv' | ||
|
||
import { Publisher } from '../src/publisher' | ||
import { Sonar } from '../src/sonar' | ||
import { GithubMerge } from '../src/github' | ||
|
||
describe('main.ts', () => { | ||
config() | ||
const token = process.env.GITHUB_TOKEN ?? '' | ||
const repo = { | ||
owner: process.env.GITHUB_OWNER ?? '', | ||
repo: process.env.GITHUB_REPO ?? '' | ||
} | ||
|
||
it('generateReport', async () => { | ||
Check warning on line 15 in __tests__/publisher.test.ts GitHub Actions / TypeScript Tests
|
||
const sonar = new Sonar({ | ||
host: 'https://sonar.openbsl.ru', | ||
projectKey: 'yaxunit', | ||
branchPluginEnabled: true, | ||
pull_number: 370 | ||
}) | ||
const github = new GithubMerge({ | ||
repo: repo, | ||
Check failure on line 23 in __tests__/publisher.test.ts GitHub Actions / TypeScript Tests
|
||
pull_number: 9, | ||
token: token | ||
Check failure on line 25 in __tests__/publisher.test.ts GitHub Actions / TypeScript Tests
|
||
}) | ||
const publisher = new Publisher(sonar, github) | ||
await publisher.generateReport() | ||
}) | ||
it('publishIssues', async () => { | ||
Check warning on line 30 in __tests__/publisher.test.ts GitHub Actions / TypeScript Tests
|
||
const sonar = new Sonar({ | ||
host: 'https://sonar.openbsl.ru', | ||
projectKey: 'yaxunit', | ||
branchPluginEnabled: true, | ||
pull_number: 370 | ||
}) | ||
const github = new GithubMerge({ | ||
repo: repo, | ||
Check failure on line 38 in __tests__/publisher.test.ts GitHub Actions / TypeScript Tests
|
||
pull_number: 370, | ||
token: token | ||
Check failure on line 40 in __tests__/publisher.test.ts GitHub Actions / TypeScript Tests
|
||
}) | ||
const publisher = new Publisher(sonar, github) | ||
const status = { | ||
projectStatus: { | ||
status: 'UNKNOWN', | ||
ignoredConditions: false, | ||
conditions: [] | ||
} | ||
} | ||
publisher.publishIssues(status, [ | ||
newIssue( | ||
'1', | ||
'exts/yaxunit/src/CommonModules/МокитоОбучение/Module.bsl', | ||
3 | ||
), | ||
newIssue( | ||
'2', | ||
'exts/yaxunit/src/CommonModules/МокитоОбучение/Module.bsl', | ||
140 | ||
) | ||
]) | ||
}) | ||
}) | ||
|
||
function newIssue(key: string, path: string, line: number) { | ||
return { | ||
key: key, | ||
project: 'yaxunit', | ||
component: 'yaxunit:' + path, | ||
rule: 'bsl-language-server:Typo', | ||
status: 'OPEN', | ||
message: 'Возможная опечатка в "Обнуружена"', | ||
severity: 'INFO', | ||
line: line, | ||
textRange: { | ||
startLine: line, | ||
endLine: line, | ||
startOffset: 1, | ||
endOffset: 1 | ||
}, | ||
effort: '1min', | ||
tags: [], | ||
type: 'CODE_SMELL' | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { debug } from 'console' | ||
import { config } from 'dotenv' | ||
|
||
import { Sonar } from '../src/sonar' | ||
|
||
describe('sonar', () => { | ||
config() | ||
const token = process.env.GITHUB_TOKEN ?? '' | ||
const sonar = new Sonar({ | ||
host: 'https://sonar.openbsl.ru', | ||
projectKey: 'yaxunit', | ||
tokenKey: '', | ||
branchPluginEnabled: true, | ||
pull_number: 367 | ||
}) | ||
|
||
it('getQualityStatus', async () => { | ||
debug(await sonar.getQualityStatus()) | ||
}) | ||
|
||
it('allIssues', async () => { | ||
debug(await sonar.allIssues()) | ||
}) | ||
}) |
This file was deleted.