1
- import { DataContext } from '@packages/data-context'
2
- import os from 'os'
3
- import electron , { App } from 'electron'
1
+ import { DataContext , getCtx , setCtx , clearCtx } from '@packages/data-context'
2
+ import electron from 'electron'
4
3
5
4
import specsUtil from './util/specs'
6
- import type { AllowedState , FindSpecs , FoundBrowser , LaunchArgs , LaunchOpts , OpenProjectLaunchOptions , PlatformName , Preferences , SettingsOptions } from '@packages/types'
5
+ import type { AllowedState , FindSpecs , FoundBrowser , LaunchArgs , LaunchOpts , OpenProjectLaunchOptions , Preferences , SettingsOptions } from '@packages/types'
7
6
import browserUtils from './browsers/utils'
8
7
import auth from './gui/auth'
9
8
import user from './user'
10
9
import * as config from './config'
11
- import { EventEmitter } from 'events'
12
10
import { openProject } from './open_project'
13
11
import cache from './cache'
14
12
import errors from './errors'
15
13
import findSystemNode from './util/find_system_node'
16
14
import { graphqlSchema } from '@packages/graphql/src/schema'
17
- import type { InternalDataContextOptions } from '@packages/data-context/src/DataContext'
18
15
import { openExternal } from '@packages/server/lib/gui/links'
19
16
import { getUserEditor } from './util/editors'
20
17
import * as savedState from './saved_state'
21
18
22
19
const { getBrowsers, ensureAndGetByNameOrPath } = browserUtils
23
20
24
- interface MakeDataContextOptions {
25
- electronApp ?: App
26
- os : PlatformName
27
- rootBus : EventEmitter
28
- launchArgs : LaunchArgs
29
- _internalOptions : InternalDataContextOptions
30
- }
31
-
32
- let legacyDataContext : DataContext | undefined
33
-
34
- // For testing
35
- export async function clearLegacyDataContext ( ) {
36
- await legacyDataContext ?. destroy ( )
37
- legacyDataContext = undefined
38
- }
39
-
40
- export function makeLegacyDataContext ( launchArgs : LaunchArgs = { } as LaunchArgs ) : DataContext {
41
- if ( legacyDataContext && process . env . LAUNCHPAD ) {
42
- throw new Error ( `Expected ctx to be passed as an arg, but used legacy data context` )
43
- } else if ( ! legacyDataContext ) {
44
- legacyDataContext = makeDataContext ( {
45
- rootBus : new EventEmitter ,
46
- launchArgs,
47
- os : os . platform ( ) as PlatformName ,
48
- _internalOptions : {
49
- loadCachedProjects : true ,
50
- } ,
51
- } )
52
- }
53
-
54
- return legacyDataContext
55
- }
21
+ export { getCtx , setCtx , clearCtx }
56
22
57
- export function makeDataContext ( options : MakeDataContextOptions ) : DataContext {
23
+ export function makeDataContext ( launchArgs : LaunchArgs ) : DataContext {
58
24
const ctx = new DataContext ( {
59
25
schema : graphqlSchema ,
60
- ... options ,
26
+ launchArgs ,
61
27
launchOptions : { } ,
62
28
appApi : {
63
29
getBrowsers,
@@ -79,7 +45,7 @@ export function makeDataContext (options: MakeDataContextOptions): DataContext {
79
45
} ,
80
46
projectApi : {
81
47
getConfig ( projectRoot : string , options ?: SettingsOptions ) {
82
- return config . get ( projectRoot , options , ctx )
48
+ return config . get ( projectRoot , options )
83
49
} ,
84
50
launchProject ( browser : FoundBrowser , spec : Cypress . Spec , options ?: LaunchOpts ) {
85
51
return openProject . launch ( { ...browser } , spec , options )
0 commit comments