Эх сурвалжийг харах

tests(persistence): write cypress tests

Ryan Chandler 4 жил өмнө
parent
commit
031038c8dd

+ 24 - 0
.github/workflows/cypress-tests.yml

@@ -0,0 +1,24 @@
+name: Run Jest tests
+
+on: [pull_request]
+
+jobs:
+  tests:
+
+    runs-on: ubuntu-latest
+
+    strategy:
+      matrix:
+        node-version: [12.x]
+
+    steps:
+      - name: Checkout repository
+        uses: actions/checkout@v1
+
+      - name: Run Cypress
+        uses: cypress-io/github-action@v2
+        with:
+          build: yarn build
+          start: yarn pre-cypress
+          browser: chrome
+          headless: true

+ 2 - 4
.github/workflows/tests.yml → .github/workflows/jest-tests.yml

@@ -1,8 +1,6 @@
-name: Run tests
+name: Run Jest tests
 
-on:
-  push:
-  pull_request:
+on: [pull_request]
 
 jobs:
   tests:

+ 2 - 1
.gitignore

@@ -1,2 +1,3 @@
 /node_modules
-yarn-error.log
+yarn-error.log
+/cypress

+ 7 - 0
cypress.json

@@ -0,0 +1,7 @@
+{
+    "video": false,
+    "pluginsFile": false,
+    "supportFile": "tests/cypress/bootstrap.js",
+    "integrationFolder": "tests/cypress/integration",
+    "baseUrl": "http://127.0.0.1:8080"
+}

+ 3 - 0
jest.config.js

@@ -2,5 +2,8 @@ module.exports = {
     moduleDirectories: [
         'node_modules',
         'src'
+    ],
+    testPathIgnorePatterns: [
+        'tests/cypress/'
     ]
 }

+ 7 - 2
package.json

@@ -15,7 +15,9 @@
     "scripts": {
         "build": "microbundle",
         "watch": "microbundle watch",
-        "test": "jest"
+        "test": "jest",
+        "pre-cypress": "http-server",
+        "cypress": "start-server-and-test 'http-server -c-1 --silent' 8080 'npx cypress run'"
     },
     "dependencies": {
         "alpinejs": "^2.5"
@@ -24,9 +26,12 @@
         "@babel/preset-env": "^7.9.5",
         "@testing-library/dom": "^7.2.2",
         "@testing-library/jest-dom": "^5.5.0",
+        "cypress": "^5.4.0",
+        "http-server": "^0.12.3",
         "jest": "^25.4.0",
         "jsdom-simulant": "^1.1.2",
         "microbundle": "^0.11.0",
-        "observable-membrane": "^0.26.1"
+        "observable-membrane": "^0.26.1",
+        "start-server-and-test": "^1.11.5"
     }
 }

+ 5 - 0
tests/cypress/bootstrap.js

@@ -0,0 +1,5 @@
+/* global cy, Cypress */
+
+Cypress.on('window:before:load', win => {
+    cy.spy(win.console, 'error')
+})

+ 18 - 0
tests/cypress/fixtures/persistence/check-persisted.html

@@ -0,0 +1,18 @@
+<html>
+    <head>
+        <script src="/dist/spruce.umd.js"></script>
+        <script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.js"></script>
+    </head>
+    <body>
+        <div x-data>
+            <p x-text="$store.persisted.foo"></p>
+            <button @click="$store.persisted.foo = 'car'"></button>
+        </div>
+
+        <script>
+            Spruce.store('persisted', {
+                foo: 'bar'
+            }, true)
+        </script>
+    </body>
+</html>

+ 15 - 0
tests/cypress/fixtures/persistence/init.html

@@ -0,0 +1,15 @@
+<html>
+    <head>
+        <script src="/dist/spruce.umd.js"></script>
+        <script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.js"></script>
+    </head>
+    <body>
+        <p x-data x-text="$store.persisted.foo"></p>
+
+        <script>
+            Spruce.store('persisted', {
+                foo: 'bar'
+            }, true)
+        </script>
+    </body>
+</html>

+ 21 - 0
tests/cypress/fixtures/persistence/store-methods.html

@@ -0,0 +1,21 @@
+<html>
+    <head>
+        <script src="/dist/spruce.umd.js"></script>
+        <script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.js"></script>
+    </head>
+    <body>
+        <div x-data>
+            <p x-text="$store.persisted.foo"></p>
+            <button @click="$store.persisted.changeFoo()"></button>
+        </div>
+
+        <script>
+            Spruce.store('persisted', {
+                foo: 'bar',
+                changeFoo() {
+                    this.foo = 'car'
+                }
+            }, true)
+        </script>
+    </body>
+</html>

+ 31 - 0
tests/cypress/integration/persistence.spec.js

@@ -0,0 +1,31 @@
+/* global describe, it, cy */
+
+describe('persisted stores', () => {
+    it('should not fail when persisted store is initialised', () => {
+        cy.visit('/tests/cypress/fixtures/persistence/init.html')
+
+        cy.get('p').should('have.text', 'bar')
+    })
+
+    it('should persist data between visits', () => {
+        cy.visit('/tests/cypress/fixtures/persistence/check-persisted.html')
+
+        cy.get('p').should('have.text', 'bar')
+
+        cy.get('button').click()
+        cy.get('p').should('have.text', 'car')
+
+        cy.reload()
+
+        cy.get('p').should('have.text', 'car')
+    })
+
+    it('should be able to call store methods when persisted', () => {
+        cy.visit('/tests/cypress/fixtures/persistence/store-methods.html')
+
+        cy.get('p').should('have.text', 'bar')
+
+        cy.get('button').click()
+        cy.get('p').should('have.text', 'car')
+    })
+})

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 624 - 8
yarn.lock


Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно