-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use correct path for scaffolding spec on CT #21411
Merged
estrada9166
merged 14 commits into
10.0-release
from
alejandro/fix/default-spec-path-for-component
May 12, 2022
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bfcf796
fix: use correct path for scaffolding spec on CT
estrada9166 50a4f91
Merge branch '10.0-release' into alejandro/fix/default-spec-path-for-…
estrada9166 612a529
Merge branch '10.0-release' into alejandro/fix/default-spec-path-for-…
estrada9166 d4eadec
Refactor code
estrada9166 2edb1c3
Merge branch '10.0-release' into alejandro/fix/default-spec-path-for-…
estrada9166 2eae482
Merge branch '10.0-release' into alejandro/fix/default-spec-path-for-…
estrada9166 1efad60
Merge branch '10.0-release' into alejandro/fix/default-spec-path-for-…
estrada9166 25e37c3
Merge branch '10.0-release' into alejandro/fix/default-spec-path-for-…
estrada9166 9f28c90
Update with feedback
estrada9166 72d83f2
Merge branch '10.0-release' into alejandro/fix/default-spec-path-for-…
estrada9166 83cf70e
Merge branch '10.0-release' into alejandro/fix/default-spec-path-for-…
estrada9166 3fd184f
Merge branch '10.0-release' into alejandro/fix/default-spec-path-for-…
estrada9166 6dfc2d7
Merge branch '10.0-release' into alejandro/fix/default-spec-path-for-…
estrada9166 284a51d
Merge branch '10.0-release' into alejandro/fix/default-spec-path-for-…
estrada9166 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import os from 'os' | ||
import chokidar from 'chokidar' | ||
import type { ResolvedFromConfig, RESOLVED_FROM, FoundSpec } from '@packages/types' | ||
import type { ResolvedFromConfig, RESOLVED_FROM, FoundSpec, TestingType } from '@packages/types' | ||
import { WIZARD_FRAMEWORKS } from '@packages/scaffold-config' | ||
import { scanFSForAvailableDependency } from 'create-cypress-tests' | ||
import minimatch from 'minimatch' | ||
|
@@ -104,7 +104,7 @@ export function transformSpec ({ | |
} | ||
} | ||
|
||
export function getDefaultSpecFileName (specPattern: string, fileExtensionToUse?: 'js' | 'ts') { | ||
export function getDefaultSpecFileName (specPattern: string, testingType: TestingType, fileExtensionToUse?: 'js' | 'ts') { | ||
function replaceWildCard (s: string, fallback: string) { | ||
return s.replace(/\*/g, fallback) | ||
} | ||
|
@@ -121,7 +121,7 @@ export function getDefaultSpecFileName (specPattern: string, fileExtensionToUse? | |
dirname = dirname.replace('**', 'cypress') | ||
} | ||
|
||
const splittedDirname = dirname.split('/').filter((s) => s !== '**').map((x) => replaceWildCard(x, 'e2e')).join('/') | ||
const splittedDirname = dirname.split('/').filter((s) => s !== '**').map((x) => replaceWildCard(x, testingType)).join('/') | ||
const fileName = replaceWildCard(parsedGlob.path.filename, 'filename') | ||
|
||
const extnameWithoutExt = parsedGlob.path.extname.replace(parsedGlob.path.ext, '') | ||
|
@@ -282,13 +282,15 @@ export class ProjectDataSource { | |
} | ||
|
||
async defaultSpecFileName () { | ||
const defaultFileName = 'cypress/e2e/filename.cy.js' | ||
const getDefaultFileName = (testingType: TestingType) => `cypress/${testingType}/filename.cy.${this.ctx.lifecycleManager.fileExtensionToUse}` | ||
|
||
try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not directly related but do we need this |
||
if (!this.ctx.currentProject || !this.ctx.coreData.currentTestingType) { | ||
return null | ||
} | ||
|
||
const defaultFileName = getDefaultFileName(this.ctx.coreData.currentTestingType) | ||
|
||
let specPatternSet: string | undefined | ||
const { specPattern = [] } = await this.ctx.project.specPatterns() | ||
|
||
|
@@ -300,15 +302,19 @@ export class ProjectDataSource { | |
return defaultFileName | ||
} | ||
|
||
const specFileName = getDefaultSpecFileName(specPatternSet, this.ctx.lifecycleManager.fileExtensionToUse) | ||
if (specPatternSet === defaultSpecPattern[this.ctx.coreData.currentTestingType]) { | ||
return defaultFileName | ||
} | ||
|
||
const specFileName = getDefaultSpecFileName(specPatternSet, this.ctx.coreData.currentTestingType, this.ctx.lifecycleManager.fileExtensionToUse) | ||
|
||
if (!specFileName) { | ||
return defaultFileName | ||
} | ||
|
||
return specFileName | ||
} catch { | ||
return defaultFileName | ||
return getDefaultFileName(this.ctx.coreData.currentTestingType ?? 'e2e') | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem correct. What if
cypress/component
does not exist? Considering the default is something likesrc/**/*.cy.{js.jsx}
, it likely won't exist for most users.Should we make sure the default placeholder is a valid path (or we don't care?)
We could check against the specPattern to make sure it matches (we've already got this logic here.
If it does not match, we could do something like:
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why it is checked here to be sure it's the default specPattern - so, this ^^ is just for the default paths
when there're custom specPatterns as you mention it is updated here using the custom pattern and wild cards
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉