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

test(Example): add cypress tests #1565

Merged
merged 11 commits into from
Feb 25, 2019
Merged
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
24 changes: 20 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ version: 2
# See https://blog.daemonl.com/2016/02/yaml.html
# To validate changes, use an online parser, eg.
# https://yaml-online-parser.appspot.com/
var_1: &cache_key yarn-cache-{{ checksum "yarn.lock" }}-0.8.0
var_1: &cache_key yarn-cache-{{ checksum "yarn.lock" }}-0.9.0
var_2: &run_in_node
docker:
- image: circleci/node:10.12
Expand Down Expand Up @@ -81,14 +81,28 @@ jobs:
- run: yarn copy:schematics
- run: git diff --name-only --exit-code ./modules
- run: yarn run ci
- run: yarn run example:build:prod
- run: yarn run example:test --watch=false
- save_cache:
key: *cache_key
paths:
- ~/.cache/yarn
- node_modules

e2e_test:
docker:
- image: circleci/node:10.12-browsers
steps:
- checkout
- restore_cache:
key: *cache_key
- run: yarn
- run: yarn run example:build:prod
- run: yarn run example:cypress:ci
- save_cache:
key: *cache_key
paths:
- ~/.cache/Cypress

docs:
<<: *run_in_node
working_directory: ~/docs/projects/ngrx.io
Expand Down Expand Up @@ -118,7 +132,7 @@ jobs:
steps:
- add_ssh_keys:
fingerprints:
- 'c9:c2:b4:5e:13:23:b6:6d:d8:29:3e:68:c6:40:9c:ec'
- "c9:c2:b4:5e:13:23:b6:6d:d8:29:3e:68:c6:40:9c:ec"
- checkout:
path: ~/docs
- restore_cache:
Expand All @@ -143,7 +157,7 @@ jobs:
steps:
- add_ssh_keys:
fingerprints:
- 'c9:c2:b4:5e:13:23:b6:6d:d8:29:3e:68:c6:40:9c:ec'
- "c9:c2:b4:5e:13:23:b6:6d:d8:29:3e:68:c6:40:9c:ec"
- checkout
- restore_cache:
key: *cache_key
Expand All @@ -159,12 +173,14 @@ workflows:
- lint
- bazel
- test
- e2e_test
- docs
- docs-preview
- deploy:
requires:
- docs
- test
- e2e_test
- bazel
filters:
branches:
Expand Down
25 changes: 0 additions & 25 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,6 @@
}
}
}
},
"example-app-e2e": {
"root": "projects/example-app-e2e/",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "projects/example-app-e2e/protractor.conf.js",
"devServerTarget": "example-app:serve"
},
"configurations": {
"production": {
"devServerTarget": "example-app:serve:production"
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "projects/example-app-e2e/tsconfig.e2e.json",
"exclude": ["**/node_modules/**"]
}
}
}
}
},
"schematics": {
Expand Down
14 changes: 14 additions & 0 deletions build/example-app-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const express = require('express');
const path = require('path');

const CONTEXT = `/${process.env.CONTEXT || 'platform/example-app'}`;
const PORT = process.env.PORT || 4000;
const DIST = path.join(__dirname, '../projects/example-app/dist');

const app = express();

app.use(CONTEXT, express.static(DIST));
app.use('/', express.static(DIST));
app.listen(PORT, () =>
console.log(`App running on http://localhost:${PORT}${CONTEXT}`)
);
18 changes: 16 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
"example:start": "yarn run cli serve",
"example:start:aot": "yarn run cli serve --prod",
"example:test": "jest -c projects/example-app/jest.config.js --watch",
"example:build":"yarn cli build --prod",
"example:cypress:open": "cypress open --project=projects/example-app-cypress",
"example:cypress:run": "cypress run --project=projects/example-app-cypress",
"example:cypress:ci": "npm-run-all --parallel --race example:server \"example:cypress:run -- --config=baseUrl=http://localhost:4000\"",
"example:build": "yarn cli build --prod",
"example:build:prod": "yarn example:build -- --base-href \"/platform/example-app/\"",
"example:server": "node build/example-app-server",
Copy link
Member

Choose a reason for hiding this comment

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

Move this into the group with the other example: scripts

"ci": "yarn run test && nyc report --reporter=text-lcov | coveralls",
"prettier": "prettier --write \"**/*.ts\"",
"watch:tests": "chokidar \"modules/**/*.ts\" --initial --command \"yarn run test:unit\"",
Expand Down Expand Up @@ -93,6 +97,7 @@
"devDependencies": {
"@angular-devkit/build-angular": "^0.10.0",
"@bazel/bazel": "^0.19.1",
"@cypress/webpack-preprocessor": "^4.0.3",
"@octokit/rest": "^15.17.0",
"@types/fs-extra": "^2.1.0",
"@types/glob": "^5.0.33",
Expand All @@ -112,11 +117,13 @@
"conventional-changelog-cli": "^1.3.21",
"coveralls": "^2.13.0",
"cpy-cli": "^1.0.1",
"cypress": "^3.1.2",
"deep-freeze": "^0.0.1",
"deep-freeze-strict": "^1.1.1",
"express": "^4.16.4",
"fs-extra": "^2.1.2",
"glob": "^7.1.2",
"husky": "^0.14.3",
"husky": "^1.2.0",
"jasmine": "^2.5.3",
"jasmine-core": "~2.5.2",
"jasmine-marbles": "^0.4.0",
Expand All @@ -132,6 +139,7 @@
"karma-jasmine-html-reporter": "^0.2.2",
"lint-staged": "^8.0.0",
"ncp": "^2.0.0",
"npm-run-all": "^4.1.5",
"nyc": "^10.1.2",
"ora": "^1.3.0",
"prettier": "^1.11.1",
Expand All @@ -141,6 +149,7 @@
"rimraf": "^2.5.4",
"rollup": "^0.50.0",
"sorcery": "^0.10.0",
"ts-loader": "^5.3.3",
"ts-node": "^5.0.1",
"tsconfig-paths": "^3.1.3",
"tsickle": "^0.32.1",
Expand All @@ -154,5 +163,10 @@
"type": "opencollective",
"url": "https://opencollective.com/ngrx",
"logo": "https://opencollective.com/opencollective/logo.txt"
},
"resolutions": {
"listr": "^0.14.2",
"listr-update-renderer": "^0.5.0",
"listr-verbose-renderer": "^0.5.0"
}
}
10 changes: 10 additions & 0 deletions projects/example-app-cypress/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"baseUrl": "http://localhost:4200",
"fixturesFolder": "fixtures",
"integrationFolder": "integration",
"pluginsFile": "plugins/index.js",
"supportFile": "support/index.js",
"screenshotsFolder": "screenshots",
"videosFolder": "videos",
"video": false
}
71 changes: 71 additions & 0 deletions projects/example-app-cypress/integration/round-trip.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
context('Full round trip', () => {
before(() => {
window.indexedDB.deleteDatabase('books_app');
cy.visit('/');
});

it('shows a message when the credentials are wrong', () => {
cy.get('[placeholder=Username]').type('wronguser');
cy.get('[placeholder=Password]').type('supersafepassword');
cy.get('[type="submit"]').click();

cy.contains('Invalid username or password').should('be.visible');
});

it('is possible to login', () => {
cy.get('[placeholder=Username]')
.clear()
.type('test');
cy.get('[type="submit"]').click();
});

it('is possible to search for books', () => {
cy.contains('My Collection');
cy.contains('menu').click();
cy.contains('Browse Books').click();

cy.get('[placeholder="Search for a book"]').type('The Alchemist');
cy.get('bc-book-preview')
.its('length')
.should('be.gte', 1);
});

it('is possible to add books', () => {
cy.get('bc-book-preview')
.eq(2)
.click();

cy.contains('Add Book to Collection').click();
cy.contains('Add Book to Collection').should('not.exist');
});

it('is possible to remove books', () => {
cy.go('back');

cy.get('bc-book-preview')
.eq(4)
.click();

cy.contains('Add Book to Collection').click();
cy.contains('Remove Book from Collection').click();
cy.contains('Remove Book from Collection').should('not.exist');
});

it('is possible to show the collection', () => {
cy.contains('menu').click();
cy.contains('My Collection').click();

cy.get('bc-book-preview')
.its('length')
.should('be', 1);
});

it('is possible to sign out', () => {
cy.contains('menu').click();
cy.contains('Sign Out').click();
cy.contains('OK').click();

cy.get('[placeholder=Username]').should('exist');
cy.get('[placeholder=Password]').should('exist');
});
});
26 changes: 26 additions & 0 deletions projects/example-app-cypress/plugins/cy-ts-preprocessor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const wp = require('@cypress/webpack-preprocessor');

const webpackOptions = {
resolve: {
extensions: ['.ts', '.js'],
},
module: {
rules: [
{
test: /\.ts$/,
exclude: [/node_modules/],
use: [
{
loader: 'ts-loader',
},
],
},
],
},
};

const options = {
webpackOptions,
};

module.exports = wp(options);
5 changes: 5 additions & 0 deletions projects/example-app-cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const cypressTypeScriptPreprocessor = require('./cy-ts-preprocessor');

module.exports = on => {
on('file:preprocessor', cypressTypeScriptPreprocessor);
};
Empty file.
13 changes: 13 additions & 0 deletions projects/example-app-cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"strict": true,
"baseUrl": "../../node_modules",
"target": "es5",
"experimentalDecorators": true,
"skipLibCheck": true,
"noImplicitAny": false,
"lib": ["es6", "dom"],
"types": ["cypress"]
},
"include": ["**/*.ts"]
}
31 changes: 0 additions & 31 deletions projects/example-app-e2e/protractor.conf.js

This file was deleted.

14 changes: 0 additions & 14 deletions projects/example-app-e2e/src/app.e2e-spec.ts

This file was deleted.

11 changes: 0 additions & 11 deletions projects/example-app-e2e/src/app.po.ts

This file was deleted.

14 changes: 0 additions & 14 deletions projects/example-app-e2e/tsconfig.e2e.json

This file was deleted.

Loading