Skip to content

Commit

Permalink
Prevent @actions/core from writting to files
Browse files Browse the repository at this point in the history
An implementation detail, but since the unittests cover multiple
platforms the action trying to write to a file will fail since the
path to the file is in the hosts format.

Signed-off-by: Andrei Horodniceanu <[email protected]>
  • Loading branch information
the-horo committed Jul 12, 2024
1 parent 2e80267 commit 4d45c00
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions __tests__/d-compiler.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Compiler } from '../src/d'
import fs from 'fs'
import * as testUtils from './test-helpers.test'

testUtils.disableGithubPaths()

describe('Test Compiler class', () => {
const logSpy = jest.spyOn(console, 'log').mockReturnValue(undefined)
Expand Down
1 change: 1 addition & 0 deletions __tests__/d-dmd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import fs from 'fs'
testUtils.hideConsoleLogs()
testUtils.saveProcessRestorePoint()
testUtils.disableNetwork()
testUtils.disableGithubPaths()
function init(version: string) { return DMD.initialize(version, '') }

describe('amd64', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/d-gdc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as tc from '@actions/tool-cache'

testUtils.saveProcessRestorePoint()
testUtils.hideConsoleLogs()
testUtils.disableGithubPaths()
const origEnv = process.env
beforeEach(() => {
process.env = origEnv
Expand Down
1 change: 1 addition & 0 deletions __tests__/d-ldc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import fs from 'fs'

testUtils.saveProcessRestorePoint()
testUtils.disableNetwork()
testUtils.disableGithubPaths()
testUtils.hideConsoleLogs()

async function doTest(input: string, url: string, sig: string | undefined,
Expand Down
7 changes: 7 additions & 0 deletions __tests__/test-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as utils from '../src/utils'
import * as coreInternals from '@actions/core/lib/file-command'

export function mockTags (expectedUrl: string | RegExp, pages: string[][]) {
async function mocker (url: string, token: string,
Expand Down Expand Up @@ -56,3 +57,9 @@ export function hideConsoleLogs () {
beforeEach(() => jest.spyOn(console, 'log').mockReturnValue(undefined))
beforeEach(() => jest.spyOn(process.stdout, 'write').mockReturnValue(true))
}

export function disableGithubPaths () {
beforeAll(() => {
jest.spyOn(coreInternals, 'issueFileCommand').mockReturnValue(undefined)
})
}

0 comments on commit 4d45c00

Please sign in to comment.