Skip to content

Commit

Permalink
Update Saucelabs (#56)
Browse files Browse the repository at this point in the history
* WIP

* Cleanup Rakefile

* Fix travis setup

* Skip unit and lint testing in WIP

* Update sauce connect

* Adjust travis.yml

* Fix rake command

* Simplify build

* Add missing tunnel identifieer

* WIP only run one test on one browser

* Use localhost

* Run all tests

* WIP

* Revert hostname change

* Use localhost (again)

* Fix?

* Run all browsers

* Shorten descriptions

* Test only windows 8 ie

* WIP

* Add no ssl bump - probably won't work!

* TEST

* Localhost?

* Fix ie runs

* localhost again

* Add bt.local host

* Force failures

* actually force failure

* Test

* Correct hostname injection

* Move HOSTNAME env to integration tests only

* wip

* Force build failure

* Correct placement of variable

* Fix tests

* Add instructions to readme

* Sleep before finding port

* Test flaky setup

* Clean up

* Unpend tests

* Unpend unit tests and linting

* Remove extra #

* Address @gesa's PR comments

* update npmignore

* Remove unnecessary line break

* Fix README

* Remove $ from docs

* Use sauceconnect in repo instead of travis

* Update Gemfile.lock
  • Loading branch information
crookedneighbor authored May 21, 2019
1 parent 9f7195b commit 8819e65
Show file tree
Hide file tree
Showing 14 changed files with 364 additions and 275 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SAUCE_USERNAME=your-user-name
SAUCE_ACCESS_KEY=your-access-key
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
scripts/
spec/
test/
config/
Expand All @@ -12,3 +13,8 @@ gulpfile.js
.rvmrc
bower.json
.npmignore
.env.example
.ruby-version
publish-gh-pages.sh
.github/ISSUE_TEMPLATE.md

12 changes: 3 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
language: node_js
before_install:
# See https://github.com/travis-ci/travis-ci/issues/5092#issuecomment-171777646
# Dirty hack for https://github.com/travis-ci/travis-ci/issues/5092
- >
PATH=`echo $PATH | sed "s/\.\/node_modules\/\.bin//g"`;
export PATH=$PATH:./node_modules/.bin;
touch .env;
if [ $IS_INTEGRATION_TEST ]; then rvm install ruby-2.4.3 --binary && rvm use ruby-2.4.3 && bundle install; else echo "Not an integration test. Skipping Ruby setup"; fi
script: npm run $TEST
addons:
sauce_connect: true
hosts:
- restricted-input.bt.local
notifications:
email: false
slack:
Expand All @@ -19,9 +15,7 @@ env:
matrix:
- TEST="lint"
- TEST="test:unit"
- TEST="test:integration" PLATFORM="desktop" IS_INTEGRATION_TEST=true
# iOS tests on Travis are flaky. Run these manually before merging something in
# - TEST="test:integration" PLATFORM="ios" IS_INTEGRATION_TEST=true
- TEST="test:integration" IS_INTEGRATION_TEST=true HOSTNAME=restricted-input.bt.local
global:
- secure: SvjZyrdqFJBWCgduVObookkrTLIer/OF4yILB5uy5DuzDT52vmUGLKWj1Zjevy6PKdoZ3QPdrbrEn8tIRuiiTCbBTi9X3X8cQjVHN1Jxq1w/TIUiCxg1Wt+M+FnS2EamLMo2BFEsCM5qXrLwUd23uLXxMRJKDikBvaq1Lgib+S3CDhROORgEtnZeXXd328NiUNriDadhnC7kTACZ16Urt9ZrTJrXwQLujNJlO/zVxB0dBTV8Hzjp/Qce/D3XFg943xeHj7UuffF9ntcJqGEImY226VVWwk3D78j9zpfOXCIBJD/h/uls77eZzSi/9o2voVqfWHGuuKoRfVC8772kuWoe95Fm8ntFUbEWutDnfhs7aMqSW4rYMbFUSMqf6qBGWse07clk6zx0cZpsC1vscf3QSDQu/joj8ohX6+1Qn4gd+1/Rp3WjLBdWUcTfcODLspahwXZ5xnkzU04m46eO23E++U6WYD22xJnHZVsWHM+aGcDRQYFg07mnzOQwSUs66qXpMLCiL4vFiZ4tTehzTD3iMNF+3cr8WDlgFUH9rNBJjzYJeCOycdxwQg9f7orh/Iwm8TdcWQAxpXaWdfa6KidY/4fDi7gCCoxePjuDHnDXt8e+xlMYIM3fy+xfHb7GWCyGnHdQRxLEPFSTPnTDyWVcg7CSbGl9YmqMRa7SMus=
- secure: u5obPww8nFh3zcov6B9jBj/7LldTT+jOWOUQv/MxE65G6dFWhyJIiNSG/f7HtYr/ziY77B5a+SIoYd097G5lqrtMj128cCGvamdXye0d3YzrbtVGiN7wS3cXPlRPORcaPhQkRl4tQPsElj742f9FRWXsXLdGDzmpPAJDO0lBk9SZuRfdNvw9nTvoHHZgQxu2/lHaMie6v2B3iXSgmgtTN5r6qXXlDoCxZlCB+4cVY2SVNAwXoNk3DDBYsWdOAzVWaOO28l1NaH5CAoKHpz9x1YjjOdHBER5mG2EogQ5Mo4/CAsO9VuEL5Mp0sfhEG7tPXdM0GktFxiRSGfYGIbaMkRUA2npwhj0cWBPdPGaMTQHZI/anr8VHaxUlEP84gXw8VvavttBpaDS/Wdz5dIy5cbqB2q3xhE0VGaR2fG39O/MA+Oq89ZUhThgS8YqltMOKe5AYM3nIeQje61NUpb7FC5q6VLuIKVfSyak2r+TFSVdI27DwU8/QrTIItl1yYJh9eASMX2VIudUahxz0twK7jXuLc9zYtOHgH4bty997G1Z/sr7vu6upyz6081p2tdPDWXzSVIU0HfLj8wRCFnvI8rkKOWfJUGg8ikKJcWoJON3Q59LiuqnEafDiehUnnuueHw5FRi8gcmw82PvFxtoQLzIxfPPNy8k7P2ghsormLjU=
11 changes: 4 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ gem "rake"

group :development do
gem "dotenv"
# The sauce gem uses driver.within_frame which
# is deprecayed in v2.8.0, so we pin to 2.7.1
gem "capybara", "2.7.1"
gem "sauce"
gem "sauce-connect"
gem "selenium-webdriver"
gem "rspec"
gem 'capybara', '>= 3.16.2'
gem "parallel_tests"
gem "rspec-retry"
gem 'rspec'
gem 'sauce_whisk'
gem 'selenium-webdriver'
end
119 changes: 50 additions & 69 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,103 +3,84 @@ GEM
specs:
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
capybara (2.7.1)
capybara (3.20.2)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
childprocess (0.9.0)
ffi (~> 1.0, >= 1.0.11)
cmdparse (3.0.4)
diff-lcs (1.2.5)
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (~> 1.2)
xpath (~> 3.2)
childprocess (1.0.1)
rake (< 13.0)
diff-lcs (1.3)
domain_name (0.5.20180417)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.1.0)
ffi (1.10.0)
highline (1.7.10)
dotenv (2.7.2)
http-cookie (1.0.3)
domain_name (~> 0.5)
json (1.8.6)
mime-types (2.99.3)
json (2.2.0)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2019.0331)
mini_mime (1.0.1)
mini_portile2 (2.4.0)
net-http-persistent (2.9.4)
net-ssh (3.2.0)
net-ssh-gateway (1.3.0)
net-ssh (>= 2.6.5)
netrc (0.11.0)
nokogiri (1.10.1)
nokogiri (1.10.3)
mini_portile2 (~> 2.4.0)
parallel (1.13.0)
parallel_tests (1.3.7)
parallel (1.17.0)
parallel_tests (2.29.0)
parallel
public_suffix (3.0.3)
rack (2.0.6)
rack (2.0.7)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rake (10.4.2)
rest-client (1.8.0)
rake (12.3.2)
regexp_parser (1.5.0)
rest-client (2.0.2)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rspec (3.4.0)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
rspec-mocks (~> 3.4.0)
rspec-core (3.4.1)
rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-mocks (3.4.1)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-retry (0.4.5)
rspec-core
rspec-support (3.4.1)
rspec-support (~> 3.8.0)
rspec-retry (0.6.1)
rspec-core (> 3.3)
rspec-support (3.8.0)
rubyzip (1.2.2)
sauce (3.7.2)
childprocess (>= 0.1.6)
cmdparse (>= 2.0.2)
highline (>= 1.5.0)
json (>= 1.2.0)
net-http-persistent
net-ssh
net-ssh-gateway
parallel_tests (>= 1.1.1, <= 1.3.7)
rest-client
sauce_whisk (~> 0.0.11)
selenium-webdriver (>= 0.1.2)
sauce-connect (3.6.2)
sauce (~> 3.5)
sauce_whisk (0.0.22)
json (>= 1.8)
rest-client (>= 1.8)
selenium-webdriver (2.53.4)
childprocess (~> 0.5)
rubyzip (~> 1.0)
websocket (~> 1.0)
sauce_whisk (0.2.1)
json
rest-client (~> 2.0)
selenium-webdriver (3.142.3)
childprocess (>= 0.5, < 2.0)
rubyzip (~> 1.2, >= 1.2.2)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5)
websocket (1.2.8)
xpath (2.1.0)
nokogiri (~> 1.3)
unf_ext (0.0.7.6)
xpath (3.2.0)
nokogiri (~> 1.8)

PLATFORMS
ruby

DEPENDENCIES
capybara (= 2.7.1)
capybara (>= 3.16.2)
dotenv
parallel_tests
rake
rspec
rspec-retry
sauce
sauce-connect
sauce_whisk
selenium-webdriver

BUNDLED WITH
1.16.6
1.17.3
40 changes: 33 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,51 @@ Try the latest version of Restricted Input [here](https://braintree.github.io/re
**Install dependencies**

```bash
$ npm i
nvm use # if you have node version manager installed
npm i
```

**Watch files and run server**
**Watch files and run demo server**

```bash
$ npm run development
npm run development
```

This will start a server on port `3099` which can be overridden with the `PORT` env var.

**Run tests**
**Unit tests**

There are unit tests:
The following command will run the linting task and the unit tests.

```bash
$ npm t
```sh
npm test
```

**Integration tests**

First, [sign up for a free open source Sauce Labs account](https://saucelabs.com/open-source).

Copy the `.env.example` file to `.env`

```sh
cp .env.example .env
```

Fill in the SAUCE_USERNAME and SAUCE_ACCESS_KEY environmental variables with your credentials:

```sh
SAUCE_USERNAME=your-user-name
SAUCE_ACCESS_KEY=your-access-key
```

Run the integration tests:

```sh
npm run test:integration
```

This will spin up the demo app, as well as open a sauce connect tunnel to forward the app to sauce labs so that the [Capybara](https://teamcapybara.github.io/capybara/) [integration tests](https://github.com/braintree/restricted-input/blob/master/spec/restricted_input_spec.rb) can run.

## Usage

```javascript
Expand Down
81 changes: 80 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1 +1,80 @@
require "sauce"
# adapted from https://github.com/saucelabs-sample-test-frameworks/Ruby-RSpec-Capybara/blob/680e533d80fa850a6906dd383d7440367a65bb30/Rakefile

require 'rspec/core/rake_task'

#
# For use in building a unique Build Name for running tests in parallel on Sauce Labs from a local machine
#
ENV['SAUCE_START_TIME'] = "Restricted Input: Local-#{Time.now.to_i}"

PORT = ENV['PORT'] || 3099
SAUCE_CONNECT_PORT = 4445

@build_success = true

PLATFORMS = {
"windows_ie9" => "Windows 7 IE9",
"windows_ie10" => "Windows 8.1 IE10",
"windows_ie11" => "Windows 10 IE11",
"windows_10_chrome" => "Windows 10 Chrome",
"windows_10_ff" => "Windows 10 Firefox",
"mac_mojave_safari" => "Mac OS 10.14 Safari"
}

$pids = []

def spawn_until_port(cmd, port)
`lsof -i :#{port}`
if $? != 0
puts "[STARTING] #{cmd} on #{port}"
$pids.push spawn(cmd, :out => "/dev/null")
wait_port(port)
end
puts "[RUNNING] #{cmd} on #{port}"
end

def wait_port(port)
loop do
`lsof -i :#{port}`
sleep 2
break if $? == 0
end
end

PLATFORMS.each do |platform_key, browser_name|
desc "Run tests using #{browser_name}"
task platform_key do
ENV['PLATFORM'] = platform_key
begin
@result = system 'rspec spec/restricted_input_spec.rb'
ensure
@build_success &= @result
end
end
end

desc "Starts up demo app and sauceconnect process"
task "setup_tests" do
spawn_until_port("npm run development", PORT)
spawn_until_port("npm run sauceconnect", SAUCE_CONNECT_PORT)
end

desc "Kills app and sauceconnect process"
task "teardown_tests" do
$pids.each do |pid|
Process.kill("INT", pid)
end
end

desc "Run all browser tests"
multitask "all_browsers": PLATFORMS.keys do
begin
raise StandardError, 'Tests failed!' unless @build_success
ensure
@build_success &= @result
end
end

task "test" => ["setup_tests", "all_browsers", "teardown_tests"]

task :default => [:test]
Loading

0 comments on commit 8819e65

Please sign in to comment.