Skip to content

Commit

Permalink
Migration to typescript (Madrapps#61)
Browse files Browse the repository at this point in the history
* Adding package.json value

* Simply converting all JS to TS

* Main should be JS

* Fix issue in index.ts

* Print something in action()

* Trying a different import

* More logs

* More logs

* More logs

* Fixing the util.test.ts

* Migrating all tests to TS with the @ts-nocheck annotation

* Fix all issues in util.ts expect return types

* Fix all issues in util.ts

* Fix all issues in render.ts

* Fix all issues in process.ts

* Fix some issues in action.ts

* Fixing all issues in action.ts

* Fixing all prettier issues

* Fixing all errors

* Changed from 1.6.1

* Changed from 1.6.1 - Build

* Building
  • Loading branch information
thsaravana authored Aug 3, 2023
1 parent db72e7e commit 468b095
Show file tree
Hide file tree
Showing 47 changed files with 8,528 additions and 2,082 deletions.
6 changes: 5 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
dist/index.js
dist/
node_modules/
jest.config.js
lib/
coverage/
24 changes: 0 additions & 24 deletions .eslintrc.js

This file was deleted.

64 changes: 64 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"plugins": ["jest", "@typescript-eslint"],
"extends": ["plugin:github/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"i18n-text/no-en": "off",
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": [
"error",
{"accessibility": "no-public"}
],
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-comment": "error",
"camelcase": "off",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/explicit-function-return-type": [
"error",
{"allowExpressions": true}
],
"filenames/match-regex": "off",
"@typescript-eslint/func-call-spacing": ["error", "never"],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
},
"env": {
"node": true,
"es6": true,
"jest/globals": true,
"jasmine": true,
"jest": true
}
}
5 changes: 4 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
dist/index.js
dist/
node_modules/
lib/
coverage/
12 changes: 0 additions & 12 deletions .prettierrc.js

This file was deleted.

10 changes: 10 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": false,
"arrowParens": "avoid"
}
27 changes: 17 additions & 10 deletions __tests__/action.test.js → __tests__/action.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const action = require('../src/action')
const core = require('@actions/core')
const github = require('@actions/github')
import * as action from '../src/action'
import * as core from '@actions/core'
import * as github from '@actions/github'

jest.mock('@actions/core')
jest.mock('@actions/github')

describe('Input validation', function () {
function getInput(key) {
function getInput(key: string): string | undefined {
switch (key) {
case 'paths':
return './__tests__/__fixtures__/report.xml'
Expand All @@ -19,7 +19,10 @@ describe('Input validation', function () {
const listComments = jest.fn()
const updateComment = jest.fn()

/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-ignore
core.getInput = jest.fn(getInput)
// @ts-ignore
github.getOctokit = jest.fn(() => {
return {
repos: {
Expand Down Expand Up @@ -50,12 +53,14 @@ describe('Input validation', function () {
},
}
})
core.setFailed = jest.fn((c) => {
// @ts-ignore
core.setFailed = jest.fn(c => {
fail(c)
})

it('Fail if paths is not present', async () => {
core.getInput = jest.fn((c) => {
// @ts-ignore
core.getInput = jest.fn(c => {
switch (c) {
case 'paths':
return ''
Expand All @@ -65,14 +70,16 @@ describe('Input validation', function () {
})
github.context.eventName = 'pull_request'

core.setFailed = jest.fn((c) => {
// @ts-ignore
core.setFailed = jest.fn(c => {
expect(c).toEqual("'paths' is missing")
})
await action.action()
})

it('Fail if token is not present', async () => {
core.getInput = jest.fn((c) => {
// @ts-ignore
core.getInput = jest.fn(c => {
switch (c) {
case 'token':
return ''
Expand All @@ -81,8 +88,8 @@ describe('Input validation', function () {
}
})
github.context.eventName = 'pull_request'

core.setFailed = jest.fn((c) => {
// @ts-ignore
core.setFailed = jest.fn(c => {
expect(c).toEqual("'token' is missing")
})
await action.action()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable no-template-curly-in-string */
const action = require('../src/action')
const core = require('@actions/core')
const github = require('@actions/github')
const { PATCH } = require('./mocks.test')
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-nocheck
import * as action from '../src/action'
import * as core from '@actions/core'
import * as github from '@actions/github'
import {PATCH} from './mocks.test'

jest.mock('@actions/core')
jest.mock('@actions/github')
Expand All @@ -13,7 +14,7 @@ describe('Aggregate report', function () {
let updateComment
let output

function getInput(key) {
function getInput(key: string): string {
switch (key) {
case 'paths':
return './__tests__/__fixtures__/aggregate-report.xml'
Expand All @@ -39,6 +40,7 @@ describe('Aggregate report', function () {
output = jest.fn()

core.getInput = jest.fn(getInput)
// @ts-ignore
github.getOctokit = jest.fn(() => {
return {
rest: {
Expand All @@ -55,7 +57,8 @@ describe('Aggregate report', function () {
},
}
})
core.setFailed = jest.fn((c) => {
// @ts-ignore
core.setFailed = jest.fn(c => {
fail(c)
})
})
Expand Down Expand Up @@ -123,7 +126,7 @@ describe('Aggregate report', function () {
it('updates a previous comment', async () => {
initContext(eventName, payload)
const title = 'JaCoCo Report'
core.getInput = jest.fn((c) => {
core.getInput = jest.fn(c => {
switch (c) {
case 'title':
return title
Expand All @@ -136,8 +139,8 @@ describe('Aggregate report', function () {

listComments.mockReturnValue({
data: [
{ id: 1, body: 'some comment' },
{ id: 2, body: `### ${title}\n to update` },
{id: 1, body: 'some comment'},
{id: 2, body: `### ${title}\n to update`},
],
})

Expand Down Expand Up @@ -169,7 +172,7 @@ describe('Aggregate report', function () {
})
})

function initContext(eventName, payload) {
function initContext(eventName, payload): void {
const context = github.context
context.eventName = eventName
context.payload = payload
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable no-template-curly-in-string */
const action = require('../src/action')
const core = require('@actions/core')
const github = require('@actions/github')
const { PATCH } = require('./mocks.test')
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-nocheck
import * as action from '../src/action'
import * as core from '@actions/core'
import * as github from '@actions/github'
import {PATCH} from './mocks.test'

jest.mock('@actions/core')
jest.mock('@actions/github')
Expand Down Expand Up @@ -50,7 +51,7 @@ describe('Multiple reports', function () {
},
}

core.getInput = jest.fn((c) => {
core.getInput = jest.fn(c => {
switch (c) {
case 'paths':
return './__tests__/__fixtures__/multi_module/appCoverage.xml,./__tests__/__fixtures__/multi_module/mathCoverage.xml,./__tests__/__fixtures__/multi_module/textCoverage.xml'
Expand Down Expand Up @@ -82,7 +83,7 @@ describe('Multiple reports', function () {
},
}
})
core.setFailed = jest.fn((c) => {
core.setFailed = jest.fn(c => {
fail(c)
})

Expand Down Expand Up @@ -179,7 +180,7 @@ describe('Multiple reports', function () {
})
})

function initContext(eventName, payload) {
function initContext(eventName, payload): void {
const context = github.context
context.eventName = eventName
context.payload = payload
Expand Down
Loading

0 comments on commit 468b095

Please sign in to comment.