瀏覽代碼

feat: init npx ng e2e

RyaneMax 9 月之前
父節點
當前提交
89efb91354
共有 9 個文件被更改,包括 926 次插入6 次删除
  1. 41 4
      angular.json
  2. 10 0
      cypress.config.ts
  3. 6 0
      cypress/e2e/spec.cy.ts
  4. 5 0
      cypress/fixtures/example.json
  5. 43 0
      cypress/support/commands.ts
  6. 17 0
      cypress/support/e2e.ts
  7. 8 0
      cypress/tsconfig.json
  8. 789 0
      package-lock.json
  9. 7 2
      package.json

+ 41 - 4
angular.json

@@ -32,7 +32,8 @@
               }
             ],
             "styles": [
-              "src/global.scss", "src/theme/variables.scss"
+              "src/global.scss",
+              "src/theme/variables.scss"
             ],
             "scripts": []
           },
@@ -113,7 +114,10 @@
                 "output": "./svg"
               }
             ],
-            "styles": ["src/global.scss", "src/theme/variables.scss"],
+            "styles": [
+              "src/global.scss",
+              "src/theme/variables.scss"
+            ],
             "scripts": []
           },
           "configurations": {
@@ -131,13 +135,46 @@
               "src/**/*.html"
             ]
           }
+        },
+        "cypress-run": {
+          "builder": "@cypress/schematic:cypress",
+          "options": {
+            "devServerTarget": "app:serve"
+          },
+          "configurations": {
+            "production": {
+              "devServerTarget": "app:serve:production"
+            }
+          }
+        },
+        "cypress-open": {
+          "builder": "@cypress/schematic:cypress",
+          "options": {
+            "watch": true,
+            "headless": false
+          }
+        },
+        "e2e": {
+          "builder": "@cypress/schematic:cypress",
+          "options": {
+            "devServerTarget": "app:serve",
+            "watch": true,
+            "headless": false
+          },
+          "configurations": {
+            "production": {
+              "devServerTarget": "app:serve:production"
+            }
+          }
         }
       }
     }
   },
   "cli": {
     "schematicCollections": [
-      "@ionic/angular-toolkit"
+      "@cypress/schematic",
+      "@ionic/angular-toolkit",
+      "@schematics/angular"
     ],
     "analytics": false
   },
@@ -149,4 +186,4 @@
       "styleext": "scss"
     }
   }
-}
+}

+ 10 - 0
cypress.config.ts

@@ -0,0 +1,10 @@
+import { defineConfig } from 'cypress'
+
+export default defineConfig({
+  
+  e2e: {
+    'baseUrl': 'http://localhost:4200'
+  },
+  
+  
+})

+ 6 - 0
cypress/e2e/spec.cy.ts

@@ -0,0 +1,6 @@
+describe('My First Test', () => {
+  it('Visits the initial project page', () => {
+    cy.visit('/')
+    cy.contains('app is running')
+  })
+})

+ 5 - 0
cypress/fixtures/example.json

@@ -0,0 +1,5 @@
+{
+    "name": "Using fixtures to represent data",
+    "email": "hello@cypress.io"
+}
+ 

+ 43 - 0
cypress/support/commands.ts

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

+ 17 - 0
cypress/support/e2e.ts

@@ -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 - 0
cypress/tsconfig.json

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

文件差異過大導致無法顯示
+ 789 - 0
package-lock.json


+ 7 - 2
package.json

@@ -9,7 +9,10 @@
     "build": "ng build",
     "watch": "ng build --watch --configuration development",
     "test": "ng test",
-    "lint": "ng lint"
+    "lint": "ng lint",
+    "e2e": "ng e2e",
+    "cypress:open": "cypress open",
+    "cypress:run": "cypress run"
   },
   "private": true,
   "dependencies": {
@@ -50,6 +53,7 @@
     "@angular/language-service": "^18.0.0",
     "@capacitor/cli": "6.1.0",
     "@compodoc/compodoc": "^1.1.25",
+    "@cypress/schematic": "^2.5.2",
     "@ionic/angular-toolkit": "^11.0.1",
     "@types/jasmine": "~5.1.0",
     "@types/parse": "^3.0.9",
@@ -66,7 +70,8 @@
     "karma-coverage": "~2.2.0",
     "karma-jasmine": "~5.1.0",
     "karma-jasmine-html-reporter": "~2.1.0",
-    "typescript": "~5.4.0"
+    "typescript": "~5.4.0",
+    "cypress": "latest"
   },
   "description": "An Ionic project"
 }

部分文件因文件數量過多而無法顯示