Skip to content

Commit

Permalink
Merge pull request #487 from webcat12345/cypress
Browse files Browse the repository at this point in the history
test(e2e): Replace protractor with cypress
  • Loading branch information
cmckni3 authored Nov 1, 2023
2 parents 996ff1c + 8ddae7a commit 47c148e
Show file tree
Hide file tree
Showing 17 changed files with 685 additions and 484 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Build

on: [push]
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/deploy-github-pages.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Deploy demo to GitHub pages

on:
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Integration Tests

on:
push:
branches: [master]

jobs:
build-and-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2

- name: Install and Run Integration tests 🧪
run: |
yarn install
yarn e2e:ci
61 changes: 48 additions & 13 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,50 @@
"src/**/*.html"
]
}
}
}
},
"ngx-ui-switch-e2e": {
"root": "",
"sourceRoot": "",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
},
"cypress-run": {
"builder": "@cypress/schematic:cypress",
"options": {
"protractorConfig": "./protractor.conf.js",
"devServerTarget": "ngx-ui-switch:serve"
},
"configurations": {
"production": {
"devServerTarget": "ngx-ui-switch:serve:production"
}
}
},
"cypress-open": {
"builder": "@cypress/schematic:cypress",
"options": {
"watch": true,
"headless": false
}
},
"ct": {
"builder": "@cypress/schematic:cypress",
"options": {
"devServerTarget": "ngx-ui-switch:serve",
"watch": true,
"headless": false,
"testingType": "component"
},
"configurations": {
"development": {
"devServerTarget": "ngx-ui-switch:serve:development"
}
}
},
"e2e": {
"builder": "@cypress/schematic:cypress",
"options": {
"devServerTarget": "ngx-ui-switch:serve",
"watch": true,
"headless": false
},
"configurations": {
"production": {
"devServerTarget": "ngx-ui-switch:serve:production"
}
}
}
}
Expand All @@ -128,6 +159,10 @@
},
"cli": {
"defaultCollection": "@angular-eslint/schematics",
"analytics": false
"analytics": false,
"schematicCollections": [
"@cypress/schematic",
"@schematics/angular"
]
}
}
}
18 changes: 18 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from 'cypress'

export default defineConfig({

e2e: {
'baseUrl': 'http://localhost:4200'
},


component: {
devServer: {
framework: 'angular',
bundler: 'webpack',
},
specPattern: '**/*.cy.ts'
}

})
6 changes: 6 additions & 0 deletions cypress/e2e/app.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
describe('My First Test', () => {
it('Visits the initial project page', () => {
cy.visit('/');
cy.get('.navbar-brand').should('include.text', 'ngx ui switch');
});
});
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]"
}

43 changes: 43 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// ***********************************************
// This example namespace declaration will help
// with Intellisense and code completion in your
// IDE or Text Editor.
// ***********************************************
// declare namespace Cypress {
// interface Chainable<Subject = any> {
// customCommand(param: any): typeof customCommand;
// }
// }
//
// function customCommand(param: any): void {
// console.warn(param);
// }
//
// NOTE: You can use it like so:
// Cypress.Commands.add('customCommand', customCommand);
//
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
12 changes: 12 additions & 0 deletions cypress/support/component-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>Components App</title>
</head>
<body>
<div data-cy-root></div>
</body>
</html>
39 changes: 39 additions & 0 deletions cypress/support/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ***********************************************************
// This example support/component.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands';

// Alternatively you can use CommonJS syntax:
// require('./commands')

import { mount } from 'cypress/angular';

// Augment the Cypress namespace to include type definitions for
// your custom command.
// Alternatively, can be defined in cypress/support/component.d.ts
// with a <reference path="./component" /> at the top of your spec.
declare global {
namespace Cypress {
interface Chainable {
mount: typeof mount;
}
}
}

Cypress.Commands.add('mount', mount);

// Example use:
// cy.mount(MyComponent)
17 changes: 17 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// When a command from ./commands is ready to use, import with `import './commands'` syntax
// import './commands';
8 changes: 8 additions & 0 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"include": ["**/*.ts"],
"compilerOptions": {
"sourceMap": false,
"types": ["cypress"]
}
}
11 changes: 0 additions & 11 deletions e2e/app.po.ts

This file was deleted.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
"cleanup": "rimraf build dist waste deploy demo docs",
"lint": "ng lint",
"e2e": "ng e2e",
"e2e:ci": "ng e2e --protractor-config=protractor-ci.conf.js",
"typedoc": "typedoc --options typedoc.json src/lib/*.ts && ts-node -P tsconfig.build.json docs.ts"
"e2e:ci": "ng run ngx-ui-switch:cypress-run",
"typedoc": "typedoc --options typedoc.json src/lib/*.ts && ts-node -P tsconfig.build.json docs.ts",
"cypress:open": "cypress open",
"cypress:run": "cypress run"
},
"dependencies": {
"@angular/animations": "^16.1.8",
Expand All @@ -61,6 +63,7 @@
"@angular/cli": "^16.1.7",
"@angular/compiler-cli": "^16.1.8",
"@angular/language-service": "^16.1.8",
"@cypress/schematic": "2.5.1",
"@types/jasmine": "^4.3.0",
"@types/jasminewd2": "^2.0.10",
"@types/node": "^18.7.12",
Expand All @@ -77,11 +80,11 @@
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"ng-packagr": "^16.1.0",
"protractor": "~7.0.0",
"sass": "^1.35.1",
"ts-node": "^10.9.1",
"tsickle": "^0.46.3",
"typedoc": "^0.14.2",
"typescript": "^4.9.5"
"typescript": "^4.9.5",
"cypress": "latest"
}
}
35 changes: 0 additions & 35 deletions protractor-ci.conf.js

This file was deleted.

28 changes: 0 additions & 28 deletions protractor.conf.js

This file was deleted.

Loading

0 comments on commit 47c148e

Please sign in to comment.