mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 11:07:10 +00:00
Four consolidations, no assertion changed and the same 217 tests passing:
harness gains run and tryRun, retiring 68 copies of context.WithTimeout plus
Run(ctx, Options{}) plus an error check. The seven sites whose error check said
something specific keep their own wording.
mock.FailurePlan retires six wrapper drivers that were the same seven-line
method with a different error constant. The three that need more than an error
on call N stay.
traceStepLine absorbs the 15 local trace-line declarations and readTraceLines is
now the only reader. No local copy disagreed with internal/trace about a JSON
tag. Three raw readers stay on purpose: one decodes a real trace.Step, one
snapshots bytes, one asserts on raw JSON text.
One embeddable base carries the five V8-path methods the five web fakes each
redeclared.
72 lines
2.0 KiB
Go
72 lines
2.0 KiB
Go
package runner
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/priyanshujain/sanderling/internal/driver"
|
|
mockdriver "github.com/priyanshujain/sanderling/internal/driver/mock"
|
|
"github.com/priyanshujain/sanderling/internal/trace"
|
|
)
|
|
|
|
// throwingDriver reports one captured uncaught error, the way the chrome
|
|
// driver reports the page's buffer.
|
|
type throwingDriver struct {
|
|
*mockdriver.Driver
|
|
}
|
|
|
|
func (d *throwingDriver) Exceptions(
|
|
context.Context,
|
|
) ([]driver.Exception, error) {
|
|
return []driver.Exception{{
|
|
Class: "TypeError",
|
|
Message: "cannot read balance of null",
|
|
StackTrace: "at render (app.js:12)",
|
|
UnixMillis: 1700000000000,
|
|
}}, nil
|
|
}
|
|
|
|
// TestRunner_LogsAndExceptionsLandInTheTrace covers the error surface an
|
|
// offline oracle has no other source for: the default properties read
|
|
// state.logs and state.exceptions, and neither used to survive the step.
|
|
func TestRunner_LogsAndExceptionsLandInTheTrace(t *testing.T) {
|
|
state := newHarness(t)
|
|
state.mock.LogEntries = []driver.LogEntry{{
|
|
UnixMillis: 1700000000123,
|
|
Level: "E",
|
|
Tag: "AndroidRuntime",
|
|
Message: "FATAL EXCEPTION: main",
|
|
}}
|
|
|
|
state.run(t, Options{
|
|
Duration: 100 * time.Millisecond,
|
|
MaxSteps: 1,
|
|
Driver: &throwingDriver{Driver: state.mock},
|
|
})
|
|
|
|
stored := readTraceLines(t, state.writer.Directory())[0]
|
|
if stored.TraceVersion != trace.TraceVersion {
|
|
t.Errorf(
|
|
"trace_version = %d, want %d; an old trace could not be told apart",
|
|
stored.TraceVersion,
|
|
trace.TraceVersion,
|
|
)
|
|
}
|
|
want := trace.LogEntry{
|
|
UnixMillis: 1700000000123,
|
|
Level: "E",
|
|
Tag: "AndroidRuntime",
|
|
Message: "FATAL EXCEPTION: main",
|
|
}
|
|
if len(stored.Logs) != 1 || stored.Logs[0] != want {
|
|
t.Errorf("logs on disk = %+v, want [%+v]", stored.Logs, want)
|
|
}
|
|
if len(stored.Exceptions) != 1 ||
|
|
stored.Exceptions[0].Class != "TypeError" ||
|
|
stored.Exceptions[0].Message != "cannot read balance of null" ||
|
|
stored.Exceptions[0].StackTrace != "at render (app.js:12)" {
|
|
t.Errorf("exceptions on disk = %+v", stored.Exceptions)
|
|
}
|
|
}
|