Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

test(STADTPULS-622): add basic Cypress testing #261

Merged
merged 24 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2add71f
chore(STADTPULS-622): add cypress dependency
dnsos Jan 18, 2022
f4f6e01
chore(STADTPULS-622): add cypress script
dnsos Jan 18, 2022
3ff9f0c
chore(STADTPULS-622): setup TypeScript for cypress
dnsos Jan 18, 2022
f1be523
chore(STADTPULS-622): setup eslint with cypress
dnsos Jan 18, 2022
4bd2628
test(STADTPULS-622): add cypress baseUrl
dnsos Jan 18, 2022
ac8bff6
test(STADTPULS-622): add cypress stubs
dnsos Jan 18, 2022
299086b
chore(STADTPULS-622): install cypress testing library
dnsos Jan 18, 2022
7d1f690
chore(STADTPULS-622): configure cypress testing library
dnsos Jan 18, 2022
13d88fd
test(STADTPULS-622): add more stubs (cypress testing library)
dnsos Jan 18, 2022
d43740b
ci(STADTPULS-622): run cypress tests in GitHub Actions
dnsos Jan 18, 2022
731a2b5
ci(STADTPULS-622): use correct dev server port for Cypress
dnsos Jan 18, 2022
2fb5c0b
ci(STADTPULS-622): pass custom port correctly
dnsos Jan 19, 2022
d3a86a2
chore: update time-based snapshot
dnsos Jan 19, 2022
55e3480
chore(STADTPULS-622): rename Cypress files: _spec -> .test
dnsos Jan 19, 2022
f27ed24
ci(STADTPULS-622): use remote-development GitHub environment
dnsos Jan 19, 2022
7095669
ci(STADTPULS-622): use Supabase public key in remote-development env
dnsos Jan 19, 2022
b78507d
refactor(STADTPULS-622): run Cypress tests in main.yml
dnsos Jan 24, 2022
8fd5813
chore: update snapshot
dnsos Jan 24, 2022
d62142f
ci: don't run first build
dnsos Jan 24, 2022
ee9a927
ci: do install dependencies again
dnsos Jan 24, 2022
5a2b2dd
ci: remove first build step altogether
dnsos Jan 24, 2022
928555f
ci: use project Node version only
dnsos Jan 24, 2022
034240f
Merge branch 'staging' into test/STADTPULS-622-add-cypress-testing
dnsos Jan 24, 2022
b095ca4
refactor: automate Node version in CI runs
dnsos Jan 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
136 changes: 73 additions & 63 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,78 @@
module.exports = {
root: true,
env: {
node: true,
es6: true,
jest: true,
},
parserOptions: { ecmaVersion: 8, project: './tsconfig.json', tsconfigRootDir: './' }, // to enable features such as async/await
ignorePatterns: ['node_modules/*', '.next/*', '.out/*', '!.prettierrc.js'], // We don't want to lint generated files nor node_modules, but we want to lint .prettierrc.js (ignored by default by eslint)
extends: ['eslint:recommended'],
overrides: [
// This configuration will apply only to TypeScript files
{
plugins: ['@typescript-eslint', 'import'],
files: ['**/*.ts', '**/*.tsx', '**/*.mdx'],
parser: '@typescript-eslint/parser',
settings: {
react: { version: 'detect' },
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
typescript: {
alwaysTryTypes: true,
},
},
},
env: {
browser: true,
node: true,
es6: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended', // TypeScript rules
"plugin:@typescript-eslint/recommended-requiring-type-checking",
'plugin:react/recommended', // React rules
'plugin:react-hooks/recommended', // React hooks rules
'plugin:jsx-a11y/recommended', // Accessibility rules
'plugin:prettier/recommended', // Prettier recommended rules
],
rules: {
// We will use TypeScript's types for component props instead
'react/prop-types': 'off',
root: true,
env: {
node: true,
es6: true,
jest: true,
},
parserOptions: {
ecmaVersion: 8,
project: "./tsconfig.json",
tsconfigRootDir: "./",
}, // to enable features such as async/await
ignorePatterns: [
"node_modules/*",
".next/*",
".out/*",
"!.prettierrc.js",
"cypress/*",
], // We don't want to lint generated files nor node_modules, but we want to lint .prettierrc.js (ignored by default by eslint)
extends: ["eslint:recommended"],
overrides: [
// This configuration will apply only to TypeScript files
{
plugins: ["@typescript-eslint", "import"],
files: ["**/*.ts", "**/*.tsx", "**/*.mdx"],
parser: "@typescript-eslint/parser",
settings: {
react: { version: "detect" },
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"],
},
"import/resolver": {
typescript: {
alwaysTryTypes: true,
},
},
},
env: {
browser: true,
node: true,
es6: true,
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended", // TypeScript rules
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:react/recommended", // React rules
"plugin:react-hooks/recommended", // React hooks rules
"plugin:jsx-a11y/recommended", // Accessibility rules
"plugin:prettier/recommended", // Prettier recommended rules
],
rules: {
// We will use TypeScript's types for component props instead
"react/prop-types": "off",

// No need to import React when using Next.js
'react/react-in-jsx-scope': 'off',
// No need to import React when using Next.js
"react/react-in-jsx-scope": "off",

// This rule is not compatible with Next.js's <Link /> components
'jsx-a11y/anchor-is-valid': 'off',
// This rule is not compatible with Next.js's <Link /> components
"jsx-a11y/anchor-is-valid": "off",

// Why would you want unused vars?
'@typescript-eslint/no-unused-vars': ['error'],
// Why would you want unused vars?
"@typescript-eslint/no-unused-vars": ["error"],

// I suggest this setting for requiring return types on functions only where useful
'@typescript-eslint/explicit-function-return-type': [
'warn',
{
allowExpressions: true,
allowConciseArrowFunctionExpressionsStartingWithVoid: true,
},
],
'prettier/prettier': ['error', {}, { usePrettierrc: true }], // Includes .prettierrc.js rules
'import/no-unresolved': 'error',
},
},
],
}
// I suggest this setting for requiring return types on functions only where useful
"@typescript-eslint/explicit-function-return-type": [
"warn",
{
allowExpressions: true,
allowConciseArrowFunctionExpressionsStartingWithVoid: true,
},
],
"prettier/prettier": ["error", {}, { usePrettierrc: true }], // Includes .prettierrc.js rules
"import/no-unresolved": "error",
},
},
],
};
32 changes: 0 additions & 32 deletions .github/workflows/build.yml

This file was deleted.

42 changes: 42 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Test and Build

on:
push:
branches: [main, staging]
pull_request:
branches: [main, staging]

jobs:
build:
runs-on: ubuntu-latest
environment: remote-development
if: "!contains(github.event.head_commit.message, 'skip ci')"

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Read .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
id: nvm
- name: Use Node.js (.nvmrc)
uses: actions/setup-node@v2
with:
node-version: ${{ steps.nvm.outputs.NVMRC }}
- name: Set timezone
uses: szenius/set-timezone@v1.0
with:
timezoneLinux: "Europe/Berlin"
- run: npm ci
- run: npm run lint
- run: npm run type-check
- run: npm run test:ci
env:
CI: true
- name: Cypress run
uses: cypress-io/github-action@v2
with:
build: npm run build
start: npm start -- -p 3333
env:
NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}
NEXT_PUBLIC_SUPABASE_PUBLIC_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_PUBLIC_KEY }}
4 changes: 4 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"baseUrl": "http://localhost:3333",
"testFiles": "**/*.test.*"
}
5 changes: 5 additions & 0 deletions cypress/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"plugin:cypress/recommended"
]
}
7 changes: 7 additions & 0 deletions cypress/integration/accounts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe("The Accounts page", () => {
it("successfully loads", () => {
cy.visit("/accounts");

cy.findByRole("heading", { name: /Alle Accounts/i }).should("exist");
});
});
9 changes: 9 additions & 0 deletions cypress/integration/docs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe("The Docs page", () => {
it("successfully loads", () => {
cy.visit("/docs");

cy.findByRole("heading", { name: /Willkommen bei Stadtpuls/i }).should(
"exist"
);
});
});
7 changes: 7 additions & 0 deletions cypress/integration/home.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe("The Home Page", () => {
it("successfully loads", () => {
cy.visit("/");

cy.findByRole("link", { name: /Sensoren ansehen/i }).should("exist");
ff6347 marked this conversation as resolved.
Show resolved Hide resolved
});
});
7 changes: 7 additions & 0 deletions cypress/integration/sensors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe("The Sensors page", () => {
it("successfully loads", () => {
cy.visit("/sensors");

cy.findByRole("heading", { name: /Alle Sensoren/i }).should("exist");
});
});
1 change: 1 addition & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "@testing-library/cypress/add-commands";
1 change: 1 addition & 0 deletions cypress/support/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./commands";
8 changes: 8 additions & 0 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "@testing-library/cypress"]
},
"include": ["**/*.ts"]
}
23 changes: 12 additions & 11 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module.exports = {
setupFilesAfterEnv: ['<rootDir>/src/setupTests.ts'],
moduleNameMapper: {
'^@components(.*)$': '<rootDir>/src/components$1',
'^@lib(.*)$': '<rootDir>/src/lib$1',
'^@common(.*)$': '<rootDir>/src/common$1',
'^@mocks(.*)$': '<rootDir>/src/mocks$1',
'^@auth(.*)$': '<rootDir>/src/auth$1',
'\\.css$': '<rootDir>/src/mocks/cssMock.ts',
'\\/mocks/index$': '<rootDir>/src/mocks/mswMock.ts',
}
}
setupFilesAfterEnv: ["<rootDir>/src/setupTests.ts"],
moduleNameMapper: {
"^@components(.*)$": "<rootDir>/src/components$1",
"^@lib(.*)$": "<rootDir>/src/lib$1",
"^@common(.*)$": "<rootDir>/src/common$1",
"^@mocks(.*)$": "<rootDir>/src/mocks$1",
"^@auth(.*)$": "<rootDir>/src/auth$1",
"\\.css$": "<rootDir>/src/mocks/cssMock.ts",
"\\/mocks/index$": "<rootDir>/src/mocks/mswMock.ts",
},
modulePathIgnorePatterns: ["<rootDir>/cypress/"],
};