feat: cypress setup for angular e2e tests

This commit is contained in:
Amadou Ada DIENE
2021-07-20 17:46:47 +02:00
parent 77b15bdfc4
commit 7a3d5d7d3a
11 changed files with 32865 additions and 31024 deletions

View File

@@ -44,6 +44,9 @@
"make": "npm run package:angular-app && electron-forge make", "make": "npm run package:angular-app && electron-forge make",
"publish": "electron-forge publish", "publish": "electron-forge publish",
"lint": "eslint --ext .ts .", "lint": "eslint --ext .ts .",
"test:e2e": "npm run test:angular-e2e && npm run test:electron-e2",
"test:angular-e2e": "npm-run-all -p -r start:angular-app start:angular-e2e",
"start:angular-e2e": "wait-on http://localhost:4200 && cd workspaces/angular-app && npm run cypress:run",
"test:electron-e2e": "npm run package && cross-env X_NODE_ENV=e2e-test node workspaces/electron-e2e/jasmine.js", "test:electron-e2e": "npm run package && cross-env X_NODE_ENV=e2e-test node workspaces/electron-e2e/jasmine.js",
"clean": "shx rm -rf .webpack out node_modules workspaces/shared-lib/.dist workspaces/angular-app/node_modules workspaces/angular-app/.dist", "clean": "shx rm -rf .webpack out node_modules workspaces/shared-lib/.dist workspaces/angular-app/node_modules workspaces/angular-app/.dist",
"version": "npx conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md", "version": "npx conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md",

View File

@@ -93,6 +93,37 @@
"styles": ["src/styles.scss"], "styles": ["src/styles.scss"],
"scripts": [] "scripts": []
} }
},
"cypress-run": {
"builder": "@cypress/schematic:cypress",
"options": {
"devServerTarget": "angular-app:serve"
},
"configurations": {
"production": {
"devServerTarget": "angular-app:serve:production"
}
}
},
"cypress-open": {
"builder": "@cypress/schematic:cypress",
"options": {
"watch": true,
"headless": false
}
},
"e2e": {
"builder": "@cypress/schematic:cypress",
"options": {
"devServerTarget": "angular-app:serve",
"watch": true,
"headless": false
},
"configurations": {
"production": {
"devServerTarget": "angular-app:serve:production"
}
}
} }
} }
} }

View File

@@ -0,0 +1,11 @@
{
"integrationFolder": "cypress/integration",
"supportFile": "cypress/support/index.ts",
"videosFolder": "cypress/videos",
"screenshotsFolder": "cypress/screenshots",
"pluginsFile": "cypress/plugins/index.ts",
"fixturesFolder": "cypress/fixtures",
"baseUrl": "http://localhost:4200",
"screenshotOnRunFailure": false,
"video": false
}

View File

@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}

View File

@@ -0,0 +1,7 @@
describe('My First Test', () => {
it('Visits the initial project page', () => {
cy.visit('/');
cy.contains('Welcome');
cy.contains('electron-angular-quick-start app is running!');
});
});

View File

@@ -0,0 +1,5 @@
// Plugins enable you to tap into, modify, or extend the internal behavior of Cypress
// For more info, visit https://on.cypress.io/plugins-api
module.exports = (_on, _config) => {
// configure plugins here
};

View File

@@ -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) => { ... })

View File

@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/index.js 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';

View File

@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"include": ["**/*.ts"],
"compilerOptions": {
"sourceMap": false,
"types": ["cypress"]
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,10 @@
"version": "2.0.0", "version": "2.0.0",
"scripts": { "scripts": {
"start": "ng serve", "start": "ng serve",
"package": "ng build --configuration production --base-href ./" "package": "ng build --configuration production --base-href ./",
"e2e": "ng e2e",
"cypress:open": "cypress open",
"cypress:run": "cypress run"
}, },
"private": true, "private": true,
"dependencies": { "dependencies": {
@@ -26,12 +29,14 @@
"@angular-devkit/build-angular": "~12.1.2", "@angular-devkit/build-angular": "~12.1.2",
"@angular/cli": "~12.1.2", "@angular/cli": "~12.1.2",
"@angular/compiler-cli": "~12.1.2", "@angular/compiler-cli": "~12.1.2",
"@cypress/schematic": "^1.4.2",
"@types/node": "^12.11.1", "@types/node": "^12.11.1",
"karma": "~6.3.0", "karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0", "karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3", "karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0", "karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "~1.7.0", "karma-jasmine-html-reporter": "~1.7.0",
"typescript": "^4.3.5" "typescript": "^4.3.5",
"cypress": "8.0.0"
} }
} }