From 753d48fdacc86d6660c125b368f8c84e278f5ebd Mon Sep 17 00:00:00 2001 From: Adrian Smijulj Date: Thu, 8 Nov 2018 19:54:42 +0100 Subject: [PATCH] fix: use default command timeout value from Cypress config. --- .all-contributorsrc | 9 +++++++++ README.md | 6 +++--- src/index.js | 40 +++++++++++++++++++++++++--------------- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 2c48e92..b598acc 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -61,6 +61,15 @@ "test", "tool" ] + }, + { + "login": "adrian1358", + "name": "Adrian Smijulj", + "avatar_url": "https://avatars0.githubusercontent.com/u/5121148?v=4", + "profile": "https://www.webiny.com", + "contributions": [ + "code" + ] } ], "repoType": "github" diff --git a/README.md b/README.md index 38e171a..bd18675 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ [![downloads][downloads-badge]][npmtrends] [![MIT License][license-badge]][license] -[![All Contributors](https://img.shields.io/badge/all_contributors-5-orange.svg?style=flat-square)](#contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors) [![PRs Welcome][prs-badge]][prs] [![Code of Conduct][coc-badge]][coc] @@ -100,8 +100,8 @@ Thanks goes to these people ([emoji key][emojis]): -| [
Kent C. Dodds](https://kentcdodds.com)
[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Code") [📖](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Tests") | [
Ivan Babak](https://sompylasar.github.io)
[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=sompylasar "Code") [🤔](#ideas-sompylasar "Ideas, Planning, & Feedback") | [
Łukasz Gandecki](http://team.thebrain.pro)
[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=lgandecki "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=lgandecki "Tests") | [
Peter Kamps](https://github.com/npeterkamps)
[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Code") [📖](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Documentation") [🤔](#ideas-npeterkamps "Ideas, Planning, & Feedback") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Tests") | [
Airat Aminev](https://github.com/airato)
[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=airato "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=airato "Tests") [🔧](#tool-airato "Tools") | -| :---: | :---: | :---: | :---: | :---: | +| [
Kent C. Dodds](https://kentcdodds.com)
[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Code") [📖](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Tests") | [
Ivan Babak](https://sompylasar.github.io)
[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=sompylasar "Code") [🤔](#ideas-sompylasar "Ideas, Planning, & Feedback") | [
Łukasz Gandecki](http://team.thebrain.pro)
[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=lgandecki "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=lgandecki "Tests") | [
Peter Kamps](https://github.com/npeterkamps)
[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Code") [📖](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Documentation") [🤔](#ideas-npeterkamps "Ideas, Planning, & Feedback") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Tests") | [
Airat Aminev](https://github.com/airato)
[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=airato "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=airato "Tests") [🔧](#tool-airato "Tools") | [
Adrian Smijulj](https://www.webiny.com)
[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=adrian1358 "Code") | +| :---: | :---: | :---: | :---: | :---: | :---: | diff --git a/src/index.js b/src/index.js index 095004c..789ab2a 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,10 @@ import {queries, waitForElement} from 'dom-testing-library' import {getContainer} from './utils' -const defaults = { - timeout: 3000, +const getDefaultCommandOptions = () => { + return { + timeout: Cypress.config().defaultCommandTimeout, + } } const commands = Object.keys(queries).map(queryName => { @@ -10,16 +12,21 @@ const commands = Object.keys(queries).map(queryName => { name: queryName, command: (...args) => { const lastArg = args[args.length - 1] - const waitOptions = (typeof lastArg === 'object') - ? Object.assign({}, defaults, lastArg) - : defaults + const defaults = getDefaultCommandOptions() + const waitOptions = + typeof lastArg === 'object' + ? Object.assign({}, defaults, lastArg) + : defaults const queryImpl = queries[queryName] const baseCommandImpl = doc => { - const container = getContainer(waitOptions.container || doc); - return waitForElement(() => queryImpl(container, ...args), Object.assign({}, waitOptions, { - container, - })) + const container = getContainer(waitOptions.container || doc) + return waitForElement( + () => queryImpl(container, ...args), + Object.assign({}, waitOptions, { + container, + }), + ) } let commandImpl if ( @@ -43,19 +50,22 @@ const commands = Object.keys(queries).map(queryName => { )(commandImpl) return cy .window({log: false}) - .then({ timeout: waitOptions.timeout + 100 }, thenHandler) + .then({timeout: waitOptions.timeout + 100}, thenHandler) .then(subject => { Cypress.log({ $el: subject, name: queryName, - message: args.filter((value) => { + message: args.filter(value => { if (Array.isArray(value) && value.length === 0) { - return false; + return false } - if (typeof value === 'object' && Object.keys(value).length === 0) { - return false; + if ( + typeof value === 'object' && + Object.keys(value).length === 0 + ) { + return false } - return Boolean(value); + return Boolean(value) }), }) return subject