Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decaf simulated type fixes 2 #4906

Merged
merged 3 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 0 additions & 58 deletions packages/driver/src/config/jquery.coffee

This file was deleted.

70 changes: 70 additions & 0 deletions packages/driver/src/config/jquery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const $ = require('jquery')
const _ = require('lodash')

require('jquery.scrollto')

const $dom = require('../dom')

// force jquery to have the same visible
// and hidden logic as cypress

// this prevents `is` from calling into the native .matches method
// which would prevent our `focus` code from ever being called during
// is(:focus).
// see https://github.com/jquery/sizzle/wiki#sizzlematchesselector-domelement-element-string-selector-

// this is to help to interpretor make optimizations around try/catch
const tryCatchFinally = function ({ tryFn, catchFn, finallyFn }) {
try {
return tryFn()
} catch (e) {
return catchFn(e)
} finally {
finallyFn()
}
}

const { matchesSelector } = $.find

$.find.matchesSelector = function (elem, expr) {
let supportMatchesSelector
const isUsingFocus = _.includes(expr, ':focus')

if (isUsingFocus) {
supportMatchesSelector = $.find.support.matchesSelector
$.find.support.matchesSelector = false
}

// eslint-disable-next-line prefer-rest-params
const args = arguments
const _this = this

return tryCatchFinally({
tryFn () {
return matchesSelector.apply(_this, args)
},
catchFn (e) {
throw e
},
finallyFn () {
if (isUsingFocus) {
$.find.support.matchesSelector = supportMatchesSelector
}
},
})
}

// see difference between 'filters' and 'pseudos'
// https://api.jquery.com/filter/ and https://api.jquery.com/category/selectors/

$.expr.pseudos.focus = $dom.isFocused
$.expr.filters.focus = $dom.isFocused
$.expr.pseudos.focused = $dom.isFocused
$.expr.filters.visible = $dom.isVisible
$.expr.filters.hidden = $dom.isHidden

$.expr.cacheLength = 1

$.ajaxSetup({
cache: false,
})
Loading