Compare commits

..

4 commits

11 changed files with 3153 additions and 61 deletions

54
.github/workflows/golangci-lint.yml vendored Normal file
View file

@ -0,0 +1,54 @@
name: golangci-lint
on:
push:
branches: [ "master" ]
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.54
# Optional: working directory, useful for monorepos
working-directory: ./backend
# Optional: golangci-lint command line arguments.
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
# Optional: if set to true, then all caching functionality will be completely disabled,
# takes precedence over all other caching options.
# skip-cache: true
# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true
# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
# skip-build-cache: true
# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall"

View file

@ -32,5 +32,6 @@ jobs:
cache: 'npm'
cache-dependency-path: '**/package-lock.json'
- run: npm ci
- run: npm run lint
- run: npm run build --if-present
- run: npm test

View file

@ -63,5 +63,9 @@ backup:
fmt:
$(GOCMD) fmt ./...
# Lint
lint:
golangci-lint run ./...
# Default target
default: build

View file

@ -15,7 +15,7 @@ func main() {
conf, err := config.ReadConfigFromFile("config.toml")
if err != nil {
conf = config.NewConfig()
conf.WriteConfigToFile("config.toml")
_ = conf.WriteConfigToFile("config.toml")
}
// Pretty print the current config

View file

@ -104,6 +104,9 @@ func (d *Db) Migrate(dirname string) error {
log.Println("Executed SQL file:", file.Name())
}
tr.Commit()
if tr.Commit() != nil {
return err
}
return nil
}

View file

@ -36,7 +36,9 @@ func TestDbGetUserId(t *testing.T) {
if err != nil {
t.Error("setupState failed:", err)
}
db.AddUser("test", "password")
if db.AddUser("test", "password") != nil {
t.Error("AddUser failed")
}
var id int

View file

@ -9,7 +9,7 @@ module.exports = {
'plugin:react-hooks/recommended',
'plugin:prettier/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs', 'tailwind.config.js', 'postcss.config.js'],
ignorePatterns: ['dist', '.eslintrc.cjs', 'tailwind.config.js', 'postcss.config.js', 'jest.config.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh', 'prettier'],
rules: {

5
frontend/jest.config.cjs Normal file
View file

@ -0,0 +1,5 @@
module.exports = {
transform: {
'^.+\\.(t|j)sx?$': '@swc/jest',
},
}

File diff suppressed because it is too large Load diff

View file

@ -8,13 +8,17 @@
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"format": "prettier --config .prettierrc '**/*.ts' '**/*.tsx' '**/*.js' '**/*.json' --write"
"format": "prettier --config .prettierrc '**/*.ts' '**/*.tsx' '**/*.js' '**/*.json' --write",
"test": "jest"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@swc/core": "^1.4.2",
"@swc/jest": "^0.2.36",
"@types/jest": "^29.5.12",
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19",
"@typescript-eslint/eslint-plugin": "^6.21.0",
@ -27,8 +31,10 @@
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"jest": "^29.7.0",
"postcss": "^8.4.35",
"prettier": "3.2.5",
"react-test-renderer": "^18.2.0",
"tailwindcss": "^3.4.1",
"typescript": "^5.2.2",
"vite": "^5.1.0"

View file

@ -0,0 +1,12 @@
import { describe, expect, test } from "@jest/globals";
function sum(a: number, b: number): number {
return a + b;
}
// This is obviously not testing the proper component
describe("sum module", () => {
test("adds 1 + 2 to equal 3", () => {
expect(sum(1, 1)).toBe(2);
});
});