From 93ff0f7ef2c33689d3df35332746b1d2cfdcb843 Mon Sep 17 00:00:00 2001 From: Edmund Miller Date: Sun, 13 Nov 2022 20:05:23 -0600 Subject: [PATCH] test: Write tests for release_data function --- package.json | 4 ++++ test/functions.ts | 19 +------------------ test/releasedata.ts | 23 +++++++++++++++++++++++ test/utils.ts | 12 ++++++++++++ 4 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 test/releasedata.ts create mode 100644 test/utils.ts diff --git a/package.json b/package.json index cc67162..0492511 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,10 @@ "source": [ "src/**/*.ts" ], + "files": [ + "test/**/*.ts", + "!test/utils.ts" + ], "concurrency": 1, "serial": true, "powerAssert": true diff --git a/test/functions.ts b/test/functions.ts index 1704833..ab547b9 100644 --- a/test/functions.ts +++ b/test/functions.ts @@ -1,4 +1,5 @@ import * as functions from '../src/functions' +import {getToken} from './utils' import * as github from '@actions/github' import anyTest, {TestFn} from 'ava' // eslint-disable-line import/no-unresolved @@ -24,23 +25,5 @@ test('lastest_stable_release_data', async t => { t.is(result['tag_name'], 'v22.10.2') }) -test('release_data', async t => { - const result = await functions.release_data('v22.10.2', t.context['octokit']) - t.is(result['tag_name'], 'v22.10.2') -}) - test.todo('nextflow_bin_url') test.todo('install_nextflow') - -function getToken(first: boolean): string { - const token = process.env['GITHUB_TOKEN'] || '' - if (!token && first) { - /* eslint-disable-next-line no-console */ - console.warn( - 'Skipping GitHub tests. Set $GITHUB_TOKEN to run REST client and GraphQL client tests' - ) - first = false - } - - return token -} diff --git a/test/releasedata.ts b/test/releasedata.ts new file mode 100644 index 0000000..7bbbff5 --- /dev/null +++ b/test/releasedata.ts @@ -0,0 +1,23 @@ +import * as github from '@actions/github' +import {release_data} from '../src/functions' +import {getToken} from './utils' +import anyTest, {TestFn} from 'ava' // eslint-disable-line import/no-unresolved + +const test = anyTest as TestFn<{foo: string}> + +test.before(t => { + const first = true + const current_token = getToken(first) + t.context = {token: current_token} + t.context = {octokit: github.getOctokit(current_token)} +}) + +const macro = test.macro(async (t, version: string, expected: string) => { + const result = await release_data(version, t.context['octokit']) + t.is(result['tag_name'], expected) +}) + +test('hard version', macro, 'v22.10.2', 'v22.10.2') +test('latest-stable', macro, 'latest-stable', 'v22.10.2') +test('latest-edge', macro, 'latest-edge', 'v22.09.7-edge') +test('latest-everything', macro, 'latest-everything', 'v22.10.2') diff --git a/test/utils.ts b/test/utils.ts new file mode 100644 index 0000000..994aa41 --- /dev/null +++ b/test/utils.ts @@ -0,0 +1,12 @@ +export function getToken(first: boolean): string { + const token = process.env['GITHUB_TOKEN'] || '' + if (!token && first) { + /* eslint-disable-next-line no-console */ + console.warn( + 'Skipping GitHub tests. Set $GITHUB_TOKEN to run REST client and GraphQL client tests' + ) + first = false + } + + return token +}