|
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'
|
@@ -59,22 +59,38 @@ export class ProjectActions {
|
59 | 59 | await this.clearActiveProject()
|
60 | 60 |
|
61 | 61 | // Set initial properties, so we can set the config object on the active project
|
62 |
| - this.setCurrentProjectProperties({ |
| 62 | + await this.setCurrentProjectProperties({ |
63 | 63 | projectRoot,
|
64 | 64 | title,
|
65 | 65 | ctPluginsInitialized: false,
|
66 | 66 | e2ePluginsInitialized: false,
|
67 | 67 | config: null,
|
68 | 68 | configChildProcess: null,
|
69 |
| - }) |
70 |
| - |
71 |
| - this.setCurrentProjectProperties({ |
72 |
| - isCTConfigured: await this.ctx.project.isTestingTypeConfigured(projectRoot, 'component'), |
73 |
| - isE2EConfigured: await this.ctx.project.isTestingTypeConfigured(projectRoot, 'e2e'), |
| 69 | + isMissingConfigFile: false, |
74 | 70 | preferences: await this.ctx.project.getProjectPreferences(title),
|
75 | 71 | })
|
76 | 72 |
|
77 |
| - return this |
| 73 | + try { |
| 74 | + // read the config and cache it |
| 75 | + await this.ctx.project.getConfig(projectRoot) |
| 76 | + |
| 77 | + this.setCurrentProjectProperties({ |
| 78 | + isCTConfigured: await this.ctx.project.isTestingTypeConfigured(projectRoot, 'component'), |
| 79 | + isE2EConfigured: await this.ctx.project.isTestingTypeConfigured(projectRoot, 'e2e'), |
| 80 | + }) |
| 81 | + |
| 82 | + return this |
| 83 | + } catch (error: any) { |
| 84 | + if (error.type === 'NO_DEFAULT_CONFIG_FILE_FOUND') { |
| 85 | + this.setCurrentProjectProperties({ |
| 86 | + isMissingConfigFile: true, |
| 87 | + }) |
| 88 | + |
| 89 | + return this |
| 90 | + } |
| 91 | + |
| 92 | + throw error |
| 93 | + } |
78 | 94 | }
|
79 | 95 |
|
80 | 96 | private setCurrentProjectProperties (currentProjectProperties: Partial<ActiveProjectShape>) {
|
@@ -257,14 +273,29 @@ export class ProjectActions {
|
257 | 273 | //
|
258 | 274 | }
|
259 | 275 |
|
260 |
| - createConfigFile (args: MutationAppCreateConfigFileArgs) { |
| 276 | + async createConfigFile (type?: 'component' | 'e2e' | null) { |
261 | 277 | const project = this.ctx.currentProject
|
262 | 278 |
|
263 | 279 | if (!project) {
|
264 | 280 | throw Error(`Cannot create config file without currentProject.`)
|
265 | 281 | }
|
266 | 282 |
|
267 |
| - this.ctx.fs.writeFileSync(path.resolve(project.projectRoot, args.configFilename), args.code) |
| 283 | + let obj: { [k: string]: object } = { |
| 284 | + e2e: {}, |
| 285 | + component: {}, |
| 286 | + } |
| 287 | + |
| 288 | + if (type) { |
| 289 | + obj = { |
| 290 | + [type]: {}, |
| 291 | + } |
| 292 | + } |
| 293 | + |
| 294 | + await this.ctx.fs.writeFile(path.resolve(project.projectRoot, 'cypress.config.js'), `module.exports = ${JSON.stringify(obj, null, 2)}`) |
| 295 | + |
| 296 | + this.setCurrentProjectProperties({ |
| 297 | + isMissingConfigFile: false, |
| 298 | + }) |
268 | 299 | }
|
269 | 300 |
|
270 | 301 | async clearLatestProjectCache () {
|
|
0 commit comments