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

Unit Test Workflow #3

Merged
merged 7 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
57 changes: 51 additions & 6 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,61 @@ module.exports = {
es2021: true,
node: true
},
extends: 'eslint:recommended',
extends: ['eslint:recommended', 'prettier'],
parserOptions: {
ecmaVersion: 12,
sourceType: 'module'
},
ignorePatterns: ["wrappedHandler.js", "handlerCloud.js", "handlerOnPrem.js"],
ignorePatterns: ['wrappedHandler.js', 'handlerCloud.js', 'handlerOnPrem.js'],
rules: {
indent: ['error', 4, { SwitchCase: 1, offsetTernaryExpressions: false }],
'linebreak-style': 'off',
quotes: ['error', 'single'],
semi: ['error', 'always']
'jsx-quotes': ['error', 'prefer-single'],
semi: ['error', 'always'],
'default-case': 'error',
quotes: ['error', 'single', { avoidEscape: true }],
curly: 'error',
eqeqeq: ['error', 'always', { null: 'ignore' }],
'guard-for-in': 'error',
'no-alert': 'error',
'no-caller': 'error',
'no-empty-function': 'error',
'no-eval': 'error',
'no-extend-native': 'error',
'no-extra-bind': 'error',
'no-implicit-coercion': 'error',
'no-implicit-globals': 'error',
'no-implied-eval': 'error',
'no-iterator': 'error',
'no-labels': 'error',
'no-lone-blocks': 'error',
'no-loop-func': 'warn',
'no-multi-spaces': 'warn',
'no-return-assign': 'error',
'no-return-await': 'warn',
'no-self-compare': 'warn',
'no-sequences': 'error',
'no-throw-literal': 'warn',
'no-unused-vars': ['error', { ignoreRestSiblings: true }],
'no-useless-call': 'warn',
'no-useless-concat': 'warn',
'no-useless-return': 'warn',
'require-unicode-regexp': 'warn',
'vars-on-top': 'error',
'no-shadow': 'warn',
'brace-style': 'warn',
camelcase: 'error',
'comma-dangle': ['error', 'never'],
'max-len': [
'warn',
{
code: 120,
tabWidth: 4,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreTrailingComments: true,
ignoreRegExpLiterals: true
}
],
'no-debugger': 'warn',
'no-duplicate-imports': 'warn'
}
};
21 changes: 21 additions & 0 deletions .github/workflows/test-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Test Report'
on:
workflow_run:
workflows: ['Unit Test']
types:
- completed
permissions:
contents: read
actions: read
checks: write

jobs:
report:
runs-on: ubuntu-latest
steps:
- uses: dorny/test-reporter@v1
with:
artifact: test-results
name: JEST Tests
path: '*.xml'
reporter: jest-junit
79 changes: 79 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Unit Test

on:
push:
branches:
- '*'
workflow_dispatch:

jobs:
unit-test:
runs-on: ubuntu-latest

steps:
- name: Self Checkout
uses: actions/checkout@v2
with:
path: 'squaredup-plugin-public'

- name: Checkout Plugins Repository
uses: actions/checkout@v2
with:
repository: 'squaredup/squaredup-plugin-repository'
path: 'squaredup-plugin-repository'
ref: 'main'
token: ${{ secrets.PLUGINS_REPO_TOKEN }}

- name: Setup NodeJs20.x
uses: actions/setup-node@v2
with:
node-version: '20.x'

- name: Install Dependencies
run: npm ci
working-directory: squaredup-plugin-public
timeout-minutes: 5

- name: Install Main Plugins Dependencies
run: npm ci
working-directory: squaredup-plugin-repository
timeout-minutes: 5

- name: Run Unit Tests
run: |
$pattern = '(?<=\/[v][0-9]\/).*'
$changes = git diff --name-only origin/main... ./plugins
$pluginsToTest = $changes -replace $pattern | Sort-Object -Unique

Set-Location "..\squaredup-plugin-repository"
if ( $null -eq $pluginsToTest ) {
Write-Output "Nothing to Test as no changes were found in plugins folder..."
exit 0
}
elseif ( $pluginsToTest.Count -eq 1 ) {
$pluginName = ($pluginsToTest.TrimEnd('/')) -replace "plugins/" -replace "/", "-"
Write-Output "Only Testing $pluginsToTest"
npm test -- --ci --path="../squaredup-plugin-public/$pluginsToTest" --pluginName="$pluginName"
Write-Output "Tested $pluginsToTest"
}
else {
Write-Output "Testing $($pluginsToTest.Count) Plugins..."
foreach ( $plugin in $pluginsToTest ) {
Write-Output "Testing $plugin"
$pluginName = ($plugin.TrimEnd('/')) -replace "plugins/" -replace "/", "-"
npm test -- --ci --path="../squaredup-plugin-public/$plugin" --pluginName="$pluginName"
Write-Output "Tested $plugin"
}
}
working-directory: squaredup-plugin-public
shell: pwsh
timeout-minutes: 10

- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v2
with:
name: test-results
path: |
squaredup-plugin-repository/pluginUnitTests/test_output/*.xml
squaredup-plugin-repository/pluginUnitTests/test_output/html/*.html
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/node_modules
package*.json
8 changes: 8 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"jsxSingleQuote": true,
"printWidth": 120,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "none",
"endOfLine": "auto"
}
11 changes: 11 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"streetsidesoftware.code-spell-checker"
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"prettier.configPath": ".prettierrc.json",
"prettier.ignorePath": ".prettierignore",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"prettier.requireConfig": true,
"eslint.workingDirectories": [{ "directory": "." }],
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
15 changes: 15 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
{
"version": "0.2",
"language": "en,en-US",
"ignorePaths": [
"**/node_modules/**",
"**/.git/**",
".vscode",
"package-lock.json"
],
"allowCompoundWords": true,
"dictionaries": [
"en_US",
"en-gb",
"softwareTerms",
"node",
"npm"
],
"words": [
"Analyse",
"datacenter",
Expand Down
50 changes: 46 additions & 4 deletions package-lock.json

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

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"description": "This repository contains third-party/community plugins for the SquaredUp Cloud product.",
"type": "module",
"scripts": {
"lint": "eslint .",
"validate": "node validate"
},
"repository": {
Expand Down Expand Up @@ -37,6 +38,8 @@
"title-case": "^3.0.3"
},
"devDependencies": {
"eslint": "^7.32.0"
"eslint": "^7.32.0",
"eslint-config-prettier": "^9.1.0",
"prettier": "^3.2.5"
}
}