Cucumber Messages protocol types for MoonBit with JSON serialization and NDJSON streaming
Dependencies
moon add moonrockz/cucumber-messages| Category | Message Types |
|---|---|
| Source & Parsing | Source, GherkinDocument, ParseError |
| Test Compilation | Pickle |
| Glue Definitions | StepDefinition, Hook, ParameterType |
| Test Run Lifecycle | TestRunStarted, TestRunFinished |
| Test Case Lifecycle | TestCase, TestCaseStarted, TestCaseFinished |
| Step Lifecycle | TestStepStarted, TestStepFinished |
| Hook Lifecycle | TestRunHookStarted, TestRunHookFinished |
| Artifacts | Attachment, ExternalAttachment |
| Metadata | Meta, Suggestion, UndefinedParameterType |
// Deserialize a message from JSON (use your package alias for Envelope, e.g. @cm)
let json = @json.parse(
"{\"meta\": {\"protocolVersion\": \"27.0.0\", \"implementation\": {\"name\": \"cucumber-moonbit\"}, \"runtime\": {\"name\": \"moonbit\"}, \"os\": {\"name\": \"linux\"}, \"cpu\": {\"name\": \"amd64\"}}}"
) catch { _ => panic() }
let envelope : Envelope = @json.from_json(json) catch { _ => panic() }
// Serialize a message to JSON
let json_value = envelope.to_json()
// NDJSON streaming: parse multiple messages from newline-delimited JSON
let envelopes = @cm.parse_ndjson(ndjson_string) catch { _ => panic() }
// Serialize envelopes to NDJSON
let ndjson = @cm.envelopes_to_ndjson(envelopes)pub struct Attachment {
body : String
contentEncoding : AttachmentContentEncoding
mediaType : String
fileName : String?
source : Source?
testCaseStartedId : String?
testStepId : String?
url : String?
testRunStartedId : String?
testRunHookStartedId : String?
timestamp : Timestamp?
}impl ToJson for Attachmentimpl FromJson for Attachmentpub enum AttachmentContentEncoding {
Identity
Base64
}impl ToJson for AttachmentContentEncodingimpl FromJson for AttachmentContentEncodingimpl ToJson for Backgroundimpl FromJson for Backgroundpub struct Duration {
seconds : Int
nanos : Int
}pub enum Envelope {
Meta(Meta)
Source(Source)
ParseError(ParseError)
TestRunStarted(TestRunStarted)
TestRunFinished(TestRunFinished)
UndefinedParameterType(UndefinedParameterType)
TestCaseStarted(TestCaseStarted)
TestCaseFinished(TestCaseFinished)
TestStepStarted(TestStepStarted)
TestStepFinished(TestStepFinished)
Attachment(Attachment)
ExternalAttachment(ExternalAttachment)
Hook(Hook)
StepDefinition(StepDefinition)
ParameterType(ParameterType)
Suggestion(Suggestion)
TestRunHookStarted(TestRunHookStarted)
TestRunHookFinished(TestRunHookFinished)
GherkinDocument(GherkinDocument)
Pickle(Pickle)
TestCase(TestCase)
}pub struct Exception {
type_ : String
message : String?
stackTrace : String?
}pub struct ExternalAttachment {
url : String
mediaType : String
testCaseStartedId : String?
testStepId : String?
testRunHookStartedId : String?
timestamp : Timestamp?
}impl ToJson for ExternalAttachmentimpl FromJson for ExternalAttachmentpub struct Feature {
location : Location
tags : Array[Tag]
language : String
keyword : String
name : String
description : String
children : Array[FeatureChild]
}impl ToJson for FeatureChildimpl FromJson for FeatureChildimpl ToJson for GherkinDocumentimpl FromJson for GherkinDocumentpub struct Git {
remote : String
revision : String
branch : String?
tag : String?
}pub struct Hook {
id : String
sourceReference : SourceReference
name : String?
tagExpression : String?
type_ : HookType?
}pub enum HookType {
BeforeTestRun
AfterTestRun
BeforeTestCase
AfterTestCase
BeforeTestStep
AfterTestStep
}pub struct JavaMethod {
className : String
methodName : String
methodParameterTypes : Array[String]
}impl ToJson for JavaMethodimpl FromJson for JavaMethodpub struct JavaStackTraceElement {
className : String
fileName : String
methodName : String
}impl ToJson for JavaStackTraceElementimpl FromJson for JavaStackTraceElementpub enum KeywordType {
Unknown
Context
Action
Outcome
Conjunction
}pub struct Location {
line : Int
column : Int?
}pub struct ParameterType {
id : String
name : String
preferForRegularExpressionMatch : Bool
regularExpressions : Array[String]
useForSnippets : Bool
sourceReference : SourceReference?
}impl ToJson for ParameterTypeimpl FromJson for ParameterTypeimpl ToJson for ParseErrorimpl FromJson for ParseErrorpub(all) struct PickleDocString {
content : String
mediaType : String?
}impl ToJson for PickleDocStringimpl FromJson for PickleDocStringpub(all) struct PickleStep {
id : String
text : String
astNodeIds : Array[String]
type_ : PickleStepType?
argument : PickleStepArgument?
}impl ToJson for PickleStepimpl FromJson for PickleStepimpl ToJson for PickleStepArgumentimpl FromJson for PickleStepArgumentpub(all) enum PickleStepType {
Unknown
Context
Action
Outcome
}impl ToJson for PickleStepTypeimpl FromJson for PickleStepTypeimpl ToJson for PickleTableimpl FromJson for PickleTablepub(all) struct PickleTableCell {
value : String
}impl ToJson for PickleTableCellimpl FromJson for PickleTableCellimpl ToJson for PickleTableRowimpl FromJson for PickleTableRowpub(all) struct PickleTag {
name : String
astNodeId : String
}pub struct Product {
name : String
version : String?
}pub struct Snippet {
language : String
code : String
}pub enum SourceMediaType {
GherkinPlain
GherkinMarkdown
}impl ToJson for SourceMediaTypeimpl FromJson for SourceMediaTypepub struct SourceReference {
uri : String?
javaMethod : JavaMethod?
javaStackTraceElement : JavaStackTraceElement?
location : Location?
}impl ToJson for SourceReferenceimpl FromJson for SourceReferencepub struct Step {
location : Location
keyword : String
text : String
id : String
keywordType : KeywordType?
docString : DocString?
dataTable : DataTable?
}pub struct StepDefinition {
id : String
pattern : StepDefinitionPattern
sourceReference : SourceReference
}impl ToJson for StepDefinitionimpl FromJson for StepDefinitionimpl ToJson for StepDefinitionPatternimpl FromJson for StepDefinitionPatternpub enum StepDefinitionPatternType {
CucumberExpression
RegularExpression
}impl ToJson for StepDefinitionPatternTypeimpl FromJson for StepDefinitionPatternTypeimpl ToJson for StepMatchArgumentimpl FromJson for StepMatchArgumentimpl ToJson for StepMatchArgumentsListimpl FromJson for StepMatchArgumentsListimpl ToJson for Suggestionimpl FromJson for Suggestionpub struct TestCaseFinished {
testCaseStartedId : String
timestamp : Timestamp
willBeRetried : Bool
}impl ToJson for TestCaseFinishedimpl FromJson for TestCaseFinishedpub struct TestCaseStarted {
attempt : Int
id : String
testCaseId : String
workerId : String?
timestamp : Timestamp
}impl ToJson for TestCaseStartedimpl FromJson for TestCaseStartedimpl ToJson for TestRunFinishedimpl FromJson for TestRunFinishedpub struct TestRunHookFinished {
testRunHookStartedId : String
result : TestStepResult
timestamp : Timestamp
}impl ToJson for TestRunHookFinishedimpl FromJson for TestRunHookFinishedpub struct TestRunHookStarted {
id : String
testRunStartedId : String
hookId : String
timestamp : Timestamp
workerId : String?
}impl ToJson for TestRunHookStartedimpl FromJson for TestRunHookStartedimpl ToJson for TestRunStartedimpl FromJson for TestRunStartedpub struct TestStep {
id : String
hookId : String?
pickleStepId : String?
stepDefinitionIds : Array[String]?
stepMatchArgumentsLists : Array[StepMatchArgumentsList]?
}pub struct TestStepFinished {
testCaseStartedId : String
testStepId : String
testStepResult : TestStepResult
timestamp : Timestamp
}impl ToJson for TestStepFinishedimpl FromJson for TestStepFinishedpub struct TestStepResult {
duration : Duration
status : TestStepResultStatus
message : String?
exception : Exception?
}impl ToJson for TestStepResultimpl FromJson for TestStepResultpub enum TestStepResultStatus {
Unknown
Passed
Skipped
Pending
Undefined
Ambiguous
Failed
}impl ToJson for TestStepResultStatusimpl FromJson for TestStepResultStatusimpl ToJson for TestStepStartedimpl FromJson for TestStepStartedpub struct Timestamp {
seconds : Int
nanos : Int
}pub struct UndefinedParameterType {
expression : String
name : String
}impl ToJson for UndefinedParameterTypeimpl FromJson for UndefinedParameterTypeInstall
Download zipCucumber Messages protocol types for MoonBit with JSON serialization and NDJSON streaming
Dependencies