Skip to content

Commit cc5aafc

Browse files
authored
fix: don't scaffold integration when using component tests (#8315)
* Don't scaffold integration when using component tests * Update tests for removing integration scaffolding
1 parent 032b869 commit cc5aafc

File tree

3 files changed

+79
-8
lines changed

3 files changed

+79
-8
lines changed

packages/server/__snapshots__/scaffold_spec.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,46 @@ exports['lib/scaffold .fileTree returns tree-like structure of scaffolded 1'] =
100100
}
101101
]
102102

103+
exports['lib/scaffold .fileTree leaves out integration tests if using component testing 1'] = [
104+
{
105+
"name": "tests",
106+
"children": [
107+
{
108+
"name": "_fixtures",
109+
"children": [
110+
{
111+
"name": "example.json"
112+
}
113+
]
114+
},
115+
{
116+
"name": "_support",
117+
"children": [
118+
{
119+
"name": "commands.js"
120+
},
121+
{
122+
"name": "index.js"
123+
}
124+
]
125+
}
126+
]
127+
},
128+
{
129+
"name": "cypress",
130+
"children": [
131+
{
132+
"name": "plugins",
133+
"children": [
134+
{
135+
"name": "index.js"
136+
}
137+
]
138+
}
139+
]
140+
}
141+
]
142+
103143
exports['lib/scaffold .fileTree leaves out fixtures if configured to false 1'] = [
104144
{
105145
"name": "tests",

packages/server/lib/scaffold.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,19 @@ const filesSizesAreSame = (files, index) => {
6565
})
6666
}
6767

68+
const componentTestingEnabled = (config) => {
69+
const experimentalComponentTestingEnabled = _.get(config, 'resolved.experimentalComponentTesting.value', false)
70+
71+
return experimentalComponentTestingEnabled && !isDefault(config, 'componentFolder')
72+
}
73+
6874
const isNewProject = (integrationFolder) => {
6975
// logic to determine if new project
70-
// 1. there are no files in 'integrationFolder'
71-
// 2. there is a different number of files in 'integrationFolder'
72-
// 3. the files are named the same as the example files
73-
// 4. the bytes of the files match the example files
76+
// 1. component testing is not enabled
77+
// 2. there are no files in 'integrationFolder'
78+
// 3. there is a different number of files in 'integrationFolder'
79+
// 4. the files are named the same as the example files
80+
// 5. the bytes of the files match the example files
7481

7582
debug('determine if new project by globbing files in %o', { integrationFolder })
7683

@@ -122,7 +129,8 @@ module.exports = {
122129
debug(`integration folder ${folder}`)
123130

124131
// skip if user has explicitly set integrationFolder
125-
if (!isDefault(config, 'integrationFolder')) {
132+
// or if user has set up component testing
133+
if (!isDefault(config, 'integrationFolder') || componentTestingEnabled(config)) {
126134
return Promise.resolve()
127135
}
128136

@@ -233,9 +241,13 @@ module.exports = {
233241

234242
return getExampleSpecs()
235243
.then((specs) => {
236-
let files = _.map(specs.shortPaths, (file) => {
237-
return getFilePath(config.integrationFolder, file)
238-
})
244+
let files = []
245+
246+
if (!componentTestingEnabled(config)) {
247+
files = _.map(specs.shortPaths, (file) => {
248+
return getFilePath(config.integrationFolder, file)
249+
})
250+
}
239251

240252
if (config.fixturesFolder) {
241253
files = files.concat([

packages/server/test/unit/scaffold_spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ describe('lib/scaffold', () => {
149149
})
150150
})
151151

152+
it('does not create any files if using component testing', function () {
153+
this.cfg.resolved.experimentalComponentTesting.value = true
154+
this.cfg.resolved.componentFolder.from = 'config'
155+
156+
return scaffold.integration(this.integrationFolder, this.cfg)
157+
.then(() => {
158+
return glob('**/*', { cwd: this.integrationFolder })
159+
}).then((files) => {
160+
expect(files.length).to.eq(0)
161+
})
162+
})
163+
152164
it('does not create example specs if integrationFolder already exists', function () {
153165
// create the integrationFolder ourselves manually
154166
return fs.ensureDirAsync(this.integrationFolder)
@@ -399,6 +411,13 @@ describe('lib/scaffold', () => {
399411
return scaffold.fileTree(this.cfg).then(snapshot)
400412
})
401413

414+
it('leaves out integration tests if using component testing', function () {
415+
this.cfg.resolved.experimentalComponentTesting.value = true
416+
this.cfg.resolved.componentFolder.from = 'config'
417+
418+
return scaffold.fileTree(this.cfg).then(snapshot)
419+
})
420+
402421
it('leaves out fixtures if configured to false', function () {
403422
this.cfg.fixturesFolder = false
404423

0 commit comments

Comments
 (0)