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

Commit

Permalink
Merge pull request #261 from technologiestiftung/test/STADTPULS-622-a…
Browse files Browse the repository at this point in the history
…dd-cypress-testing

test(STADTPULS-622): add basic Cypress testing
  • Loading branch information
dnsos committed Jan 24, 2022
2 parents 1147516 + b095ca4 commit 820e5b7
Show file tree
Hide file tree
Showing 15 changed files with 35,419 additions and 923 deletions.
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");
});
});
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/"],
};

0 comments on commit 820e5b7

Please sign in to comment.