From 3c3e08e8415fc64a0213b42ba710c02e7170c6e5 Mon Sep 17 00:00:00 2001 From: cwanjau Date: Wed, 24 Apr 2024 20:23:23 +0300 Subject: [PATCH] run tests on creating a Pull request --- .eslintrc.json | 13 +++++++++++-- .github/workflows/pullRequest.yml | 32 +++++++++++++++++++++++++++++++ package.json | 2 +- src/input.ts | 14 +++++++------- tests/configfile.test.ts | 10 +++++----- 5 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/pullRequest.yml diff --git a/.eslintrc.json b/.eslintrc.json index 802134a..882ae61 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -29,13 +29,22 @@ "spaced-comment": ["error", "always", { "markers": ["/"] }], "space-infix-ops": ["error"], "use-isnan": "error", - "@typescript-eslint/class-name-casing": "error", "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/explicit-function-return-type": [ "warn", { "allowExpressions": true, "allowTypedFunctionExpressions": true } ], - "@typescript-eslint/interface-name-prefix": ["error", "never"], + "@typescript-eslint/naming-convention": [ + "error", + { + "selector": "interface", + "format": ["PascalCase"] + }, + { + "selector": "class", + "format": ["PascalCase"] + } + ], "@typescript-eslint/no-unused-vars": "warn", "@typescript-eslint/no-useless-constructor": "error", "@typescript-eslint/no-use-before-define": "off", diff --git a/.github/workflows/pullRequest.yml b/.github/workflows/pullRequest.yml new file mode 100644 index 0000000..cacbdac --- /dev/null +++ b/.github/workflows/pullRequest.yml @@ -0,0 +1,32 @@ +name: PullRequest +on: + pull_request: + branches: + - main + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up node + uses: actions/setup-node@v2 + with: + node-version: '20' + + - name: Install dependencies + run: | + npm i -g @vercel/ncc + npm install + + - name: Compile files + run: npm run build + + - name: Run tests + run: npm run test + + - name: Check linting errors + run: npm run lint diff --git a/package.json b/package.json index 9ee4818..3928d24 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "syncConfig", "private": true, "scripts": { - "build": "ncc build src\\main.ts -m -o lib", + "build": "ncc build src/main.ts -m -o lib", "lint": "eslint src/**/*.ts", "lint:fix": "eslint src/**/*.ts --fix", "test": "jest" diff --git a/src/input.ts b/src/input.ts index 88d723f..e563c6e 100644 --- a/src/input.ts +++ b/src/input.ts @@ -3,6 +3,13 @@ import * as core from '@actions/core'; import { ConfigFormat } from './configfile'; import { ArgumentError } from './errors'; +/** + * Represents the tags that apply to a setting + */ +export interface Tags { + [propertyName: string]: string; +} + /** * Represents the inputs to the GitHub action */ @@ -20,13 +27,6 @@ export interface Input { contentType?: string; } -/** - * Represents the tags that apply to a setting - */ -export interface Tags { - [propertyName: string]: string; -} - /** * Obtain the action inputs from the GitHub environment */ diff --git a/tests/configfile.test.ts b/tests/configfile.test.ts index e09b9a1..675d028 100644 --- a/tests/configfile.test.ts +++ b/tests/configfile.test.ts @@ -9,13 +9,13 @@ describe('loadConfigFiles', () => { it('throw when no config files are found', async () => { const promise = configfile.loadConfigFiles(__dirname, "missing.json", configfile.ConfigFormat.JSON, "."); - await (expect(promise)).rejects.toThrowError(ArgumentError); + await (expect(promise)).rejects.toThrow(ArgumentError); }) it('throw when config format is invalid', async () => { const promise = configfile.loadConfigFiles(__dirname, "appsettings.json", -1 as configfile.ConfigFormat, "."); - await (expect(promise)).rejects.toThrowError(ParseError); + await (expect(promise)).rejects.toThrow(ParseError); }) it('loads JSON with separator .', async () => { @@ -43,7 +43,7 @@ describe('loadConfigFiles', () => { it('throw when JSON is invalid', async () => { const promise = configfile.loadConfigFiles(__dirname, "invalid.json", configfile.ConfigFormat.JSON, "."); - await (expect(promise)).rejects.toThrowError(ParseError); + await (expect(promise)).rejects.toThrow(ParseError); }) it('loads YAML', async () => { @@ -62,9 +62,9 @@ describe('loadConfigFiles', () => { }) it('throw when YAML is invalid', async () => { - const promise = configfile.loadConfigFiles(__dirname, "invalid.YAML", configfile.ConfigFormat.YAML, "."); + const promise = configfile.loadConfigFiles(__dirname, "invalid.yaml", configfile.ConfigFormat.YAML, "."); - await (expect(promise)).rejects.toThrowError(ParseError); + await (expect(promise)).rejects.toThrow(ParseError); }) it('loads .properties', async () => {