Files
cypress/packages/server/lib/studio.ts
Lachlan Miller 72b8a65e78 feat: Cypress Studio for Cypress 10 (#23544)
* chore: wire up Cypress Studio  (#23413)

* wip

* wip

* wip - spike

* more wip [skip ci]

* update style

* fix ts

* move types around

* extract types

* lint

* fixing tests

* fix component test

* skip some tests

* do not error on experimentalStudio flag

* add studio controls placeholder

* fixing tests

* revert

* revert changes

* rename store

* rename method

* remove comment

* refactor

* correctly feature flag studio

* simplify code

* simplify code

* lift check into useEventManager

* correctly hide create studio prompt based on flag;

* remove superfulous css

* rename variables

* fix bugs

* wip

* unskip tests

* unskip more tests

* fix a bug in the assertion API

* fix bug in assertions [skip ci]

* wip - bugs [skip ci]

* feat: add experimentalStudio flag back (#23506)

Co-authored-by: astone123 <adams@cypress.io>

* chore: Add Studio UI to Cypress 10 (#23537)

* wip

* wip

* wip - spike

* more wip [skip ci]

* update style

* fix ts

* move types around

* extract types

* lint

* fixing tests

* fix component test

* skip some tests

* do not error on experimentalStudio flag

* add studio controls placeholder

* fixing tests

* revert

* revert changes

* rename store

* rename method

* remove comment

* refactor

* correctly feature flag studio

* chore: wip add barebones studio modals

* simplify code

* simplify code

* lift check into useEventManager

* correctly hide create studio prompt based on flag;

* remove superfulous css

* chore: style studio toolbar

* chore: misc feedback

* chore: remove studio store prop

* chore: studio URL prompt and other changes

* update component

* chore: UI styling and remove studio init modal

* chore: revert unnecessary changes

* chore: fix types

* chore: fix some tests, minor refactor (#23545)

* fix test

* fix test

* add noHelp link to StandardModal

Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com>

* test: studio e2e tests (#23546)

* add basic e2e test

* add some e2e tests for studio and a note on limitations

* additional spec

* add more tests, refactor helper

* fix bug in studio

* remove test code

* chore: UI feedback

* fix race condition

* update tests

* rename test

* improve types in reporter

* remove dead code

* improve tests

* merge tests into one spec

* chore: Cap instruction modal width; exit studio mode when new spec is chosen

* chore: Only render studio error when test has failed; add test for studioEnabled

* correctly check if command is studio or not

* improve specs and hopefully reduce flake

* communicate studio state from app->reporter

* receive studio save state validity from app

* fix test

* improve test coverage

* fix external link

Co-authored-by: astone123 <adams@cypress.io>
2022-08-30 07:45:06 +10:00

60 lines
1.4 KiB
TypeScript

import * as savedState from './saved_state'
import { Command, SaveDetails, createNewTestInFile, appendCommandsToTest, createNewTestInSuite, convertCommandsToText } from './util/spec_writer'
interface SaveInfo extends SaveDetails {
isSuite: boolean
isRoot: boolean
}
class StudioSaveError extends Error {
static errMessage = (isSuite) => `Studio was unable to find your ${isSuite ? 'suite' : 'test'} in the spec file.`
constructor (isSuite) {
super(StudioSaveError.errMessage(isSuite))
this.name = 'StudioSaveError'
}
}
export const getStudioModalShown = () => {
return savedState.create()
.then((state) => state.get())
.then((state) => !!state.showedStudioModal)
}
export const save = (saveInfo: SaveInfo) => {
const { isSuite, isRoot, absoluteFile, commands, testName } = saveInfo
const saveToFile = () => {
if (isRoot) {
return createNewTestInFile(absoluteFile, commands, testName || 'New Test')
}
if (isSuite) {
return createNewTestInSuite(saveInfo)
}
return appendCommandsToTest(saveInfo)
}
return saveToFile()
.then((success) => {
if (!success) {
throw new StudioSaveError(isSuite)
}
return null
})
.catch((err) => {
return {
type: err.type,
name: err.name,
message: err.message,
stack: err.stack,
}
})
}
export const getCommandsText = (commands: Command[]) => {
return convertCommandsToText(commands)
}