Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c5d7da6

Browse files
Merge pull request cypress-io#7227 from sainthkh/decaff-driver-4
2 parents 3c4a1af + dc55f21 commit c5d7da6

30 files changed

+2709
-2166
lines changed

packages/driver/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/// <reference path="../../cli/types/index.d.ts" />
2+
/// <reference path="../ts/index.d.ts" />
23
export const $Cypress: Cypress.Cypress
34

45
export default $Cypress

packages/driver/src/cypress/clock.coffee

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const _ = require('lodash')
2+
const lolex = require('lolex')
3+
4+
const install = (win, now, methods) => {
5+
return lolex.withGlobal(win).install({
6+
target: win,
7+
now,
8+
toFake: methods,
9+
})
10+
}
11+
12+
const create = (win, now, methods) => {
13+
let clock = install(win, now, methods)
14+
15+
const tick = (ms) => {
16+
return clock.tick(ms)
17+
}
18+
19+
const restore = () => {
20+
_.each(clock.methods, (method) => {
21+
try {
22+
// before restoring the clock, we need to
23+
// reset the hadOwnProperty in case a
24+
// the application code eradicated the
25+
// overridden clock method at a later time.
26+
// this is a property that lolex using internally
27+
// when restoring the global methods.
28+
// https://github.com/cypress-io/cypress/issues/2850
29+
const fn = clock[method]
30+
31+
if (fn && fn.hadOwnProperty && win[method]) {
32+
win[method].hadOwnProperty = true
33+
}
34+
} catch (error) {} // eslint-disable-line no-empty
35+
})
36+
37+
return clock.uninstall()
38+
}
39+
40+
const bind = (win) => {
41+
clock = install(win, now, methods)
42+
43+
return clock
44+
}
45+
46+
const details = () => {
47+
return _.pick(clock, 'now', 'methods')
48+
}
49+
50+
return {
51+
tick,
52+
53+
restore,
54+
55+
bind,
56+
57+
details,
58+
59+
}
60+
}
61+
62+
module.exports = {
63+
create,
64+
}

packages/driver/src/cypress/command.coffee

Lines changed: 0 additions & 107 deletions
This file was deleted.
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
const _ = require('lodash')
2+
3+
class $Command {
4+
constructor (obj = {}) {
5+
this.reset()
6+
7+
this.set(obj)
8+
}
9+
10+
set (key, val) {
11+
let obj
12+
13+
if (_.isString(key)) {
14+
obj = {}
15+
obj[key] = val
16+
} else {
17+
obj = key
18+
}
19+
20+
_.extend(this.attributes, obj)
21+
22+
return this
23+
}
24+
25+
finishLogs () {
26+
// finish each of the logs we have
27+
return _.invokeMap(this.get('logs'), 'finish')
28+
}
29+
30+
log (log) {
31+
// always set the chainerId of the log to ourselves
32+
// so it can be queried on later
33+
log.set('chainerId', this.get('chainerId'))
34+
35+
this.get('logs').push(log)
36+
37+
return this
38+
}
39+
40+
getLastLog () {
41+
// return the last non-event log
42+
const logs = this.get('logs')
43+
44+
if (logs.length) {
45+
for (let i = logs.length - 1; i >= 0; i--) {
46+
const log = logs[i]
47+
48+
if (log.get('event') === false) {
49+
return log
50+
}
51+
}
52+
}
53+
}
54+
55+
hasPreviouslyLinkedCommand () {
56+
const prev = this.get('prev')
57+
58+
return !!(prev && (prev.get('chainerId') === this.get('chainerId')))
59+
}
60+
61+
is (str) {
62+
return this.get('type') === str
63+
}
64+
65+
get (attr) {
66+
return this.attributes[attr]
67+
}
68+
69+
toJSON () {
70+
return this.attributes
71+
}
72+
73+
_removeNonPrimitives (args) {
74+
// if the obj has options and
75+
// log is false, set it to true
76+
for (let i = args.length - 1; i >= 0; i--) {
77+
const arg = args[i]
78+
79+
if (_.isObject(arg)) {
80+
// filter out any properties which arent primitives
81+
// to prevent accidental mutations
82+
const opts = _.omitBy(arg, _.isObject)
83+
84+
// force command to log
85+
opts.log = true
86+
87+
args[i] = opts
88+
89+
return
90+
}
91+
}
92+
}
93+
94+
skip () {
95+
return this.set('skip', true)
96+
}
97+
98+
stringify () {
99+
let { name, args } = this.attributes
100+
101+
args = _.reduce(args, (memo, arg) => {
102+
arg = _.isString(arg) ? _.truncate(arg, { length: 20 }) : '...'
103+
memo.push(arg)
104+
105+
return memo
106+
}, [])
107+
108+
args = args.join(', ')
109+
110+
return `cy.${name}('${args}')`
111+
}
112+
113+
clone () {
114+
this._removeNonPrimitives(this.get('args'))
115+
116+
return $Command.create(_.clone(this.attributes))
117+
}
118+
119+
reset () {
120+
this.attributes = {}
121+
this.attributes.logs = []
122+
123+
return this
124+
}
125+
126+
static create (obj) {
127+
return new $Command(obj)
128+
}
129+
}
130+
131+
// mixin lodash methods
132+
_.each(['pick'], (method) => {
133+
return $Command.prototype[method] = function (...args) {
134+
args.unshift(this.attributes)
135+
136+
return _[method].apply(_, args)
137+
}
138+
})
139+
140+
module.exports = $Command

0 commit comments

Comments
 (0)