Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vitest for frontend testing #2810

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ jobs:
- run:
name: Check formatting of CSS & JS files
command: npx prettier --check .
vitest:
docker:
- image: "cimg/node:lts"
resource_class: small
steps:
- checkout
- attach_workspace:
at: .
- run:
name: Run frontend tests
command: npm run test
eslint:
docker:
- image: "cimg/node:lts"
Expand Down Expand Up @@ -609,6 +620,9 @@ workflows:
- prettier:
requires:
- npm-install
- vitest:
requires:
- npm-install
- webpack:
requires:
- npm-install
Expand Down
17 changes: 17 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
const path = require("path");

module.exports = {
env: {
es6: true,
browser: true,
},
settings: {
"import/resolver": {
node: {
paths: ["src"],
extensions: [".js", ".jsx", ".ts", ".d.ts", ".tsx"],
},
typescript: {
project: "./tsconfig.json",
},
alias: {
map: [["~", path.resolve(__dirname, "./src")]],
extensions: [".js", ".jsx", ".ts", ".d.ts", ".tsx"],
},
},
},
ignorePatterns: [
"**/dist/",
"**/htmlcov/**",
Expand Down
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ repos:
types_or: [python, html]
language: script
pass_filenames: false
- repo: local
hooks:
- id: frontend-tests
name: frontend-tests
description: Run frontend tests
entry: tools/vitest.sh
language: script
pass_filenames: false
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
Expand Down
9 changes: 9 additions & 0 deletions integreat_cms/static/src/js/__tests__/utils/mfa-utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { expect, test } from "vitest";
import { b64enc } from "../../utils/mfa-utils";

test("base64 and url encoding", () => {
const testDataString = "https://example.com/?q=Hello+World!";
const testData = new TextEncoder().encode(testDataString);

expect(b64enc(testData)).toBe("aHR0cHM6Ly9leGFtcGxlLmNvbS8_cT1IZWxsbytXb3JsZCE");
});
Loading
Loading