Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Improve cypress setup

  • Loading branch information...
brtjkzl committed Oct 21, 2018
1 parent 69ae1c5 commit 025072e7a8970af5eb723c46691e7811aca09b23
@@ -27,7 +27,7 @@
"env": {
"production": {
"plugins": [
["react-remove-properties", { "properties": ["data-test"] }],
["react-remove-properties", { "properties": ["data-cy"] }],
"transform-react-remove-prop-types"
]
},
@@ -29,3 +29,8 @@
/node_modules
yarn-debug.log*
.yarn-integrity

# Ignore cypress files
/public/packs-cypress
/cypress/videos
/cypress/screenshots
@@ -12,16 +12,15 @@
$ brew install hivemind
$ bundle install
$ yarn install
$ rails db:setup
$ yarn setup
$ yarn start
```

## Test

```sh
$ rails test
$ yarn test
$ yarn cypress
$ yarn test:cypress
```

## Deployment
@@ -12,7 +12,7 @@ const Button = ({
onClick
}) => (
<$Button
data-test={`button-${type}-${kebabCase(children)}`}
data-cy={`button-${type}-${kebabCase(children)}`}
size={size}
modifier={type}
onClick={onClick}
@@ -5,7 +5,7 @@ import $DropdownItem from "./$DropdownItem";

const DropdownItem = ({ onClick, children, destructive }) => (
<$DropdownItem
data-test={`dropdown-item-${kebabCase(children)}`}
data-cy={`dropdown-item-${kebabCase(children)}`}
onClick={onClick}
destructive={destructive}
>
@@ -59,7 +59,7 @@ class SearchBar extends Component {
onChange={this.updateQuery}
value={query}
type="text"
data-test="search-input"
data-cy="search-input"
/>
<$SearchIcon>
{haveSearchResults ? (
@@ -44,7 +44,7 @@ const GameCard = ({ game, setGameStatus, setGamePlatforms, rateGame }) => {
const isInCollection = status && status !== Status.UNASSIGNED;

return (
<$GameCard data-test={`game-card-${kebabCase(name)}`}>
<$GameCard data-cy={`game-card-${kebabCase(name)}`}>
<GameCover src={cover} />

<$GameRating>
@@ -1,6 +1,5 @@
<% if Rails.env.development? %>
<% unless Rails.env.production? %>
<%= stylesheet_pack_tag 'env' %>

<div class="env">dev</div>
<div class="env"><%= Rails.env %></div>
<% end %>

@@ -1 +1 @@
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QQQbU7p7+5GUZ05myzM9aOmV/lb0dcEDij8M0jsAy6gZ2aY9ixLqI684HoQ9n1YE9hI24mFaNNOne0O9alW9mIr70zijb1udSK/1byjUp4IWTtVJiwCQVbiQaswQ8qOlLdZdf522SgG2j0HzB+Z4EA2Nha2zML55rBlmLYgY79LHqDmYlI7hnQCn5r8asAKze/yDwTxYUB+KkU/zWKWVHYjQCJ4IfOB0x+RochZK3cu8NnASmIGSs/rQLJUyN2kA1Tc6ne3bus4WWaQAGnQYK0oh7KyjTABeZM5qz3PVWiEJDM/pka2wrRIfP8w5T193viJB6PeEL8eHIuiv3M2JwkPoCzghDDzB/wE+MHMDOsGbLEbojgGVVhWXE1WJOeDPY36Gq98KXQeKYCGu0F6Ku+2OShTcyhVgOQMpopaIYuFP1PYTHBnlOj5XvykjUJq806HxBNse/x+hubI4DOlr32NuqjhBWc9orSbKfkmA4SGHkTaMNrJcHzI=--I79RJ3Jp0Gohc55X--TCinLO7pZYyI+NUDdJmGpw==
@@ -11,5 +11,9 @@ test:
<<: *default
database: games_tracker_test

cypress:
<<: *default
database: games_tracker_cypress

production:
url: <%= ENV['DATABASE_URL'] %>
@@ -0,0 +1,51 @@
Rails.application.configure do
# Verifies that versions and hashed value of the package contents in the project's package.json
config.webpacker.check_yarn_integrity = true
# Settings specified here will take precedence over those in config/application.rb.

# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false

# Do not eager load code on boot.
config.eager_load = false

# Show full error reports.
config.consider_all_requests_local = true

# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
if Rails.root.join("tmp", "caching-dev.txt").exist?
config.action_controller.perform_caching = true

config.cache_store = :memory_store
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{2.days.to_i}"
}
else
config.action_controller.perform_caching = false

config.cache_store = :null_store
end

# Store uploaded files on the local file system (see config/storage.yml for options)
# config.active_storage.service = :local

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load

# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true


# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end
@@ -47,18 +47,24 @@ development:
use_local_ip: false
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
"Access-Control-Allow-Origin": "*"
watch_options:
ignored: /node_modules/


test:
<<: *default
compile: true

# Compile test packs to a separate directory
public_output_path: packs-test

cypress:
<<: *default
compile: true

# Compile cypress packs to a separate directory
public_output_path: packs-cypress

production:
<<: *default

@@ -1,4 +1,5 @@
{
"baseUrl": "http://localhost:3000",
"pluginsFile": false
"baseUrl": "http://localhost:4000",
"pluginsFile": false,
"fixturesFolder": false
}

This file was deleted.

@@ -1 +1,4 @@
// TODO test authentication and logout
describe("Authentication", () => {
it.skip("allows to sign in with Facebook", () => {});
it.skip("allows to log out", () => {});
});
@@ -1,46 +1,9 @@
// TODO test collection (adding, removing, unassigned)
// TODO test rating (adding, removing)
// TODO test platforms (adding, removing)

describe("Collection", () => {
it("allows to collect and rate games", () => {
// Search game as logged in user
cy.signIn();
cy.visit("/");
cy.getId("search-input").type("witcher{enter}");
cy.getId("game-card-the-witcher-3-wild-hunt");

// Add game to backlog
cy.getId("game-card-the-witcher-3-wild-hunt")
.findId("button-primary-add-to-collection")
.click();
cy.getId("dropdown-item-backlog").click();

// Rate it for 9
cy.getId("game-card-the-witcher-3-wild-hunt")
.findId("button-primary-rate")
.click();
cy.getId("dropdown-item-9").click();

// Have it on PS4
cy.getId("game-card-the-witcher-3-wild-hunt")
.findId("button-outline-ps-4")
.click();

// Verify the game has been added to the profile
cy.getId("link-profile").click();
cy.getId("game-card-the-witcher-3-wild-hunt").findId(
"button-primary-backlog"
);
cy.getId("game-card-the-witcher-3-wild-hunt").findId("button-primary-9");
cy.getId("game-card-the-witcher-3-wild-hunt").findId("button-primary-ps-4");

// Verify the game is correctly shown on search results
cy.getId("link-home").click({ force: true });
cy.getId("game-card-the-witcher-3-wild-hunt").findId(
"button-primary-backlog"
);
cy.getId("game-card-the-witcher-3-wild-hunt").findId("button-primary-9");
cy.getId("game-card-the-witcher-3-wild-hunt").findId("button-primary-ps-4");
});
it.skip("allows to add to collection", () => {});
it.skip("allows to remove from collection", () => {});
it.skip("shows unassigned collection", () => {});
it.skip("allows to add rating", () => {});
it.skip("allows to remove rating", () => {});
it.skip("allows to add platform", () => {});
it.skip("allows to remove platform", () => {});
});
@@ -1,11 +1,9 @@
// TODO test search

describe("Search", () => {
it("works", () => {
it("allows to find games", () => {
cy.visit("/");
cy.getId("search-input").type("witcher{enter}");
cy.getId("game-card-the-witcher-3-wild-hunt");
cy.getId("game-card-the-witcher-2-assassins-of-kings");
cy.getId("game-card-the-witcher");
cy.getNode("search-input").type("witcher{enter}");
cy.getNode("game-card-the-witcher-3-wild-hunt-game-of-the-year-edition");
cy.getNode("game-card-the-witcher-3-wild-hunt");
cy.getNode("game-card-the-witcher-2-assassins-of-kings");
});
});
@@ -1,15 +1,5 @@
Cypress.Commands.add("getId", id => cy.get(`[data-test="${id}"]`));
Cypress.Commands.add("getNode", testId => cy.get(`[data-cy="${testId}"]`));

Cypress.Commands.add("findId", { prevSubject: true }, (subject, id) =>
subject.find(`[data-test="${id}"]`)
Cypress.Commands.add("findNode", { prevSubject: true }, (subject, testId) =>
subject.find(`[data-cy="${testId}"]`)
);

Cypress.Commands.add("signIn", () => {
cy.fixture("authCookie").then(authCookie => {
cy.setCookie("auth", encodeURIComponent(JSON.stringify(authCookie)));
});
});

Cypress.Commands.add("signOut", () => {
cy.clearCookies();
});
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"allowJs": true,
"baseUrl": "../node_modules",
"types": ["cypress"]
},
"include": ["**/*.*"]
}
@@ -6,3 +6,5 @@
{ igdb: 12, slug: "X360" },
{ igdb: 130, slug: "NSW" }
])

User.create(email: "bkzl@me.com")
@@ -2,12 +2,19 @@
"name": "games-tracker",
"private": true,
"scripts": {
"analyze": "source-map-explorer",
"cypress": "cypress open",
"bundle-size": "source-map-explorer",
"lint": "eslint app/client/",
"setup": "bundle exec rails db:setup",
"start": "hivemind Procfile.dev",
"test": "jest --watch",
"test:ci": "jest --ci"
"test": "yarn test:api && yarn test:client:ci",
"test:api": "bundle exec rails test",
"test:client": "jest --watch",
"test:client:ci": "jest --ci",
"cypress": "start-server-and-test cypress:server http://localhost:4000 cypress:open",
"cypress:ci": "start-server-and-test cypress:server http://localhost:4000 cypress:run",
"cypress:open": "cypress open",
"cypress:run": "cypress run",
"cypress:server": "bundle exec rails server -p 4000 -e cypress"
},
"dependencies": {
"@rails/webpacker": "3.5",
@@ -34,14 +41,15 @@
},
"devDependencies": {
"babel-eslint": "^8.2.6",
"cypress": "^3.0.3",
"cypress": "3.1.0",
"eslint": "^5.3.0",
"eslint-plugin-cypress": "^2.0.1",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-jest": "^21.18.0",
"eslint-plugin-react": "^7.10.0",
"jest": "^23.4.2",
"source-map-explorer": "^1.5.0",
"start-server-and-test": "^1.7.4",
"webpack-dev-server": "2.11.2"
}
}

0 comments on commit 025072e

Please sign in to comment.
You can’t perform that action at this time.