Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup for L0 Testcases #6

Merged
merged 9 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
on:
pull_request:
push:
branches:
- master
- 'releases/*'

jobs:
build_test_job:
name: 'Build and test job'
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
steps:

- name: 'Checking out repo code'
uses: actions/checkout@v1

- name: 'Validate build'
run: |
npm install
npm build
- name: 'Run L0 tests'
run: |
npm run test
- name : 'Run test coverage'
if: runner.os == 'Windows'
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$coverage_result = npm run test-coverage
$start = $false;
$middle = $false;
$end = $false;
$count = 0;

foreach ($j in $coverage_result)
{
if ($j.tostring().startswith("----------"))
{
if (!$start)
{
$start = $true;
$start_index = $count
}
elseif (!$middle)
{
$middle = $true;
}
elseif (!$end)
{
$end = $true;
$end_index = $count
}
}
$count++
}

$tbl_md = $coverage_result[($start_index+1)..($end_index-1)] -join "\n"
$summary = $coverage_result[($end_index + 1)..$count] -join "\n"
$comment = $tbl_md + "\n" + $summary
$url = "https://api.github.com/repos/${env:GITHUB_REPOSITORY}/issues/${env:PR_NUMBER}/comments"
$headers = @{
"Authorization" = "token ${env:GITHUB_TOKEN}"
}
Invoke-RestMethod -Method POST -Uri $url -Headers $headers -Body "{ `"body`": `"${comment}`" }"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as Azure/k8s-set-context#8

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,4 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/
node_modules
7 changes: 7 additions & 0 deletions __tests__/run.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {run} from '../src/run'

describe('This is a placeholder for intial test cases, to be removed', () => {
test('Dummy test case', async () => {
await expect(run()).rejects.toThrow();
})
})
18 changes: 18 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true,
coverageThreshold: {
"global": {
"branches": 0,
"functions": 14,
"lines": 27,
"statements": 27
}
}
}
2 changes: 2 additions & 0 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = void 0;
const os = require("os");
const path = require("path");
const util = require("util");
Expand Down Expand Up @@ -80,4 +81,5 @@ function run() {
core.setOutput('kubectl-path', cachedPath);
});
}
exports.run = run;
run().catch(core.setFailed);
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"private": true,
"main": "lib/run.js",
"scripts": {
"build": "tsc --outDir .\\lib\\ --rootDir .\\src\\"
"build": "tsc --outDir .\\lib\\ --rootDir .\\src\\",
"test": "jest",
"test-coverage": "jest --coverage"
},
"keywords": [
"actions",
Expand All @@ -19,6 +21,10 @@
"@actions/tool-cache": "^1.0.0"
},
"devDependencies": {
"@types/node": "^12.0.4"
"@types/node": "^12.0.4",
"jest": "^26.0.1",
"@types/jest": "^25.2.2",
"ts-jest": "^25.5.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ts-jest isn't being used yet right?

"typescript": "3.9.2"
}
}
2 changes: 1 addition & 1 deletion src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function downloadKubectl(version: string): Promise<string> {
return kubectlPath;
}

async function run() {
export async function run() {
let version = core.getInput('version', { 'required': true });
if (version.toLocaleLowerCase() === 'latest') {
version = await getStableKubectlVersion();
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"module": "commonjs"
},
"exclude": [
"node_modules"
"node_modules",
"__tests__"
]
}