Skip to content

Commit

Permalink
Merge pull request #12 from yurvon-screamo/3-autorun-test-from-dev-mode
Browse files Browse the repository at this point in the history
Create dev mode
  • Loading branch information
yurvon-screamo authored Aug 27, 2024
2 parents dab3740 + 073213d commit c53dd50
Show file tree
Hide file tree
Showing 39 changed files with 461 additions and 247 deletions.
40 changes: 29 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Whether your test outputs format, Utsukushii helps you present your results with

## 🚀 Features

- **Dev mode**: Run test from UI !
- **JUnit Format Support**: Convert JUnit outputs into a unified, beautiful report.
- **Dotnet trx logger Support**: Convert dotnet trx logger report into a unified, beautiful report.
- **Go-Test Format Support**: Convert Go test outputs into a unified, beautiful report.
- **Dev modes**: Run tests and look at their result in 1 command
- **Merge reports**: Union multiple reports into single.

## 📥 Installation
Expand All @@ -26,24 +26,36 @@ go install github.com/yurvon-screamo/utsukushii@latest

## 📚 Usage

### Golang dev
### Dev mode

Run test, gen content and serve:
![dev_mode](dev_mode.png)

```bash
go test -v --json ./... | utsukushii go-dev
```
1) Create config file `utsukushii-dev.yaml`:

### Dotnet dev
```yaml
# Required part
# The command to run the tests
cmd: go test -v --json ./...
# Your solution language, oneof - 'go', '.net'
lang: go

Run test, gen content and serve:
# Optional part
# title: my report title
# coverage: 46
# addr: ':8080'
# ignore_open: true
```

```bash
dotnet test --logger trx | utsukushii dotnet-dev
```
2) Start it:

```bash
utsukushii dev
```

### Generate and Serve Reports

![gen_serve](gen_serve.png)

1. **Generate Content**:

```bash
Expand All @@ -56,6 +68,12 @@ dotnet test --logger trx | utsukushii dotnet-dev
utsukushii serve --content my-utsukushii.json
```

Support:

- go test json
- dotnet test trx
- junit reports

By default, the report is served at `http://localhost:8080`.

## 🛠️ Development and Design Goals
Expand Down
68 changes: 68 additions & 0 deletions cmd/dev_mode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package cmd

import (
"log"
"os"

"github.com/spf13/cobra"
"github.com/yurvon-screamo/utsukushii/dev_mode"
"gopkg.in/yaml.v3"
)

type devModeYamlConfig struct {
Cmd string `yaml:"cmd"`
Lang string `yaml:"lang"`
Title string `yaml:"title"`
Coverage int16 `yaml:"coverage"`
ServeAddress string `yaml:"addr"`
IgnoreOpenBrowser bool `yaml:"ignore_open"`
}

func handleDevMode(cmd *cobra.Command, args []string) {
rawConfig, err := os.ReadFile(devModeConfig)
if err != nil {
log.Fatalf("error read config: %v", err)
}

config := devModeYamlConfig{}
err = yaml.Unmarshal([]byte(rawConfig), &config)
if err != nil {
log.Fatalf("error unmarshal: %v", err)
}

if config.ServeAddress == "" {
config.ServeAddress = ":8080"
}
if config.Title == "" {
config.Title = "Utsukushii dev"
}

devModeConfig := &dev_mode.DevModeConfig{
Cmd: config.Cmd,
Lang: config.Lang,
Title: config.Title,
Coverage: config.Coverage,
ServeAddress: config.ServeAddress,
OpenBrowser: !config.IgnoreOpenBrowser,
}

err = dev_mode.RunDevMode(devModeConfig)
if err != nil {
log.Fatalf("run dev mode: %v", err)
}
}

var devModeConfig string

var devModeCmd = &cobra.Command{
Use: "dev",
Short: "Serve and open UI in dev mode",
Long: `Run your tests from utsukushii report and get feedback immediately`,
Run: handleDevMode,
}

func init() {
rootCmd.AddCommand(devModeCmd)

devModeCmd.Flags().StringVarP(&devModeConfig, "config", "c", "utsukushii-dev.yaml", "Path to dev mode config")
}
98 changes: 0 additions & 98 deletions cmd/dotnet_dev.go

This file was deleted.

8 changes: 4 additions & 4 deletions cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (

"github.com/spf13/cobra"

"github.com/yurvon-screamo/utsukushii/dotnet_trx_input"
"github.com/yurvon-screamo/utsukushii/gotest_input"
"github.com/yurvon-screamo/utsukushii/json_output"
"github.com/yurvon-screamo/utsukushii/junit_input"
"github.com/yurvon-screamo/utsukushii/model"
"github.com/yurvon-screamo/utsukushii/specification/dotnet_trx_input"
"github.com/yurvon-screamo/utsukushii/specification/gotest_input"
"github.com/yurvon-screamo/utsukushii/specification/json_output"
"github.com/yurvon-screamo/utsukushii/specification/junit_input"
)

func handleGen(cmd *cobra.Command, args []string) {
Expand Down
81 changes: 0 additions & 81 deletions cmd/go_dev.go

This file was deleted.

31 changes: 4 additions & 27 deletions cmd/serve.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,16 @@
package cmd

import (
"io/fs"
"log"
"net/http"

"github.com/pkg/browser"
"github.com/spf13/cobra"
"github.com/yurvon-screamo/utsukushii/utsukushii_ui"
"github.com/yurvon-screamo/utsukushii/serve"
)

func handleServe(cmd *cobra.Command, args []string) {
distFS, err := fs.Sub(utsukushii_ui.UtsukushiiUi, "staticBuild")
if err != nil {
log.Fatal(err)
}

http.HandleFunc("/utsukushii.json", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, r.URL.Path[1:])
})

http.Handle("/", http.FileServer(http.FS(distFS)))

log.Println("Starting HTTP server at", addr)

if open {
url := addr
if addr[0] == ':' {
url = "localhost" + url
}
url = "http://" + url
browser.OpenURL(url)
}
serve.RunUiHandle()
serve.RunUtsukushiiFsContentHandle(content)

log.Fatal(http.ListenAndServe(addr, nil))
serve.ListenAndServe(addr, open)
}

var addr string
Expand Down
Binary file added dev_mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions dev_mode/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev_mode

type DevModeConfig struct {
Cmd string
Lang string
Title string
Coverage int16
ServeAddress string
OpenBrowser bool
}

const (
golang = "go"
dotnet = ".net"
)
Loading

0 comments on commit c53dd50

Please sign in to comment.