Skip to content

Commit

Permalink
Revert "chore: remove unused codeGenGlobs (#21438)"
Browse files Browse the repository at this point in the history
This reverts commit df3ca15.
  • Loading branch information
astone123 committed Jul 20, 2022
1 parent 36278fc commit 7dbb92b
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/app/src/specs/CreateSpecModal.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ describe('<CreateSpecModal />', () => {
gql={{
currentProject: {
id: 'id',
codeGenGlobs: {
id: 'super-unique-id',
__typename: 'CodeGenGlobs',
component: '**.vue',
},
currentTestingType: 'component',
configFile: 'cypress.config.js',
configFileAbsolutePath: '/path/to/cypress.config.js',
Expand Down Expand Up @@ -163,6 +168,11 @@ describe('playground', () => {
gql={{
currentProject: {
id: 'id',
codeGenGlobs: {
id: 'super-unique-id',
__typename: 'CodeGenGlobs',
component: '**.vue',
},
currentTestingType: 'component',
configFile: 'cypress.config.js',
configFileAbsolutePath: '/path/to/cypress.config.js',
Expand Down
13 changes: 13 additions & 0 deletions packages/app/src/specs/CreateSpecModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
v-if="generator"
:key="`${generator.id}-${iteration}`"
v-model:title="title"
:code-gen-glob="codeGenGlob"
:gql="props.gql.currentProject"
:type="props.gql.currentProject?.currentTestingType"
:spec-file-name="specFileName"
Expand Down Expand Up @@ -77,6 +78,10 @@ fragment CreateSpecModal on Query {
id
fileExtensionToUse
defaultSpecFileName
codeGenGlobs {
id
component
}
...EmptyGenerator
}
}
Expand Down Expand Up @@ -105,6 +110,14 @@ const specFileName = computed(() => {
return getPathForPlatform(props.gql.currentProject?.defaultSpecFileName || '')
})
const codeGenGlob = computed(() => {
if (!generator.value) {
return null
}
return props.gql.currentProject?.codeGenGlobs[generator.value.id]
})
const filteredGenerators = getFilteredGeneratorList(props.gql.currentProject?.currentTestingType)
const singleGenerator = computed(() => filteredGenerators.value.length === 1 ? filteredGenerators.value[0] : null)
Expand Down
1 change: 1 addition & 0 deletions packages/data-context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@urql/exchange-graphcache": "4.3.6",
"chokidar": "3.5.1",
"common-path-prefix": "3.0.0",
"create-cypress-tests": "0.0.0-development",
"cross-fetch": "^3.1.4",
"dataloader": "^2.0.0",
"dayjs": "^1.9.3",
Expand Down
27 changes: 27 additions & 0 deletions packages/data-context/src/sources/ProjectDataSource.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os from 'os'
import chokidar from 'chokidar'
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'
import _ from 'lodash'
import path from 'path'
Expand Down Expand Up @@ -478,6 +480,31 @@ export class ProjectDataSource {
return preferences[projectTitle] ?? null
}

private guessFramework (projectRoot: string) {
const guess = WIZARD_FRAMEWORKS.find((framework) => {
const lookingForDeps = framework.detectors.map((x) => x.package).reduce(
(acc, dep) => ({ ...acc, [dep]: '*' }),
{},
)

return scanFSForAvailableDependency(projectRoot, lookingForDeps)
})

return guess ?? null
}

async getCodeGenGlobs () {
assert(this.ctx.currentProject, `Cannot find glob without currentProject.`)

const looseComponentGlob = '*.{js,jsx,ts,tsx,.vue}'

const framework = this.guessFramework(this.ctx.currentProject)

return {
component: framework?.glob ?? looseComponentGlob,
}
}

async getResolvedConfigFields (): Promise<ResolvedFromConfig[]> {
const config = this.ctx.lifecycleManager.loadedFullConfig?.resolved ?? {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { parse } from '@babel/parser'
import { WIZARD_FRAMEWORKS } from '@packages/scaffold-config'
import { expect } from 'chai'
import dedent from 'dedent'
import fs from 'fs-extra'
import path from 'path'
import sinon from 'sinon'
import { DataContext } from '../../../src'
import {
Action, codeGenerator, CodeGenResult, CodeGenResults,
Expand Down Expand Up @@ -219,6 +221,9 @@ describe('code-generator', () => {
target,
}

// @ts-ignore
sinon.stub(ctx.project, 'guessFramework').returns(WIZARD_FRAMEWORKS[0])

const newSpecCodeGenOptions = new SpecOptions(ctx, {
codeGenPath: path.join(__dirname, 'files', 'react', 'Button.jsx'),
codeGenType: 'component',
Expand All @@ -239,6 +244,9 @@ describe('code-generator', () => {
target,
}

// @ts-ignore
sinon.stub(ctx.project, 'guessFramework').returns(WIZARD_FRAMEWORKS[1])

const newSpecCodeGenOptions = new SpecOptions(ctx, {
codeGenPath: path.join(__dirname, 'files', 'vue', 'Button.vue'),
codeGenType: 'component',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export const createTestCurrentProject = (title: string, currentProject: Partial<
],
config,
cloudProject: CloudProjectStubs.componentProject,
codeGenGlobs: {
id: 'super-unique-id',
__typename: 'CodeGenGlobs',
component: '**/*.vue',
},
activeBrowser: stubBrowsers[0],
browsers: stubBrowsers,
isDefaultSpecPattern: true,
Expand Down
9 changes: 9 additions & 0 deletions packages/graphql/schemas/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,14 @@ type CodeFrame {
line: Int
}

"""Glob patterns for detecting files for code gen."""
type CodeGenGlobs implements Node {
component: String!

"""Relay style Node ID field for the CodeGenGlobs field"""
id: ID!
}

enum CodeGenType {
component
e2e
Expand Down Expand Up @@ -543,6 +551,7 @@ type CurrentProject implements Node & ProjectLike {

"""List of all code generation candidates stories"""
codeGenCandidates(glob: String!): [FileParts]
codeGenGlobs: CodeGenGlobs!

"""Project configuration"""
config: JSON!
Expand Down
10 changes: 10 additions & 0 deletions packages/graphql/src/schemaTypes/objectTypes/gql-CodeGenGlobs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { objectType } from 'nexus'

export const CodeGenGlobs = objectType({
name: 'CodeGenGlobs',
description: 'Glob patterns for detecting files for code gen.',
node: 'component',
definition (t) {
t.nonNull.string('component')
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from 'path'
import { BrowserStatusEnum, FileExtensionEnum } from '..'
import { TestingTypeEnum } from '../enumTypes/gql-WizardEnums'
import { Browser } from './gql-Browser'
import { CodeGenGlobs } from './gql-CodeGenGlobs'
import { FileParts } from './gql-FileParts'
import { ProjectPreferences } from './gql-ProjectPreferences'
import { Spec } from './gql-Spec'
Expand Down Expand Up @@ -193,6 +194,11 @@ export const CurrentProject = objectType({
},
})

t.nonNull.field('codeGenGlobs', {
type: CodeGenGlobs,
resolve: (src, args, ctx) => ctx.project.getCodeGenGlobs(),
})

t.list.field('codeGenCandidates', {
type: FileParts,
description: 'List of all code generation candidates stories',
Expand Down
1 change: 1 addition & 0 deletions packages/graphql/src/schemaTypes/objectTypes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './gql-AuthState'
export * from './gql-Browser'
export * from './gql-CachedUser'
export * from './gql-CodeFrame'
export * from './gql-CodeGenGlobs'
export * from './gql-CurrentProject'
export * from './gql-DevState'
export * from './gql-Editor'
Expand Down
8 changes: 8 additions & 0 deletions packages/scaffold-config/src/frameworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const WIZARD_FRAMEWORKS = [
]
},
codeGenFramework: 'react',
glob: '*.{js,jsx,tsx}',
mountModule: 'cypress/react',
supportStatus: 'full',
componentIndexHtml: componentIndexHtmlGenerator(),
Expand All @@ -95,6 +96,7 @@ export const WIZARD_FRAMEWORKS = [
]
},
codeGenFramework: 'vue',
glob: '*.vue',
mountModule: 'cypress/vue2',
supportStatus: 'full',
componentIndexHtml: componentIndexHtmlGenerator(),
Expand All @@ -114,6 +116,7 @@ export const WIZARD_FRAMEWORKS = [
]
},
codeGenFramework: 'vue',
glob: '*.vue',
mountModule: 'cypress/vue',
supportStatus: 'full',
componentIndexHtml: componentIndexHtmlGenerator(),
Expand All @@ -133,6 +136,7 @@ export const WIZARD_FRAMEWORKS = [
]
},
codeGenFramework: 'react',
glob: '*.{js,jsx,tsx}',
mountModule: 'cypress/react',
supportStatus: 'alpha',
/**
Expand All @@ -158,6 +162,7 @@ export const WIZARD_FRAMEWORKS = [
]
},
codeGenFramework: 'vue',
glob: '*.vue',
mountModule: 'cypress/vue2',
supportStatus: 'alpha',
componentIndexHtml: componentIndexHtmlGenerator(),
Expand All @@ -176,6 +181,7 @@ export const WIZARD_FRAMEWORKS = [
]
},
codeGenFramework: 'vue',
glob: '*.vue',
mountModule: 'cypress/vue2',
supportStatus: 'full',
componentIndexHtml: componentIndexHtmlGenerator(),
Expand All @@ -194,6 +200,7 @@ export const WIZARD_FRAMEWORKS = [
]
},
codeGenFramework: 'vue',
glob: '*.vue',
mountModule: 'cypress/vue',
supportStatus: 'full',
componentIndexHtml: componentIndexHtmlGenerator(),
Expand All @@ -213,6 +220,7 @@ export const WIZARD_FRAMEWORKS = [
]
},
codeGenFramework: 'react',
glob: '*.{js,jsx,tsx}',
mountModule: 'cypress/react',
supportStatus: 'full',
componentIndexHtml: componentIndexHtmlGenerator(),
Expand Down

0 comments on commit 7dbb92b

Please sign in to comment.