From 7a45cee3de6afdf03020a5bc5126b356c340fe77 Mon Sep 17 00:00:00 2001 From: Trym Lund Flogard Date: Sat, 5 Jun 2021 13:09:07 +0200 Subject: [PATCH] add simple integration test --- __tests__/doubles/InputsDouble.ts | 37 ++++++++++++++++ __tests__/fixtures/test-artifact/a.txt | 0 .../fixtures/test-artifact/some-folder/b.txt | 0 __tests__/integration.test.ts | 9 ++++ __tests__/setup.ts | 1 + jest.config.js | 12 +++++ package.json | 15 ++++++- src/Inputs.ts | 44 +++++-------------- 8 files changed, 83 insertions(+), 35 deletions(-) create mode 100644 __tests__/doubles/InputsDouble.ts create mode 100644 __tests__/fixtures/test-artifact/a.txt create mode 100644 __tests__/fixtures/test-artifact/some-folder/b.txt create mode 100644 __tests__/integration.test.ts create mode 100644 __tests__/setup.ts create mode 100644 jest.config.js diff --git a/__tests__/doubles/InputsDouble.ts b/__tests__/doubles/InputsDouble.ts new file mode 100644 index 0000000..5dd6501 --- /dev/null +++ b/__tests__/doubles/InputsDouble.ts @@ -0,0 +1,37 @@ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ +import { Inputs } from '../../src/Inputs' +import { NoFileOption } from '../../src/NoFileOption' + +export class InputsDouble implements Inputs { + get ArtifactName(): string { + return process.env['ARTIFACT_NAME']! + } + + get ArtifactPath(): string { + return process.env['ARTIFACT_PATH']! + } + + get Retention(): string { + return '' + } + + get Endpoint(): string { + return process.env['ENDPOINT']! + } + + get Username(): string { + return process.env['USERNAME']! + } + + get Password(): string { + return process.env['PASSWORD']! + } + + get Token(): string { + return process.env['TOKEN']! + } + + get NoFileBehvaior(): NoFileOption { + return NoFileOption.error + } +} diff --git a/__tests__/fixtures/test-artifact/a.txt b/__tests__/fixtures/test-artifact/a.txt new file mode 100644 index 0000000..e69de29 diff --git a/__tests__/fixtures/test-artifact/some-folder/b.txt b/__tests__/fixtures/test-artifact/some-folder/b.txt new file mode 100644 index 0000000..e69de29 diff --git a/__tests__/integration.test.ts b/__tests__/integration.test.ts new file mode 100644 index 0000000..10fd29d --- /dev/null +++ b/__tests__/integration.test.ts @@ -0,0 +1,9 @@ +import { NextcloudArtifact } from '../src/nextcloud/NextcloudArtifact' +import { InputsDouble } from './doubles/InputsDouble' + +describe('integration tests', () => { + it('works', async () => { + const artifact = new NextcloudArtifact(new InputsDouble()) + await artifact.run() + }) +}) diff --git a/__tests__/setup.ts b/__tests__/setup.ts new file mode 100644 index 0000000..27834af --- /dev/null +++ b/__tests__/setup.ts @@ -0,0 +1 @@ +require("dotenv").config() \ No newline at end of file diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..a170b9a --- /dev/null +++ b/jest.config.js @@ -0,0 +1,12 @@ +module.exports = { + clearMocks: true, + moduleFileExtensions: ['js', 'ts'], + testEnvironment: 'node', + testMatch: ['**/*.test.ts'], + testRunner: 'jest-circus/runner', + transform: { + '^.+\\.ts$': 'ts-jest' + }, + verbose: true, + setupFiles: ["./__tests__/setup.ts"] +} \ No newline at end of file diff --git a/package.json b/package.json index 49c972d..b21d70e 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "format": "prettier --write **/*.ts", "format-check": "prettier --check **/*.ts", "lint": "eslint src/**/*.ts", - "package": "npx ncc build --source-map --license licenses.txt" + "package": "npx ncc build --source-map --license licenses.txt", + "test": "jest --ci" }, "repository": { "type": "git", @@ -37,11 +38,13 @@ "@octokit/webhooks": "^9.6.3", "@types/archiver": "^5.1.0", "@types/btoa": "^1.2.3", + "@types/jest": "^26.0.23", "@types/node": "^15.6.2", "@types/node-fetch": "^2.5.10", "@types/uuid": "^8.3.0", "@typescript-eslint/eslint-plugin": "^4.16.1", "@typescript-eslint/parser": "^4.16.1", + "dotenv": "^10.0.0", "eslint": "^7.21.0", "eslint-plugin-github": "^4.1.3", "eslint-plugin-jest": "^24.1.7", @@ -52,5 +55,15 @@ "prettier": "2.2.1", "ts-jest": "^26.5.3", "typescript": "^4.3.2" + }, + "jest-junit": { + "suiteName": "jest tests", + "outputDirectory": "__tests__/__results__", + "outputName": "jest-junit.xml", + "ancestorSeparator": " › ", + "uniqueOutputName": "false", + "suiteNameTemplate": "{filepath}", + "classNameTemplate": "{classname}", + "titleTemplate": "{title}" } } diff --git a/src/Inputs.ts b/src/Inputs.ts index a2a1a0b..f93da35 100644 --- a/src/Inputs.ts +++ b/src/Inputs.ts @@ -1,43 +1,19 @@ -import * as core from '@actions/core'; -import { NoFileOption } from './NoFileOption'; +import { NoFileOption } from './NoFileOption' -export class Inputs { - static get ArtifactName(): string { - return core.getInput("name"); - } +export interface Inputs { + readonly ArtifactName: string - static get ArtifactPath(): string { - return core.getInput("path"); - } + readonly ArtifactPath: string - static get Retention(): string { - return core.getInput("retention-days"); - } + readonly Retention: string - static get Endpoint(): string { - return core.getInput("nextcloud-url"); - } + readonly Endpoint: string - static get Username(): string { - return core.getInput("nextcloud-username"); - } + readonly Username: string - static get Password(): string { - return core.getInput("nextcloud-password"); - } + readonly Password: string - static get NoFileBehvaior(): NoFileOption { - const notFoundAction = core.getInput("if-no-files-found") || NoFileOption.warn; - const noFileBehavior: NoFileOption = NoFileOption[notFoundAction as keyof typeof NoFileOption]; + readonly Token: string - if (!noFileBehavior) { - core.setFailed( - `Unrecognized ${"ifNoFilesFound"} input. Provided: ${notFoundAction}. Available options: ${Object.keys( - NoFileOption - )}` - ); - } - - return noFileBehavior; - } + readonly NoFileBehvaior: NoFileOption }