diff --git a/.gitignore b/.gitignore index c69c9168e..c3c199a10 100644 --- a/.gitignore +++ b/.gitignore @@ -106,7 +106,10 @@ dist .serverless # IDE / Editor -.idea +.idea/* +!.idea/jsLinters +!.idea/runConfigurations +!.idea/vcs.xml # Service worker sw.* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f284d2808..68b777da5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,51 +1,69 @@ -image: node:latest - -lint: +check: stage: test - script: + image: node:latest + before_script: - set -o pipefail - - - echo -e "\e[0Ksection_start:`date +%s`:prepare_dependencies\r\e[0KPrepare Dependencies" - - 'sed -i ''s/git+ssh:\/\/git@gitlab.com:Avris\/FontAwesomePro.git/git+https:\/\/git@gitlab.com\/Avris\/FakeFontAwesomePro.git/'' package.json' - - 'sed -i ''/"devDependencies"/a "eslint-formatter-gitlab": "*",'' package.json' - - echo -e "\e[0Ksection_end:`date +%s`:prepare_dependencies\r\e[0K" - - - make switch LANG=en - - - echo -e "\e[0Ksection_start:`date +%s`:install_dependencies\r\e[0KInstall Dependencies" - - yarn install --immutable --immutable-cache --check-cache --cache-folder .yarn - - echo -e "\e[0Ksection_end:`date +%s`:install_dependencies\r\e[0K" - - - echo -e "\e[0Ksection_start:`date +%s`:reset_dependencies\r\e[0KReset Dependencies" - - git restore package.json yarn.lock - - echo -e "\e[0Ksection_end:`date +%s`:reset_dependencies\r\e[0K" - - - echo -e "\e[0Ksection_start:`date +%s`:check_lints\r\e[0KCheck linting rules" - - yarn lint --format gitlab --color --fix --quiet - - echo -e "\e[0Ksection_end:`date +%s`:check_lints\r\e[0K" - - - echo -e "\e[0Ksection_start:`date +%s`:check_fixable\r\e[0KCheck for fixable problems" - - git diff --stat --exit-code - - echo -e "\e[0Ksection_end:`date +%s`:check_fixable\r\e[0K" - artifacts: - reports: - codequality: gl-codequality.json - -unit-tests: - stage: test + - export NODE_ENV=development + - > + start_section () { + current_section=$1; + echo -e "\e[0Ksection_start:`date +%s`:${current_section//[^a-zA-Z0-9]/-}\r\e[0K$current_section"; + }; + end_section () { + echo -e "\e[0Ksection_end:`date +%s`:${current_section//[^a-zA-Z0-9]/-}\r\e[0K"; + }; + failures=(); + record_failure () { + exit_code=$?; + name=${1:-$current_section}; + echo -e "\033[0;31m$name failed with exit code $exit_code\033[0m"; failures+=("$name"); + }; script: - - echo -e "\e[0Ksection_start:`date +%s`:prepare_dependencies\r\e[0KPrepare Dependencies" - - 'sed -i ''s/git+ssh:\/\/git@gitlab.com:Avris\/FontAwesomePro.git/git+https:\/\/git@gitlab.com\/Avris\/FakeFontAwesomePro.git/'' package.json' - - 'sed -i ''/"devDependencies"/a "jest-junit": "*",'' package.json' - - echo -e "\e[0Ksection_end:`date +%s`:prepare_dependencies\r\e[0K" + - start_section "Install Dependencies" + # temporarily replace FontAwesomePro dependency with its fake version as the CI can’t access it + # the name needs to be changed in both package.json and yarn.lock + - 'sed -i "s/git+ssh:\/\/git@gitlab.com:Avris\/FontAwesomePro.git/git+https:\/\/gitlab.com\/Avris\/FakeFontAwesomePro.git/" package.json yarn.lock' + # the referenced SHA needs to be additionally changed in yarn.lock + - 'sed -i "s/f00db606f659dca78b143b7bcab5671b2cb459a8/0d322c775cbe9bf99da261700be30251291b51a8/" yarn.lock' + - yarn install --frozen-lockfile || record_failure + - git restore package.json yarn.lock + - end_section - make switch LANG=en - - echo -e "\e[0Ksection_start:`date +%s`:install_dependencies\r\e[0KInstall Dependencies" - - yarn install --immutable --immutable-cache --check-cache --cache-folder .yarn - - echo -e "\e[0Ksection_end:`date +%s`:install_dependencies\r\e[0K" + - start_section "Unit Tests" + - > + yarn test --ci --reporters=default --reporters=jest-junit + --coverage --collect-coverage-from="./{plugins,server,src,store}/**" + --coverage-reporters=text --coverage-reporters=cobertura || record_failure + - end_section - - yarn test --ci --reporters=default --reporters=jest-junit --coverage --collect-coverage-from="./{plugins,server,src,store}/**" --coverage-reporters=text --coverage-reporters=cobertura + - start_section "Check linting rules" + - yarn lint --format gitlab --color --fix | grep -v "^\S*warn" || record_failure + - end_section + + - start_section "Check for fixable problems" + - git diff --stat --exit-code || record_failure + - end_section + + # calls scripts to check for simple issues while disabling actual work (e.g. no publishing to third party) + # some scripts are left out because they need special configuration or are not safe to smoke test + - start_section "Smoke test server scripts" + - node server/migrate.js || record_failure "Smoke test migrate" + - node server/calendarBot.js en,pl,es,pt,de,nl,fr,ja,ru,sv,lad,ua,vi "" || record_failure "Smoke test calendarBot" + - node server/cleanupAccounts.js || record_failure "Smoke test cleanupAccounts" + - node server/notify.js || record_failure "Smoke test notify" + - node server/stats.js || record_failure "Smoke test stats" + - node server/subscriptions.js || record_failure "Smoke test subscriptions" + - end_section + + - > + if [[ ${failures[@]} ]]; then + echo -e "\033[0;31mSome checks have failed:"; + printf -- "- %s\n" "${failures[@]}"; + echo -en "\033[0m"; + false; + fi coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/ artifacts: reports: @@ -53,3 +71,4 @@ unit-tests: coverage_report: coverage_format: cobertura path: coverage/cobertura-coverage.xml + codequality: gl-codequality.json diff --git a/.idea/jsLinters/eslint.xml b/.idea/jsLinters/eslint.xml new file mode 100644 index 000000000..67738fad0 --- /dev/null +++ b/.idea/jsLinters/eslint.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/jest-all-tests.run.xml b/.idea/runConfigurations/jest-all-tests.run.xml new file mode 100644 index 000000000..359b0b181 --- /dev/null +++ b/.idea/runConfigurations/jest-all-tests.run.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..f183d1548 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,20 @@ + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 6c7b4950e..df3c74304 100644 --- a/README.md +++ b/README.md @@ -77,12 +77,22 @@ SECRET=replaceThis ### Editor -Some libraries like Vue recommend using Visual Studio Code as editor. -There are some recommended extensions in `.vscode/extensions.json` to help with development. +#### Visual Studio Code +Recommended extensions are provided in `.vscode/extensions.json` +and Visual Studio Code will ask for your permission to install them upon project open. +`.vscode/settings.json` already includes settings to integrate with tooling. + +#### JetBrains IDE (WebStorm, PhpStorm, …) +Most of the tooling is already shipped with a JetBrains IDE. +`.idea` already contains some settings to integrate with the tooling. +If you want syntax highlighting for `.suml` files, you need to manually bind them to `yaml` syntax +via `Settings › Editor › File Types`. + +#### Others When you want to use a different editor, you may need to configure some points to reduce manual work: - Integrating ESLint with auto-fixing on save (the formatting relies on it) -- Integration Jest to easily view test results +- Integrating Jest to easily view test results - Use `yaml` syntax highlighting for `.suml` files ### Tools @@ -135,7 +145,18 @@ A non-comprehensive list of things to look out during development and review: - Be consistent with the design guidelines (at `/design`) - Check frontend in both dark and light mode - Check that changes work in a differently configured locale (especially for optionally configurable features) -- Add new translations to `_base/translations.suml` and if applicable to `expectedTranslations.js` +- Add new translations to `_base/translations.suml` and if applicable add a condition to `missingTranslations.js` +- Consider backwards-compatibility (e.g. links to pronouns in their profile or mail signature shouldn’t break) +- If you changed code related to those scripts, check that they keep running: + - `server/calendar.js` + - `server/calendarBot.js` (with arguments `en,pl,es,pt,de,nl,fr,ja,ru,sv,lad,ua,vi twitter,mastodon`) + - `server/cleanupImages.js` + - `server/cleanupAccounts.js` + - `server/miastamaszerujace.js` (pl locale only) + - `server/migrate.js` + - `server/notify.js` + - `server/stats.js` + - `server/subscriptions.js` ### Integrations diff --git a/package.json b/package.json index 24eb82e06..e3f2a7994 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,7 @@ "css-loader": "^5.2.7", "csv-loader": "^3.0.3", "eslint": "^8.55.0", + "eslint-formatter-gitlab": "^5.1.0", "eslint-plugin-import": "^2.29.0", "eslint-plugin-jsonc": "^2.11.2", "eslint-plugin-vue": "^9.19.2", @@ -95,6 +96,7 @@ "globals": "^13.24.0", "html-loader": "^1.3.2", "jest": "^29.7.0", + "jest-junit": "^16.0.0", "markdown-loader": "^6.0.0", "postcss": "^8.2.15", "postcss-import": "^13.0.0", diff --git a/routes/profile.vue b/routes/profile.vue index 35ce33234..9010252f0 100644 --- a/routes/profile.vue +++ b/routes/profile.vue @@ -369,11 +369,11 @@ export default { } } else { const customOpinion = profile.opinions[opinion]; - if (customOpinion !== undefined - && customOpinion.colour !== 'grey' - && customOpinion.style !== 'small' - && !['ban', 'slash'].includes(customOpinion.icon) - && !(customOpinion.icon || '').endsWith('-slash') + if (customOpinion !== undefined && + customOpinion.colour !== 'grey' && + customOpinion.style !== 'small' && + !['ban', 'slash'].includes(customOpinion.icon) && + !(customOpinion.icon || '').endsWith('-slash') ) { best.push(pronoun); } diff --git a/yarn.lock b/yarn.lock index c02116e98..9029a4c87 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5578,6 +5578,14 @@ eslint-compat-utils@^0.1.1, eslint-compat-utils@^0.1.2: resolved "https://registry.yarnpkg.com/eslint-compat-utils/-/eslint-compat-utils-0.1.2.tgz#f45e3b5ced4c746c127cf724fb074cd4e730d653" integrity sha512-Jia4JDldWnFNIru1Ehx1H5s9/yxiRHY/TimCuUc0jNexew3cF1gI6CYZil1ociakfWO3rRqFjl1mskBblB3RYg== +eslint-formatter-gitlab@^5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/eslint-formatter-gitlab/-/eslint-formatter-gitlab-5.1.0.tgz#33162a17eefba5a44a257af568511d360212e866" + integrity sha512-IxhrjLYzDlbFgPWEnvZlWLwPjMeyymbyo0hDHWntZ3DSAP9AP9huj15KbU+BK3OqeO3OHhbFEh2TA6sR0KZhkA== + dependencies: + chalk "^4.0.0" + yaml "^2.0.0" + eslint-import-resolver-node@^0.3.9: version "0.3.9" resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.9.tgz#d4eaac52b8a2e7c3cd1903eb00f7e053356118ac" @@ -7897,6 +7905,16 @@ jest-haste-map@^29.7.0: optionalDependencies: fsevents "^2.3.2" +jest-junit@^16.0.0: + version "16.0.0" + resolved "https://registry.yarnpkg.com/jest-junit/-/jest-junit-16.0.0.tgz#d838e8c561cf9fdd7eb54f63020777eee4136785" + integrity sha512-A94mmw6NfJab4Fg/BlvVOUXzXgF0XIH6EmTgJ5NDPp4xoKq0Kr7sErb+4Xs9nZvu58pJojz5RFGpqnZYJTrRfQ== + dependencies: + mkdirp "^1.0.4" + strip-ansi "^6.0.1" + uuid "^8.3.2" + xml "^1.0.1" + jest-leak-detector@^29.7.0: version "29.7.0" resolved "https://registry.yarnpkg.com/jest-leak-detector/-/jest-leak-detector-29.7.0.tgz#5b7ec0dadfdfec0ca383dc9aa016d36b5ea4c728" @@ -13841,6 +13859,11 @@ xml2js@0.5.0: sax ">=0.6.0" xmlbuilder "~11.0.0" +xml@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5" + integrity sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw== + xmlbuilder@~11.0.0: version "11.0.1" resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3"