@@ -4,7 +4,7 @@ import sinon from "sinon";
44import { ActionsEnvVars } from "../environment" ;
55import * as errors from "../error-messages" ;
66import { Feature } from "../feature-flags" ;
7- import { callee , getTestEnv } from "../testing-utils" ;
7+ import { callee } from "../testing-utils" ;
88import { ConfigurationError } from "../util" ;
99
1010import {
@@ -88,16 +88,13 @@ test("parseRemoteFileAddress accepts full remote addresses", async (t) => {
8888} ) ;
8989
9090test ( "parseRemoteFileAddress accepts remote address without an owner" , async ( t ) => {
91- const target = callee ( parseRemoteFileAddress ) ;
92-
93- const env = target . getState ( ) . env ;
9491 const owner = "test-owner" ;
95- const getRequired = sinon . stub ( env , "getRequired" ) ;
96- getRequired
97- . withArgs ( ActionsEnvVars . GITHUB_REPOSITORY )
98- . returns ( ` ${ owner } /current-repo` ) ;
99-
100- const targetWithEnv = target . withEnv ( env ) ;
92+ const target = callee ( parseRemoteFileAddress ) . withEnv ( ( env ) => {
93+ const getRequired = sinon . stub ( env , "getRequired" ) ;
94+ getRequired
95+ . withArgs ( ActionsEnvVars . GITHUB_REPOSITORY )
96+ . returns ( ` ${ owner } /current-repo` ) ;
97+ } ) ;
10198
10299 const testCases : ParseRemoteFileAddressTest [ ] = [
103100 {
@@ -139,7 +136,7 @@ test("parseRemoteFileAddress accepts remote address without an owner", async (t)
139136 ] ;
140137
141138 for ( const testCase of testCases ) {
142- const targetWithArgs = targetWithEnv . withArgs ( testCase . input ) ;
139+ const targetWithArgs = target . withArgs ( testCase . input ) ;
143140
144141 // Should fail when the FF is not enabled.
145142 await targetWithArgs
@@ -154,14 +151,16 @@ test("parseRemoteFileAddress accepts remote address without an owner", async (t)
154151} ) ;
155152
156153test ( "parseRemoteFileAddress throws for invalid `GITHUB_REPOSITORY`" , async ( t ) => {
157- const target = callee ( parseRemoteFileAddress ) . withArgs ( "repo@ref" ) ;
158-
159- const env = target . getState ( ) . env ;
160- const getRequired = sinon . stub ( env , "getRequired" ) ;
154+ const getRequired : sinon . SinonStub = sinon . stub ( ) ;
161155 getRequired . withArgs ( ActionsEnvVars . GITHUB_REPOSITORY ) . returns ( `not-valid` ) ;
162156
157+ const target = callee ( parseRemoteFileAddress )
158+ . withArgs ( "repo@ref" )
159+ . withEnv ( ( env ) => {
160+ sinon . define ( env , "getRequired" , getRequired ) ;
161+ } ) ;
162+
163163 await target
164- . withEnv ( env )
165164 . withFeatures ( [ Feature . NewRemoteFileAddresses ] )
166165 . throws ( t , { instanceOf : Error } ) ;
167166
@@ -223,14 +222,13 @@ test("parseRemoteFileAddress accepts remote address without a ref", async (t) =>
223222} ) ;
224223
225224test ( "parseRemoteFileAddress rejects invalid values" , async ( t ) => {
226- const env = getTestEnv ( ) ;
227225 const owner = "owner" ;
228- const getRequired = sinon . stub ( env , "getRequired" ) ;
229- getRequired
230- . withArgs ( ActionsEnvVars . GITHUB_REPOSITORY )
231- . returns ( ` ${ owner } /current-repo` ) ;
232-
233- const target = callee ( parseRemoteFileAddress ) . withEnv ( env ) ;
226+ const target = callee ( parseRemoteFileAddress ) . withEnv ( ( env ) => {
227+ const getRequired = sinon . stub ( env , "getRequired" ) ;
228+ getRequired
229+ . withArgs ( ActionsEnvVars . GITHUB_REPOSITORY )
230+ . returns ( ` ${ owner } /current-repo` ) ;
231+ } ) ;
234232
235233 const testInputs = [
236234 " " ,
0 commit comments