Skip to content

Commit 51c4a7c

Browse files
committed
address comments
1 parent e46badf commit 51c4a7c

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.js can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
// This function is called when a project is opened or re-opened (e.g. due to
13+
// the project's config changing)
14+
15+
/**
16+
* @type {Cypress.PluginConfig}
17+
*/
18+
// eslint-disable-next-line no-unused-vars
19+
module.exports = (on, config) => {
20+
// `on` is used to hook into various events Cypress emits
21+
// `config` is the resolved Cypress config
22+
}

packages/data-context/src/actions/ProjectActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class ProjectActions {
186186
await this.api.clearLatestProjectsCache()
187187
}
188188

189-
async createComponentIndexHtml (template: string) {
189+
createComponentIndexHtml (template: string) {
190190
const project = this.ctx.activeProject
191191

192192
if (!project) {
@@ -196,7 +196,7 @@ export class ProjectActions {
196196
if (this.ctx.activeProject?.isFirstTimeCT) {
197197
const indexHtmlPath = path.resolve(this.ctx.activeProject.projectRoot, 'cypress/component/support/index.html')
198198

199-
this.ctx.fs.outputFileSync(indexHtmlPath, template)
199+
this.ctx.fs.outputFile(indexHtmlPath, template)
200200
}
201201
}
202202
}

packages/data-context/src/actions/StorybookActions.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { FoundSpec, FullConfig } from '@packages/types'
12
import { CsfFile, readCsfOrMdx } from '@storybook/csf-tools'
23
import endent from 'endent'
34
import * as path from 'path'
@@ -13,15 +14,18 @@ export class StorybookActions {
1314
throw Error(`Cannot generate a spec without activeProject.`)
1415
}
1516

16-
const spec = await this.generate(storyPath, project.projectRoot)
17+
const config = await this.ctx.project.getConfig(project.projectRoot)
18+
19+
const spec = await this.generate(storyPath, project.projectRoot, config.componentFolder)
1720

1821
this.ctx.wizardData.generatedSpec = spec
1922
}
2023

2124
private async generate (
2225
storyPath: string,
2326
projectRoot: string,
24-
): Promise<Cypress.Cypress['spec'] | null> {
27+
componentFolder: FullConfig['componentFolder'],
28+
): Promise<FoundSpec | null> {
2529
const storyFile = path.parse(storyPath)
2630
const storyName = storyFile.name.split('.')[0]
2731

@@ -38,11 +42,12 @@ export class StorybookActions {
3842
return null
3943
}
4044

45+
const specFileExtension = '.cy-spec'
4146
const newSpecContent = this.generateSpecFromCsf(parsed, storyFile)
4247
const newSpecPath = path.join(
4348
storyPath,
4449
'..',
45-
`${parsed.meta.component}.cy-spec${storyFile.ext}`,
50+
`${parsed.meta.component}${specFileExtension}${storyFile.ext}`,
4651
)
4752

4853
// If this passes then the file exists and we don't want to overwrite it
@@ -56,10 +61,18 @@ export class StorybookActions {
5661

5762
await this.ctx.fs.outputFileSync(newSpecPath, newSpecContent)
5863

64+
const parsedSpec = path.parse(newSpecPath)
65+
66+
// Can this be obtained from the spec watcher?
5967
return {
60-
name: path.parse(newSpecPath).name,
68+
baseName: parsedSpec.base,
69+
fileName: parsedSpec.base.replace(specFileExtension, ''),
70+
specFileExtension,
71+
fileExtension: parsedSpec.ext,
72+
name: path.relative(componentFolder || projectRoot, newSpecPath),
6173
relative: path.relative(projectRoot, newSpecPath),
6274
absolute: newSpecPath,
75+
specType: 'component',
6376
}
6477
} catch (e) {
6578
return null

0 commit comments

Comments
 (0)