From 0c6e9b16548614dc0ce91296e3885c9e421e4e99 Mon Sep 17 00:00:00 2001 From: Shinigami Date: Fri, 9 Sep 2022 20:07:17 +0800 Subject: test: e2e tests (#1362) --- .github/workflows/ci.yml | 6 ++++-- cypress/e2e/api.cy.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ cypress/e2e/guide.cy.ts | 13 +++++++++++++ cypress/e2e/smoke.cy.ts | 26 -------------------------- cypress/tsconfig.json | 7 +++++-- tsconfig.json | 3 ++- 6 files changed, 67 insertions(+), 31 deletions(-) create mode 100644 cypress/e2e/api.cy.ts create mode 100644 cypress/e2e/guide.cy.ts delete mode 100644 cypress/e2e/smoke.cy.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1691afe..83f2ff6a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,14 +67,16 @@ jobs: uses: actions/setup-node@v3 with: node-version: 18 - cache: 'pnpm' - name: Install deps run: pnpm install - - name: Run E2E + - name: Build docs run: pnpm run docs:build:ci + - name: Run e2e + run: pnpm run docs:test:e2e:run + lint: runs-on: ubuntu-latest name: 'Lint: node-18, ubuntu-latest' diff --git a/cypress/e2e/api.cy.ts b/cypress/e2e/api.cy.ts new file mode 100644 index 00000000..ec21d3d3 --- /dev/null +++ b/cypress/e2e/api.cy.ts @@ -0,0 +1,43 @@ +describe('API Test', () => { + it('navigates to the api index search', () => { + // given + cy.visit('/'); + + // when + cy.get('a').contains('API').click(); + + // then + cy.url().should('include', '/api/'); + cy.contains('API Reference'); + }); + + describe('API Reference', () => { + beforeEach(() => { + // given + cy.visit('/api/'); + }); + + it('should at least list more than 7 modules', () => { + cy.get('.api-group').should('have.length.above', 7); + }); + + it('should include at least 1 element in each module', () => { + cy.get('.api-group').each(($el) => { + cy.wrap($el).get('li a[href]').should('have.length.above', 0); + }); + }); + + it('should not have dead links', () => { + cy.get('.api-group li').each(($el) => { + const text = $el.find('a').text(); + const link = $el.find('a').attr('href'); + + cy.visit(`/api/${link}`); + + cy.get('h2').should('include.text', text); + cy.get('h1').should('not.include.text', 'PAGE NOT FOUND'); + cy.go('back'); + }); + }); + }); +}); diff --git a/cypress/e2e/guide.cy.ts b/cypress/e2e/guide.cy.ts new file mode 100644 index 00000000..6186f938 --- /dev/null +++ b/cypress/e2e/guide.cy.ts @@ -0,0 +1,13 @@ +describe('Guide Test', () => { + it('navigates to the getting started section', () => { + // given + cy.visit('/'); + + // when + cy.get('a').contains('Get Started').click(); + + // then + cy.url().should('include', '/guide/'); + cy.contains('Getting Started'); + }); +}); diff --git a/cypress/e2e/smoke.cy.ts b/cypress/e2e/smoke.cy.ts deleted file mode 100644 index eb3cf1fb..00000000 --- a/cypress/e2e/smoke.cy.ts +++ /dev/null @@ -1,26 +0,0 @@ -describe('Smoke Test', () => { - beforeEach(() => { - cy.visit('/guide/'); - cy.get('a[href="/api/animal.html"]').as('firstSectionLink'); - }); - - it('compiles the guide page', () => { - cy.contains('Getting Started'); - }); - - it('renders this last code example in the code', () => { - // Click on any section in the sidebar - cy.get('@firstSectionLink') - .click() - // Make sure the number of code examples is the same between reloads - .get('.container pre code') - .then(($codeBlocks) => { - // Trigger a reload - cy.reload() - // Give the runtime a chance to update/fail - .wait(500) - .get('.container pre code') - .should('have.length', $codeBlocks.length); - }); - }); -}); diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json index 5e8cb532..0446ab75 100644 --- a/cypress/tsconfig.json +++ b/cypress/tsconfig.json @@ -1,8 +1,11 @@ { "compilerOptions": { "target": "ES5", - "lib": ["ES5", "DOM"], - "types": ["cypress"] + "lib": ["ES2015", "DOM"], + "types": ["cypress"], + "esModuleInterop": true, + "noEmit": true, + "resolveJsonModule": true }, "include": ["**/*.ts"] } diff --git a/tsconfig.json b/tsconfig.json index 1944ff18..f96902eb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,7 +15,8 @@ // "noImplicitAny": true, // "noImplicitThis": true, "useUnknownInCatchVariables": true, - "stripInternal": true + "stripInternal": true, + "baseUrl": "." }, "include": ["src/**/*"], "exclude": ["node_modules"] -- cgit v1.2.3