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

[WIP] Cypress on Travis #7201

Closed
Closed
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
3 changes: 3 additions & 0 deletions .cypress.ci.env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"disable_screenshots": "true"
}
3 changes: 3 additions & 0 deletions .cypress.dev.env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"disable_screenshots": "false"
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ config/webpack/paths.json
*.sw[po]
cypress/screenshots
cypress/videos
cypress.env.json
9 changes: 3 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ addons:
chrome: beta
env:
matrix:
- TEST_SUITE=spec
- TEST_SUITE=spec:routes
- TEST_SUITE=spec:javascript
- TEST_SUITE=spec:compile
- TEST_SUITE=spec:jest
- TEST_SUITE=spec:debride
- TEST_SUITE=spec:cypress
matrix:
exclude:
- rvm: 2.5.7
Expand All @@ -32,6 +27,8 @@ matrix:
env: TEST_SUITE=spec:jest
- rvm: 2.5.7
env: TEST_SUITE=spec:debride
- rvm: 2.5.7
env: TEST_SUITE=spec:cypress
bundler_args: "--no-deployment"
before_install: source tools/ci/before_install.sh
install: bin/setup
Expand Down
21 changes: 21 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ namespace :spec do
desc "Run all javascript specs"
task :javascript => ["app:test:initialize", :environment, "jasmine:ci"]

desc "Run all cypress specs"
task :cypress => ["app:cypress:ui:run"]

namespace :cypress do
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For those who might re-reviewing this again, this section was mostly to running get things running via manageiq-cross_repo-tests PR I have been using:

ManageIQ/manageiq-cross_repo-tests#150

I was trying to write too much bash scripting inside of environment variables, so this was a much easier way to not only debug, but also my idea standardize things a bit using rake.

That said, this probably won't be needed if we are running things from this repo, and I expect this is probably not a preferred way of doing things by most, so we can remove this once the core changes have been merged. I can always archive this commit somewhere to consider as an option in the future.

task :ci => ["ci:set_node_path", "app:cypress:ui:seed", "spec:cypress"]

task "ci:install_yarn" do
sh "/bin/bash", "-c", "source ~/.nvm/nvm.sh && nvm install 12 && npm install -g yarn"
end

task "ci:set_node_path" do
ENV["PATH"] = "#{Dir.glob("/home/travis/.nvm/versions/node/v12*").sort.last}/bin:#{ENV["PATH"]}"
# puts;puts;puts
# puts ">>>>>> PATH: #{ENV["PATH"]}"
# puts;puts;puts
end

desc "Setup for CI"
task "ci:setup" => ["ci:install_yarn", "ci:set_node_path", "update:ui"]
end

desc "Try to compile assets"
task :compile => ["app:assets:precompile"]

Expand Down
4 changes: 2 additions & 2 deletions bin/webpack
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ require "yaml"
ENV["RAILS_ENV"] ||= "development"
RAILS_ENV = ENV["RAILS_ENV"]

ENV["NODE_ENV"] ||= RAILS_ENV
ENV["NODE_ENV"] ||= RAILS_ENV == "integration" ? "production" : RAILS_ENV
NODE_ENV = ENV["NODE_ENV"]

APP_PATH = File.expand_path("../", __dir__)
NODE_MODULES_PATH = File.join(APP_PATH, "node_modules")
WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/#{NODE_ENV}.js")
WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/#{RAILS_ENV}.js")

unless File.exist?(WEBPACK_CONFIG)
puts "Webpack configuration not found."
Expand Down
11 changes: 11 additions & 0 deletions config/webpack/integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Note: You must restart bin/webpack-dev-server for changes to take effect

/* eslint global-require: 0 */

const { env } = require('process')

if (env.CYPRESS_DEV) {
module.exports = require('./development.js')
} else {
module.exports = require('./production.js')
}
9 changes: 9 additions & 0 deletions config/webpacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,14 @@ development:
test:
<<: *default

integration:
<<: *default

# uncomment these to enable webpack:server
dev_server:
host: 0.0.0.0
port: 8080
https: false

production:
<<: *default
7 changes: 7 additions & 0 deletions cypress/support/assertions/expect_title.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Cypress.Commands.add("expect_explorer_title", (text) => {
return cy.get('#explorer_title_text').contains(text);
});

Cypress.Commands.add("expect_show_list_title", (text) => {
return cy.get('#main-content h1').contains(text);
});
198 changes: 0 additions & 198 deletions cypress/support/commands.js

This file was deleted.

18 changes: 18 additions & 0 deletions cypress/support/commands/explorer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// cy.accordion('Catalog Items') - click accordion, unless already expanded
Cypress.Commands.add('accordion', (text) => {
cy.get('#main-content'); // ensure screen loads first

let ret = cy.get('#accordion')
.find('.panel-title a')
.contains(new RegExp(`^${text}$`))

ret.then((el) => {
// do not collapse if expanded
if (el.is('.collapsed')) {
el.click();
}
return el;
});

return ret.parents('.panel');
});
22 changes: 22 additions & 0 deletions cypress/support/commands/gtl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// GTL related helpers
Cypress.Commands.add("gtl_error", () => {
return cy.get('#miq-gtl-view > #flash_msg_div').should('be.visible');
});

Cypress.Commands.add("gtl_no_record", () => {
return cy.get('#miq-gtl-view > div.no-record').should('be.visible');
});

Cypress.Commands.add("gtl", () => {
cy.get('#miq-gtl-view').then($gtlTile => {
if ($gtlTile.find("miq-tile-view").length > 0) {
return cy.get("div[pf-card-view] > .card-view-pf > .card");
} else {
return cy.get('#miq-gtl-view > miq-data-table > div > table');
};
});
});

Cypress.Commands.add("gtl_click", (name) => {
cy.gtl().contains(name).click()
});
10 changes: 10 additions & 0 deletions cypress/support/commands/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// cy.login() - log in
// FIXME: use cy.request and inject cookie and localStorage.miqToken
Cypress.Commands.add("login", (user = 'admin', password = 'smartvm') => {
cy.visit('/');

cy.get('#user_name').type(user);
cy.get('#user_password').type(password);
return cy.get('#login').click();
});

Loading