Skip to content

Commit

Permalink
dev watchRebuiltRun
Browse files Browse the repository at this point in the history
  • Loading branch information
teintinu authored Sep 1, 2021
1 parent 399fd20 commit 54a4cb7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 35 deletions.
3 changes: 2 additions & 1 deletion examples/simple-workspace/e/src/e.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { functionE } from './'

it('module e', () => {
it('module e', async () => {
await new Promise((resolve) => setTimeout(resolve, 300))
expect(functionE()).toEqual({ e: 'e' })
})
44 changes: 27 additions & 17 deletions internal/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package internal
import (
"os"
"os/exec"
"path"
"strings"
"sync"
"time"

"github.com/evanw/esbuild/pkg/api"
)
Expand All @@ -17,9 +17,9 @@ func Dev(repo *Repository) error {

webterm := NewWebTerm()

wg.Add(2)
wg.Add(1)
devRunExecutables(repo, wg, webterm)
devTestApps(repo, wg, webterm)
// devRunExecutables(repo, wg, webterm)

webterm.Start(DevPort)
wg.Wait()
Expand All @@ -29,21 +29,22 @@ func Dev(repo *Repository) error {

func devTestApps(repo *Repository, wg *sync.WaitGroup, webterm *WebTerm) {

jestReport := path.Join(repo.RootDir, ".jest/html-report")
jestReport := ""
total := ""
failed := ""

getCommand := func() (*exec.Cmd, error) {
return CreateJestCommand(repo, TestOptions{
Watch: true,
Coverage: false,
Colors: false,
Colors: true,
}), nil
}
executeAllTests := &WebTermTabAction{
id: "executeAllTests",
title: "Run All Tests",
icon: "play",
action: func(pty *os.File, args ...string) {
println("executeAllTests-cmd")
pty.WriteString("a")
},
}
Expand All @@ -52,38 +53,47 @@ func devTestApps(repo *Repository, wg *sync.WaitGroup, webterm *WebTerm) {
}

processConsoleOutput := func(lineWithColors string, wtts *WebTermTabRoutines) {
if strings.Contains(lineWithColors, "\x1b[K") {
wtts.setRunning()
return
}
// println(strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(lineWithColors, "\b", "BS"), "\r", "CR"), "\x1b", "ESC"))
// println("a:", strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(lineWithColors, "\b", "BS"), "\r", "CR"), "\x1b", "ESC"))
line := RegRemoveANSI.ReplaceAllString(lineWithColors, "")
testResult := RegExpJestRunComplete.FindStringSubmatch(line)
// fmt.Println("b:", line)
// fmt.Println()
// fmt.Println()
// fmt.Println(testResult)
//fmt.Println()
//fmt.Println("b:", line)
//fmt.Println()
//fmt.Println(testResult)

if len(testResult) > 0 {
total := testResult[1]
failed := testResult[2]
total = testResult[3]
failed = testResult[1]
} else if strings.Contains(line, "Ran all test suites") {
if total == "0" {
wtts.setUnknow()
} else if failed == "0" {
} else if failed == "" {
wtts.setSuccess(line, total, failed)
} else {
wtts.setError(line, total, failed)
}
} else if strings.Contains(line, "No tests found related to files changed since last commit.") {
wtts.setUnknow()
} else if RegExpJestRunStart.MatchString(line) {
wtts.setRunning()
} else if RegExpJestReportCreated.MatchString(line) {
wtts.sendToFrontEnd("reloadTab")
}
}
webterm.AddShell("/jest", "Tests", jestReport, true, getCommand, actions, processConsoleOutput)

go func() {
for !webterm.IsClosed() {
time.Sleep(time.Second)
}
wg.Done()
}()
}

func devRunExecutables(repo *Repository, wg *sync.WaitGroup, webterm *WebTerm) {
for _, pkg := range repo.Packages {
wg.Add(1)
BundleWithEsbuild(repo, pkg, &BuildOpts{
Target: api.ESNext,
Minify: false,
Expand Down
1 change: 0 additions & 1 deletion internal/required.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var requiredWorkspaceDevDependencies = map[string]string{
"typescript": "^4.3.5",
"jest": "^27.0.6",
"@types/jest": "^26.0.24",
"jest-html-reporters": "^2.1.6",
"ts-jest": "^27.0.3",
"esbuild": "^0.12.15",
"esbuild-jest": "^0.5.0",
Expand Down
8 changes: 0 additions & 8 deletions internal/setupWorkspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,6 @@ module.exports = {
}
]
},
reporters: [
'./.jest/jest.report',
['jest-html-reporters', {
publicPath: './.jest/html-report',
filename: 'index.html',
expand: true
}]
],
coverageDirectory: './.jest/coverage/',
coverageReporters: [
'text',
Expand Down
7 changes: 3 additions & 4 deletions internal/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ func CreateJestCommand(repo *Repository, opts TestOptions) *exec.Cmd {
return jestCmd
}

var RegExpJestRunStart = regexp.MustCompile(`^\s+jestRunStart\s+$`)

// jestRunComplete count=0 failed=0
var RegExpJestRunComplete = regexp.MustCompile(`^\s+jestRunComplete\s+count=(\d+)\s+failed=(\d+)\s+$`)
// Tests: 5 passed, 5 total
// Tests: 1 failed, 4 passed, 5 total
var RegExpJestRunComplete = regexp.MustCompile(`^\s*Tests:\s+(?:(\d+)\s+failed,)?\s*(?:(\d+).+passed,)?\s*(\d+)\s+total\s*$`)

var RegExpJestReportCreated = regexp.MustCompile(`reporter is created on`)
3 changes: 0 additions & 3 deletions internal/webterm.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func (webterm *WebTerm) Start(port int32) {
}

func (webterm *WebTerm) processCommand(command []string) {
fmt.Println(command)
tabId := command[0]
actionId := command[1]
if tabId == "*" {
Expand All @@ -71,9 +70,7 @@ func (webterm *WebTerm) processCommand(command []string) {
} else {
for _, tab := range webterm.tabs {
if tab.id == tabId {
println("tab", tab.id, "==", tabId)
for _, ac := range tab.actions {
println("action", ac.id, "==", actionId)
if ac.id == actionId {
ac.action(tab.pty, command[2:]...)
}
Expand Down
1 change: 0 additions & 1 deletion internal/webtermTabShell.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ func (tab *WebTermTab) Pty(
}

func (tab *WebTermTab) consoleOutput(line string) {
print(line)
if tab.ws != nil {
if _, err := tab.ws.Write(append([]byte(line), linefeedDelimiter)); err != nil {
tab.ws = nil
Expand Down

0 comments on commit 54a4cb7

Please sign in to comment.