Skip to content

Commit

Permalink
fix: vitest cannot mock
Browse files Browse the repository at this point in the history
  • Loading branch information
andykenward committed Jan 14, 2024
1 parent e49cc5f commit 3cc1a5d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
8 changes: 4 additions & 4 deletions __tests__/helpers/env.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {vi} from 'vitest'

import {raise} from '@/src/utils.js'

export const TEST_ENV_VARS: NodeJS.ProcessEnv = {
GITHUB_HEAD_REF: 'mock-github-head-ref',
GITHUB_REF: 'refs/heads/mock-github-ref',
Expand All @@ -17,8 +15,10 @@ export const TEST_ENV_VARS: NodeJS.ProcessEnv = {

export const stubTestEnvVars = () => {
for (const key in TEST_ENV_VARS) {
const value =
TEST_ENV_VARS[key] ?? raise(`Missing TEST_ENV_VARS value for key: ${key}`)
const value = TEST_ENV_VARS[key]
if (!value) {
throw new Error(`Missing TEST_ENV_VARS value for key: ${key}`)
}
vi.stubEnv(key, value)
}
}
2 changes: 1 addition & 1 deletion __tests__/helpers/inputs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {vi} from 'vitest'

import {INPUT_KEYS_REQUIRED} from '@/src/inputs.js'
import {INPUT_KEYS_REQUIRED} from '../../input-keys.js'

const INPUT_KEY = `INPUT_`

Expand Down
16 changes: 16 additions & 0 deletions input-keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const INPUT_KEY_CLOUDFLARE_ACCOUNT_ID = 'cloudflare-account-id' as const
export const INPUT_KEY_CLOUDFLARE_API_TOKEN = 'cloudflare-api-token' as const
export const INPUT_KEY_CLOUDFLARE_PROJECT_NAME =
'cloudflare-project-name' as const
export const INPUT_KEY_DIRECTORY = 'directory' as const
export const INPUT_KEY_GITHUB_ENVIRONMENT = 'github-environment' as const
export const INPUT_KEY_GITHUB_TOKEN = 'github-token' as const

export const INPUT_KEYS_REQUIRED = [
INPUT_KEY_CLOUDFLARE_ACCOUNT_ID,
INPUT_KEY_CLOUDFLARE_API_TOKEN,
INPUT_KEY_CLOUDFLARE_PROJECT_NAME,
INPUT_KEY_DIRECTORY,
INPUT_KEY_GITHUB_ENVIRONMENT,
INPUT_KEY_GITHUB_TOKEN
] as const
11 changes: 2 additions & 9 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@ import type {InputOptions} from '@unlike/github-actions-core'

import {getInput} from '@unlike/github-actions-core'

const INPUT_KEY_CLOUDFLARE_ACCOUNT_ID = 'cloudflare-account-id'
const INPUT_KEY_CLOUDFLARE_API_TOKEN = 'cloudflare-api-token'
const INPUT_KEY_CLOUDFLARE_PROJECT_NAME = 'cloudflare-project-name'
const INPUT_KEY_DIRECTORY = 'directory'
const INPUT_KEY_GITHUB_ENVIRONMENT = 'github-environment'
const INPUT_KEY_GITHUB_TOKEN = 'github-token'

export const INPUT_KEYS_REQUIRED = [
import {
INPUT_KEY_CLOUDFLARE_ACCOUNT_ID,
INPUT_KEY_CLOUDFLARE_API_TOKEN,
INPUT_KEY_CLOUDFLARE_PROJECT_NAME,
INPUT_KEY_DIRECTORY,
INPUT_KEY_GITHUB_ENVIRONMENT,
INPUT_KEY_GITHUB_TOKEN
] as const
} from '../input-keys.js'

const OPTIONS: InputOptions = {
required: true
Expand Down

0 comments on commit 3cc1a5d

Please sign in to comment.