add simple integration test

This commit is contained in:
Trym Lund Flogard 2021-06-05 13:09:07 +02:00
parent 518c6f09f4
commit 7a45cee3de
8 changed files with 83 additions and 35 deletions

View File

@ -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
}
}

View File

View File

@ -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()
})
})

1
__tests__/setup.ts Normal file
View File

@ -0,0 +1 @@
require("dotenv").config()

12
jest.config.js Normal file
View File

@ -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"]
}

View File

@ -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}"
}
}

View File

@ -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
}