@@ -5,51 +5,43 @@ import ezSpawn from "@jsdevtools/ez-spawn"
55import pushWorkflowRunInProgressFixture from './fixtures/workflow_run.in_progress.json'
66import prWorkflowRunRequestedFixture from './fixtures/pr.workflow_run.requested.json'
77import prPullRequestSynchronizeFixture from './fixtures/pr.pull_request.json'
8- import { setupServer } from 'msw/node'
9- import { http , HttpResponse } from 'msw'
10-
11- const server = setupServer (
12- // Mock the GitHub API installation endpoint
13- http . get ( 'https://api.github.com/repos/:owner/:repo/installation' , ( ctx ) => {
14- return HttpResponse . json ( {
15- id : 1234567 ,
16- access_tokens_url : 'https://api.github.com/app/installations/1234567/access_tokens' ,
17- } )
18- } ) ,
8+ import { simulation } from '@simulacrum/github-api-simulator'
199
20- // Mock the GitHub API token endpoint
21- http . post ( 'https://api.github.com/app/installations/:installation_id/access_tokens' , ( ctx ) => {
22- return HttpResponse . json ( {
23- token : 'ghs_mock_token' ,
24- expires_at : '2024-03-22T00:00:00Z' ,
25- } )
26- } )
27- )
10+ let server ;
11+ let workerUrl : string ;
2812
2913let worker : UnstableDevWorker
30-
3114beforeAll ( async ( ) => {
32- // Start MSW server
33- server . listen ( )
15+ const app = simulation ( {
16+ initialState : {
17+ users : [ ] ,
18+ organizations : [ { login : "stackblitz-labs" } ] ,
19+ repositories : [ { owner : "stackblitz-labs" , name : "temporary-test" } ] ,
20+ branches : [ { name : "main" } ] ,
21+ blobs : [ ] ,
22+ } ,
23+ } ) ;
24+ server = await app . listen ( 3300 ) ;
3425
3526 await ezSpawn . async ( 'pnpm cross-env TEST=true pnpm --filter=backend run build' , [ ] , {
3627 stdio : "inherit" ,
3728 shell : true ,
3829 } ) ;
39- worker = await unstable_dev ( ' dist/_worker.js' , {
40- config : '. /wrangler.toml' ,
30+ worker = await unstable_dev ( ` ${ import . meta . dirname } / dist/_worker.js` , {
31+ config : ` ${ import . meta . dirname } /wrangler.toml` ,
4132 } )
4233 const url = `${ worker . proxyData . userWorkerUrl . protocol } //${ worker . proxyData . userWorkerUrl . hostname } :${ worker . proxyData . userWorkerUrl . port } `
4334 console . log ( url )
35+ workerUrl = url
4436 await ezSpawn . async ( `pnpm cross-env TEST=true API_URL=${ url } pnpm --filter=pkg-pr-new run build` , [ ] , {
4537 stdio : "inherit" ,
4638 shell : true ,
4739 } ) ;
4840} )
4941
50- afterAll ( ( ) => {
51- server . close ( )
52- } )
42+ afterAll ( async ( ) => {
43+ await server . ensureClose ( ) ;
44+ } ) ;
5345
5446describe . sequential . each ( [
5547 [ pushWorkflowRunInProgressFixture ] ,
@@ -135,7 +127,7 @@ describe.sequential.each([
135127 expect ( shaBlobSize ) . toEqual ( refBlobSize ) ;
136128
137129 // Test installation
138- const url = `/${ owner } /${ repo } /playground-a@${ sha } ?id=${ Date . now ( ) } `
130+ const url = new URL ( `/${ owner } /${ repo } /playground-a@${ sha } ?id=${ Date . now ( ) } ` , workerUrl )
139131 const installProcess = await ezSpawn . async ( `pnpm cross-env CI=true npx -f playground-a@${ url } ` , {
140132 stdio : "overlapped" ,
141133 shell : true ,
@@ -152,7 +144,7 @@ describe.sequential.each([
152144 expect ( response . status ) . toBe ( 200 )
153145
154146 // Test installation
155- const url = `/${ owner } /${ repo } /playground-b@${ sha } ?id=${ Date . now ( ) } `
147+ const url = new URL ( `/${ owner } /${ repo } /playground-b@${ sha } ?id=${ Date . now ( ) } ` , workerUrl )
156148 const installProcess = await ezSpawn . async ( `pnpm cross-env CI=true npx -f playground-b@${ url } ` , {
157149 stdio : "overlapped" ,
158150 shell : true ,
0 commit comments