Skip to content

Commit

Permalink
Adds token info
Browse files Browse the repository at this point in the history
  • Loading branch information
francostramana committed Jan 23, 2024
1 parent 9cfe36e commit dec3f4a
Show file tree
Hide file tree
Showing 14 changed files with 285 additions and 135 deletions.
3 changes: 2 additions & 1 deletion .github/linters/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ rules:
'no-unused-vars': 'off',
'prettier/prettier': 'error',
'semi': 'off',
'no-shadow': 'warn',
'@typescript-eslint/array-type': 'error',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/ban-ts-comment': 'error',
Expand Down Expand Up @@ -76,7 +77,7 @@ rules:
'@typescript-eslint/promise-function-async': 'error',
'@typescript-eslint/require-array-sort-compare': 'error',
'@typescript-eslint/restrict-plus-operands': 'error',
'@typescript-eslint/semi': ['error', 'never'],
'@typescript-eslint/semi': ['error', 'always'],
'@typescript-eslint/space-before-function-paren': 'off',
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/unbound-method': 'error'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:

permissions:
contents: read
pull-requests: write
checks: write

jobs:
test-action:
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"semi": true,
"singleQuote": true,
"quoteProps": "as-needed",
"jsxSingleQuote": false,
Expand Down
12 changes: 6 additions & 6 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
* Unit tests for the action's entrypoint, src/index.ts
*/

import * as main from '../src/main'
import * as main from '../src/main';

// Mock the action's entrypoint
const runMock = jest.spyOn(main, 'run').mockImplementation()
const runMock = jest.spyOn(main, 'run').mockImplementation();

describe('index', () => {
it('calls run when imported', async () => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('../src/index')
require('../src/index');

expect(runMock).toHaveBeenCalled()
})
})
expect(runMock).toHaveBeenCalled();
});
});
72 changes: 36 additions & 36 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,71 +6,71 @@
* variables following the pattern `INPUT_<INPUT_NAME>`.
*/

import * as core from '@actions/core'
import * as main from '../src/main'
import * as core from '@actions/core';
import * as main from '../src/main';

// Mock the action's main function
const runMock = jest.spyOn(main, 'run')
const runMock = jest.spyOn(main, 'run');

// Other utilities
const timeRegex = /^\d{2}:\d{2}:\d{2}/
const timeRegex = /^\d{2}:\d{2}:\d{2}/;

// Mock the GitHub Actions core library
let debugMock: jest.SpyInstance
let errorMock: jest.SpyInstance
let getInputMock: jest.SpyInstance
let setFailedMock: jest.SpyInstance
let setOutputMock: jest.SpyInstance
let debugMock: jest.SpyInstance;
let errorMock: jest.SpyInstance;
let getInputMock: jest.SpyInstance;
let setFailedMock: jest.SpyInstance;
let setOutputMock: jest.SpyInstance;

describe('action', () => {
beforeEach(() => {
jest.clearAllMocks()
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()
})
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: string): string => {
switch (name) {
case 'milliseconds':
return '500'
return '500';
default:
return ''
return '';
}
})
});

await main.run()
expect(runMock).toHaveReturned()
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()
})
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: string): string => {
switch (name) {
case 'milliseconds':
return 'this is not a number'
return 'this is not a number';
default:
return ''
return '';
}
})
});

await main.run()
expect(runMock).toHaveReturned()
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()
})
})
expect(setFailedMock).toHaveBeenNthCalledWith(1, 'milliseconds not a number');
expect(errorMock).not.toHaveBeenCalled();
});
});
107 changes: 101 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/app.config.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const CHECK_NAME = 'SCANOSS Policy Checker'
export const CHECK_NAME = 'SCANOSS Policy Checker';
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* The entrypoint for the action.
*/
import { run } from './main'
import { run } from './main';

// eslint-disable-next-line @typescript-eslint/no-floating-promises
run()
run();
55 changes: 0 additions & 55 deletions src/libs/github-check.ts

This file was deleted.

Loading

0 comments on commit dec3f4a

Please sign in to comment.