|
1 |
| -import type { CodeGenType, MutationAddProjectArgs, MutationAppCreateConfigFileArgs, MutationSetProjectPreferencesArgs, TestingTypeEnum } from '@packages/graphql/src/gen/nxs.gen' |
| 1 | +import type { CodeGenType, MutationAddProjectArgs, MutationSetProjectPreferencesArgs, TestingTypeEnum } from '@packages/graphql/src/gen/nxs.gen' |
2 | 2 | import type { FindSpecs, FoundBrowser, FoundSpec, FullConfig, LaunchArgs, LaunchOpts, OpenProjectLaunchOptions, Preferences, SettingsOptions } from '@packages/types'
|
3 | 3 | import path from 'path'
|
4 | 4 | import type { ActiveProjectShape, ProjectShape } from '../data/coreDataShape'
|
@@ -62,22 +62,38 @@ export class ProjectActions {
|
62 | 62 | await this.clearActiveProject()
|
63 | 63 |
|
64 | 64 | // Set initial properties, so we can set the config object on the active project
|
65 |
| - this.setCurrentProjectProperties({ |
| 65 | + await this.setCurrentProjectProperties({ |
66 | 66 | projectRoot,
|
67 | 67 | title,
|
68 | 68 | ctPluginsInitialized: false,
|
69 | 69 | e2ePluginsInitialized: false,
|
70 | 70 | config: null,
|
71 | 71 | configChildProcess: null,
|
72 |
| - }) |
73 |
| - |
74 |
| - this.setCurrentProjectProperties({ |
75 |
| - isCTConfigured: await this.ctx.project.isTestingTypeConfigured(projectRoot, 'component'), |
76 |
| - isE2EConfigured: await this.ctx.project.isTestingTypeConfigured(projectRoot, 'e2e'), |
| 72 | + isMissingConfigFile: false, |
77 | 73 | preferences: await this.ctx.project.getProjectPreferences(title),
|
78 | 74 | })
|
79 | 75 |
|
80 |
| - return this |
| 76 | + try { |
| 77 | + // read the config and cache it |
| 78 | + await this.ctx.project.getConfig(projectRoot) |
| 79 | + |
| 80 | + this.setCurrentProjectProperties({ |
| 81 | + isCTConfigured: await this.ctx.project.isTestingTypeConfigured(projectRoot, 'component'), |
| 82 | + isE2EConfigured: await this.ctx.project.isTestingTypeConfigured(projectRoot, 'e2e'), |
| 83 | + }) |
| 84 | + |
| 85 | + return this |
| 86 | + } catch (error: any) { |
| 87 | + if (error.type === 'NO_DEFAULT_CONFIG_FILE_FOUND') { |
| 88 | + this.setCurrentProjectProperties({ |
| 89 | + isMissingConfigFile: true, |
| 90 | + }) |
| 91 | + |
| 92 | + return this |
| 93 | + } |
| 94 | + |
| 95 | + throw error |
| 96 | + } |
81 | 97 | }
|
82 | 98 |
|
83 | 99 | // Temporary: remove after other refactor lands
|
@@ -277,14 +293,29 @@ export class ProjectActions {
|
277 | 293 | //
|
278 | 294 | }
|
279 | 295 |
|
280 |
| - createConfigFile (args: MutationAppCreateConfigFileArgs) { |
| 296 | + async createConfigFile (type?: 'component' | 'e2e' | null) { |
281 | 297 | const project = this.ctx.currentProject
|
282 | 298 |
|
283 | 299 | if (!project) {
|
284 | 300 | throw Error(`Cannot create config file without currentProject.`)
|
285 | 301 | }
|
286 | 302 |
|
287 |
| - this.ctx.fs.writeFileSync(path.resolve(project.projectRoot, args.configFilename), args.code) |
| 303 | + let obj: { [k: string]: object } = { |
| 304 | + e2e: {}, |
| 305 | + component: {}, |
| 306 | + } |
| 307 | + |
| 308 | + if (type) { |
| 309 | + obj = { |
| 310 | + [type]: {}, |
| 311 | + } |
| 312 | + } |
| 313 | + |
| 314 | + await this.ctx.fs.writeFile(path.resolve(project.projectRoot, 'cypress.config.js'), `module.exports = ${JSON.stringify(obj, null, 2)}`) |
| 315 | + |
| 316 | + this.setCurrentProjectProperties({ |
| 317 | + isMissingConfigFile: false, |
| 318 | + }) |
288 | 319 | }
|
289 | 320 |
|
290 | 321 | async clearLatestProjectCache () {
|
|
0 commit comments