Skip to content

Commit

Permalink
cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-north committed Oct 2, 2023
1 parent d740bfe commit 22bb44c
Show file tree
Hide file tree
Showing 16 changed files with 1,054 additions and 55 deletions.
32 changes: 21 additions & 11 deletions .github/workflows/ci-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Lint
run: yarn lerna run lint --scope website
- name: Test
run: yarn lerna run test --scope website
run: yarn lerna run test:jest --scope website

os-compatibility:
needs: build
Expand All @@ -62,15 +62,16 @@ jobs:
- name: Build
run: yarn lerna run build --scope website
- name: Test
run: yarn lerna run test --scope website
run: yarn lerna run test:jest --scope website

node-compatibility:
needs: build
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 19.x]
node-version: [18.x]
# node-version: [16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v4
- uses: volta-cli/action@v4
Expand All @@ -89,7 +90,7 @@ jobs:
- name: Build
run: yarn lerna run build --scope website
- name: Test
run: yarn lerna run test --scope website
run: yarn lerna run test:jest --scope website


ts-compatibility:
Expand All @@ -98,14 +99,17 @@ jobs:
continue-on-error: ${{ matrix.experimental }}
strategy:
matrix:
typescript-version: ['~5.2.0', latest, next, beta, rc]
typescript-version: ['~5.1.0', next, beta, rc]
include:
- typescript-version: '~5.2.0'
# - typescript-version: '~5.0.0'
# experimental: false
# name: 'ts-5.0'
- typescript-version: '~5.1.0'
experimental: false
name: 'ts-5.2'
- typescript-version: latest
experimental: false
name: 'ts-stable'
name: 'ts-5.1'
# - typescript-version: latest
# experimental: false
# name: 'ts-stable'
- typescript-version: beta
experimental: false
name: 'ts-beta'
Expand Down Expand Up @@ -140,7 +144,13 @@ jobs:
yarn replace-in-file 'import chalk' 'import * as chalk' node_modules/gatsby-cli/lib/reporter/reporter.d.ts
yarn lerna run typecheck --scope website
- name: Test
run: yarn lerna run test --scope website
run: yarn lerna run test:jest --scope website
- name: Cypress
uses: cypress-io/github-action@v6
with:
build: yarn lerna run build --scope website
start: yarn lerna run test:cypress --scope website
browser: chrome

publish:
needs: [build, os-compatibility, node-compatibility, ts-compatibility]
Expand Down
16 changes: 16 additions & 0 deletions packages/website/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@
"@typescript-eslint/no-unused-vars": "off"
}
},
{
"files": ["cypress/**/*.ts"],
"env": { "node": true, "cypress/globals": true },
"plugins": ["cypress"],
"extends": [
"plugin:cypress/recommended"
],
"rules": {
"cypress/no-assigning-return-values": "error",
"cypress/no-unnecessary-waiting": "error",
"cypress/assertion-before-screenshot": "warn",
"cypress/no-force": "warn",
"cypress/no-async-tests": "error",
"cypress/no-pause": "error"
}
},
{
"files": ["loadershim.js"],
"env": { "node": true, "jest": true }
Expand Down
8 changes: 8 additions & 0 deletions packages/website/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'cypress'

export default defineConfig({
e2e: {
baseUrl: 'http://localhost:1234',
testIsolation: false
},
})
97 changes: 97 additions & 0 deletions packages/website/cypress/e2e/course-list/course-list.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/// <reference types="cypress" />

// Welcome to Cypress!
//
// This spec file contains a variety of sample tests
// for a todo list app that are designed to demonstrate
// the power of writing tests in Cypress.
//
// To learn more about how Cypress works and
// what makes it such an awesome testing tool,
// please read our getting started guide:
// https://on.cypress.io/introduction-to-cypress

describe('example to-do app', () => {
beforeEach(() => {
// Cypress starts out with a blank slate for each test
// so we must tell it to visit our website with the `cy.visit()` command.
// Since we want to visit the same URL at the start of all our tests,
// we include it in our beforeEach function so that it runs before each test
cy.visit('http://localhost:8000').waitForRouteChange();
});

it('displays multiple courses', () => {
// We use the `cy.get()` command to get all elements that match the selector.
// Then, we use `should` to assert that there are two matched items,
// which are the two default items.
cy.get('.course-summary').should('have.length', 4);

// We can go even further and check that the default todos each contain
// the correct text. We use the `first` and `last` functions
// to get just the first and last matched elements individually,
// and then perform an assertion with `should`.
// cy.get('.todo-list li').first().should('have.text', 'Pay electric bill')
// cy.get('.todo-list li').last().should('have.text', 'Walk the dog')
});

it('clicking TS-fundamentals v3 course link visits the course page', () => {
cy.contains('TypeScript Fundamentals v3').click();
cy.location('href').should(
'include',
'course/fundamentals-v3',
);
cy.get('h1').should(
'have.text',
'TypeScript Fundamentals v3',
);
cy.get('.course-article__title').should(
'have.length.at.least',
5,
);
});
it('clicking TS-intermediate v1 course link visits the course page', () => {
cy.contains('Intermediate TypeScript').click();
cy.location('href').should(
'include',
'course/intermediate-v1',
);
cy.get('h1').should(
'have.text',
'Intermediate TypeScript',
);
cy.get('.course-article__title').should(
'have.length.at.least',
5,
);
});
it('clicking TS-fullstack v1 course link visits the course page', () => {
cy.contains('Full Stack TypeScript').click();
cy.location('href').should(
'include',
'course/full-stack-typescript',
);
cy.get('h1').should(
'have.text',
'Full Stack TypeScript',
);
cy.get('.course-article__title').should(
'have.length.at.least',
5,
);
});
it('clicking make-TS-stick v1 course link visits the course page', () => {
cy.contains('Making TypeScript Stick').click();
cy.location('href').should(
'include',
'course/making-typescript-stick',
);
cy.get('h1').should(
'have.text',
'Making TypeScript Stick',
);
cy.get('.course-article__title').should(
'have.length.at.least',
5,
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/// <reference types="cypress" />

describe('course page', () => {
beforeEach(() => {
cy.visit(
'http://localhost:8000/course/enterprise-v2',
).waitForRouteChange();
});

it('course sections appear', () => {
cy.get('.course-article__title').should(
'have.length.above',
4,
);
});

it('title is present', () => {
cy.get('h1').should(
'contain.text',
'Enterprise TypeScript v2',
);
});
it('summary is present', () => {
cy.contains('Combine TypeScript').should('exist');
});
it('logo is present', () => {
cy.get('main > header > img')
.should('exist')
.should('have.attr', 'src', '/full-stack-ts.png');
});
it('clicking on a section works', () => {
cy.get('.course-article__title')
.contains('Intro')
.click();
cy.waitForRouteChange();
cy.location('href').should(
'include',
'course/enterprise-v2/01',
);
cy.get('h2').should('have.length.above', 1);
});
});
42 changes: 42 additions & 0 deletions packages/website/cypress/e2e/courses/full-stack-typescript.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/// <reference types="cypress" />

describe('course page', () => {
beforeEach(() => {
cy.visit(
'http://localhost:8000/course/full-stack-typescript',
).waitForRouteChange();
});

it('course sections appear', () => {
cy.get('.course-article__title').should(
'have.length.above',
4,
);
});

it('title is present', () => {
cy.get('h1').should(
'contain.text',
'Full Stack TypeScript',
);
});
it('summary is present', () => {
cy.contains('Combine TypeScript').should('exist');
});
it('logo is present', () => {
cy.get('main > header > img')
.should('exist')
.should('have.attr', 'src', '/full-stack-ts.png');
});
it('clicking on a section works', () => {
cy.get('.course-article__title')
.contains('Intro')
.click();
cy.waitForRouteChange();
cy.location('href').should(
'include',
'course/full-stack-typescript/01',
);
cy.get('h2').should('have.length.above', 1);
});
});
42 changes: 42 additions & 0 deletions packages/website/cypress/e2e/courses/fundamentals-v3.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/// <reference types="cypress" />

describe('course page', () => {
beforeEach(() => {
cy.visit(
'http://localhost:8000/course/fundamentals-v3',
).waitForRouteChange();
});

it('course sections appear', () => {
cy.get('.course-article__title').should(
'have.length.above',
4,
);
});

it('title is present', () => {
cy.get('h1').should(
'contain.text',
'TypeScript Fundamentals',
);
});
it('summary is present', () => {
cy.contains('Learn everything').should('exist');
});
it('logo is present', () => {
cy.get('main > header > img')
.should('exist')
.should('have.attr', 'src', '/ts-fundamentals-v3.png');
});
it('clicking on a section works', () => {
cy.get('.course-article__title')
.contains('Intro')
.click();
cy.waitForRouteChange();
cy.location('href').should(
'include',
'course/fundamentals-v3/01',
);
cy.get('h2').should('have.length.above', 4);
});
});
42 changes: 42 additions & 0 deletions packages/website/cypress/e2e/courses/fundamentals-v4.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/// <reference types="cypress" />

describe('course page', () => {
beforeEach(() => {
cy.visit(
'http://localhost:8000/course/fundamentals-v4',
).waitForRouteChange();
});

it('course sections appear', () => {
cy.get('.course-article__title').should(
'have.length.above',
4,
);
});

it('title is present', () => {
cy.get('h1').should(
'contain.text',
'TypeScript Fundamentals',
);
});
it('summary is present', () => {
cy.contains('Learn everything').should('exist');
});
it('logo is present', () => {
cy.get('main > header > img')
.should('exist')
.should('have.attr', 'src', '/ts-fundamentals-v3.png');
});
it('clicking on a section works', () => {
cy.get('.course-article__title')
.contains('Intro')
.click();
cy.waitForRouteChange();
cy.location('href').should(
'include',
'course/fundamentals-v4/01',
);
cy.get('h2').should('have.length.above', 4);
});
});
Loading

0 comments on commit 22bb44c

Please sign in to comment.