Skip to content

Commit ce1119a

Browse files
chore: make mobx decoratorless (#31459)
Co-authored-by: Jennifer Shehane <[email protected]>
1 parent a1fa6b2 commit ce1119a

20 files changed

+360
-179
lines changed

.circleci/workflows.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mainBuildFilters: &mainBuildFilters
3838
- /^release\/\d+\.\d+\.\d+$/
3939
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
4040
- 'update-v8-snapshot-cache-on-develop'
41-
- 'chore/fix_react_18_deprecation_warnings'
41+
- 'chore/update_mobx_decoratorless'
4242

4343
# usually we don't build Mac app - it takes a long time
4444
# but sometimes we want to really confirm we are doing the right thing
@@ -49,7 +49,7 @@ macWorkflowFilters: &darwin-workflow-filters
4949
- equal: [ develop, << pipeline.git.branch >> ]
5050
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
5151
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
52-
- equal: [ 'chore/fix_react_18_deprecation_warnings', << pipeline.git.branch >> ]
52+
- equal: [ 'chore/update_mobx_decoratorless', << pipeline.git.branch >> ]
5353
- matches:
5454
pattern: /^release\/\d+\.\d+\.\d+$/
5555
value: << pipeline.git.branch >>
@@ -60,7 +60,7 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
6060
- equal: [ develop, << pipeline.git.branch >> ]
6161
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
6262
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
63-
- equal: [ 'chore/fix_react_18_deprecation_warnings', << pipeline.git.branch >> ]
63+
- equal: [ 'chore/update_mobx_decoratorless', << pipeline.git.branch >> ]
6464
- matches:
6565
pattern: /^release\/\d+\.\d+\.\d+$/
6666
value: << pipeline.git.branch >>
@@ -83,8 +83,7 @@ windowsWorkflowFilters: &windows-workflow-filters
8383
- equal: [ develop, << pipeline.git.branch >> ]
8484
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
8585
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
86-
- equal: [ 'chore/fix_react_18_deprecation_warnings', << pipeline.git.branch >> ]
87-
- equal: [ 'cacie/fix-du', << pipeline.git.branch >> ]
86+
- equal: [ 'chore/update_mobx_decoratorless', << pipeline.git.branch >> ]
8887
- matches:
8988
pattern: /^release\/\d+\.\d+\.\d+$/
9089
value: << pipeline.git.branch >>
@@ -158,7 +157,7 @@ commands:
158157
name: Set environment variable to determine whether or not to persist artifacts
159158
command: |
160159
echo "Setting SHOULD_PERSIST_ARTIFACTS variable"
161-
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "chore/fix_react_18_deprecation_warnings" ]]; then
160+
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "chore/update_mobx_decoratorless" ]]; then
162161
export SHOULD_PERSIST_ARTIFACTS=true
163162
fi' >> "$BASH_ENV"
164163
# You must run `setup_should_persist_artifacts` command and be using bash before running this command

packages/app/src/store/mobx-runner-store.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,47 @@ const defaults = {
1515
} as const
1616

1717
export class MobxRunnerStore {
18-
@observable spec?: Cypress.Spec
19-
@observable specs: Cypress.Spec[] = []
20-
@observable specRunId?: string
21-
@observable isLoading = true
22-
@observable width: number
23-
@observable height: number
24-
@observable automation?: AutomationStatus
25-
@observable canSaveStudioLogs = false
18+
spec?: Cypress.Spec
19+
specs: Cypress.Spec[] = []
20+
specRunId?: string
21+
isLoading = true
22+
width: number
23+
height: number
24+
automation?: AutomationStatus
25+
canSaveStudioLogs = false
2626

2727
constructor (testingType: Cypress.TestingType) {
28-
makeObservable(this)
28+
makeObservable(this, {
29+
spec: observable,
30+
specs: observable,
31+
specRunId: observable,
32+
isLoading: observable,
33+
width: observable,
34+
height: observable,
35+
automation: observable,
36+
canSaveStudioLogs: observable,
37+
setCanSaveStudioLogs: action,
38+
setSpec: action,
39+
checkCurrentSpecStillExists: action,
40+
setSpecs: action,
41+
setIsLoading: action,
42+
updateDimensions: action,
43+
})
44+
2945
this.width = defaults[testingType].width
3046
this.height = defaults[testingType].height
3147
}
3248

33-
@action setCanSaveStudioLogs (canSave: boolean) {
49+
setCanSaveStudioLogs (canSave: boolean) {
3450
this.canSaveStudioLogs = canSave
3551
}
3652

37-
@action setSpec (spec: Cypress.Spec | undefined) {
53+
setSpec (spec: Cypress.Spec | undefined) {
3854
this.spec = spec
3955
this.specRunId = nanoid()
4056
}
4157

42-
@action checkCurrentSpecStillExists (specs: Cypress.Spec[]) {
58+
checkCurrentSpecStillExists (specs: Cypress.Spec[]) {
4359
const newSpecsAbsolutes = new Set(specs.map((spec) => spec.absolute))
4460

4561
this.specs.forEach((oldSpec) => {
@@ -49,16 +65,16 @@ export class MobxRunnerStore {
4965
})
5066
}
5167

52-
@action setSpecs (specs: Cypress.Spec[]) {
68+
setSpecs (specs: Cypress.Spec[]) {
5369
this.checkCurrentSpecStillExists(specs)
5470
this.specs = specs
5571
}
5672

57-
@action setIsLoading (isLoading: boolean) {
73+
setIsLoading (isLoading: boolean) {
5874
this.isLoading = isLoading
5975
}
6076

61-
@action updateDimensions (width: number, height: number) {
77+
updateDimensions (width: number, height: number) {
6278
this.height = height
6379
this.width = width
6480
}

packages/app/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
"../frontend-shared/cypress/**/*.ts"
1313
],
1414
"compilerOptions": {
15-
"noImplicitThis": true,
15+
// needed for mobx
1616
"useDefineForClassFields": true,
17+
"noImplicitThis": true,
1718
"paths": {
1819
"@cy/i18n": ["../frontend-shared/src/locales/i18n"],
1920
"@cy/components/*": ["../frontend-shared/src/components/*"],

packages/reporter/src/agents/agent-model.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ export interface AgentProps extends InstrumentProps {
77
}
88

99
export default class Agent extends Instrument {
10-
@observable callCount: number = 0
11-
@observable functionName: string
10+
callCount: number = 0
11+
functionName: string
1212

1313
constructor (props: AgentProps) {
1414
super(props)
1515

16-
makeObservable(this)
16+
makeObservable(this, {
17+
callCount: observable,
18+
functionName: observable,
19+
})
1720

1821
this.callCount = props.callCount
1922
this.functionName = props.functionName

packages/reporter/src/attempts/attempt-model.ts

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,68 @@ import type Log from '../instruments/instrument-model'
1414
import Session, { SessionProps } from '../sessions/sessions-model'
1515

1616
export default class Attempt {
17-
@observable agents: Agent[] = []
18-
@observable sessions: Record<string, Session> = {}
19-
@observable commands: Command[] = []
20-
@observable err?: Err = undefined
21-
@observable hooks: Hook[] = []
17+
agents: Agent[] = []
18+
sessions: Record<string, Session> = {}
19+
commands: Command[] = []
20+
err?: Err = undefined
21+
hooks: Hook[] = []
2222
// TODO: make this an enum with states: 'QUEUED, ACTIVE, INACTIVE'
23-
@observable isActive: boolean | null = null
24-
@observable routes: Route[] = []
25-
@observable _state?: TestState | null = null
26-
@observable _testOuterStatus?: TestState = undefined
27-
@observable _invocationCount: number = 0
28-
@observable invocationDetails?: FileDetails
23+
isActive: boolean | null = null
24+
routes: Route[] = []
25+
_state?: TestState | null = null
26+
_testOuterStatus?: TestState = undefined
27+
_invocationCount: number = 0
28+
invocationDetails?: FileDetails
2929
// eslint-disable-next-line @typescript-eslint/no-unused-vars
30-
@observable hookCount: { [name in HookName]: number } = {
30+
hookCount: { [name in HookName]: number } = {
3131
'before all': 0,
3232
'before each': 0,
3333
'after all': 0,
3434
'after each': 0,
3535
'test body': 0,
3636
'studio commands': 0,
3737
}
38-
@observable _isOpen: boolean|null = null
38+
_isOpen: boolean|null = null
3939

40-
@observable isOpenWhenLast: boolean | null = null
40+
isOpenWhenLast: boolean | null = null
4141
_callbackAfterUpdate: Function | null = null
4242
testId: string
4343

44-
@observable id: number
44+
id: number
4545
test: Test
4646

4747
_logs: {[key: string]: Log} = {}
4848

4949
constructor (props: TestProps, test: Test) {
50-
makeObservable(this)
50+
makeObservable(this, {
51+
agents: observable,
52+
sessions: observable,
53+
commands: observable,
54+
err: observable,
55+
hooks: observable,
56+
isActive: observable,
57+
routes: observable,
58+
_state: observable,
59+
_testOuterStatus: observable,
60+
_invocationCount: observable,
61+
invocationDetails: observable,
62+
hookCount: observable,
63+
_isOpen: observable,
64+
isOpenWhenLast: observable,
65+
id: observable,
66+
hasCommands: computed,
67+
isLongRunning: computed,
68+
_hasLongRunningCommand: computed,
69+
state: computed,
70+
error: computed,
71+
isLast: computed,
72+
isOpen: computed,
73+
start: action,
74+
update: action,
75+
setIsOpen: action,
76+
finish: action,
77+
})
78+
5179
this.testId = props.id
5280
this.id = props.currentRetry || 0
5381
this.test = test
@@ -66,25 +94,25 @@ export default class Attempt {
6694
_.each(props.routes, this.addLog)
6795
}
6896

69-
@computed get hasCommands () {
97+
get hasCommands () {
7098
return !!this.commands.length
7199
}
72100

73-
@computed get isLongRunning () {
101+
get isLongRunning () {
74102
return this.isActive && this._hasLongRunningCommand
75103
}
76104

77-
@computed get _hasLongRunningCommand () {
105+
get _hasLongRunningCommand () {
78106
return _.some(this.commands, (command) => {
79107
return command.isLongRunning
80108
})
81109
}
82110

83-
@computed get state () {
111+
get state () {
84112
return this._state || (this.isActive ? 'active' : 'processing')
85113
}
86114

87-
@computed get error () {
115+
get error () {
88116
const command = this.err?.isCommandErr ? this.commandMatchingErr() : undefined
89117

90118
return {
@@ -94,11 +122,11 @@ export default class Attempt {
94122
}
95123
}
96124

97-
@computed get isLast () {
125+
get isLast () {
98126
return this.id === this.test.lastAttempt.id
99127
}
100128

101-
@computed get isOpen () {
129+
get isOpen () {
102130
if (this._isOpen !== null) {
103131
return this._isOpen
104132
}
@@ -166,11 +194,11 @@ export default class Attempt {
166194
.last()
167195
}
168196

169-
@action start () {
197+
start () {
170198
this.isActive = true
171199
}
172200

173-
@action update (props: UpdatableTestProps) {
201+
update (props: UpdatableTestProps) {
174202
if (props.state) {
175203
this._state = props.state
176204
}
@@ -200,11 +228,11 @@ export default class Attempt {
200228
}
201229
}
202230

203-
@action setIsOpen (isOpen: boolean) {
231+
setIsOpen (isOpen: boolean) {
204232
this._isOpen = isOpen
205233
}
206234

207-
@action finish (props: UpdatableTestProps, isInteractive: boolean) {
235+
finish (props: UpdatableTestProps, isInteractive: boolean) {
208236
this.update(props)
209237
this.isActive = false
210238

0 commit comments

Comments
 (0)