Skip to content

Commit

Permalink
Merge pull request #586 from appsignal/update-span-tests
Browse files Browse the repository at this point in the history
Update span tests
  • Loading branch information
tombruijn authored Feb 2, 2022
2 parents 52f77e1 + e683f1f commit 9baec12
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions packages/nodejs/src/__tests__/span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type SpanData = {
span_id?: string
start_time?: number
trace_id?: string
attributes?: { [key: string]: string }
}

describe("RootSpan", () => {
Expand Down Expand Up @@ -52,14 +53,6 @@ describe("RootSpan", () => {
expect(traceId).toEqual(internal.trace_id)
})

it("exposes a start time", () => {
const { traceId } = span

expect(traceId).toBeDefined()
expect(internal.trace_id).toBeDefined()
expect(traceId).toEqual(internal.trace_id)
})

it("creates a new ChildSpan", () => {
const child = span.child()

Expand All @@ -85,6 +78,15 @@ describe("RootSpan", () => {
expect(internal.name).toEqual(name)
})

it("sets the category", () => {
const category = "test_category"

const span = new RootSpan().setCategory(category)
const internal = JSON.parse(span.toJSON())

expect(internal.attributes["appsignal:category"]).toEqual(category)
})

it("closes a span", () => {
span = new RootSpan().close()
internal = JSON.parse(span.toJSON())
Expand Down Expand Up @@ -142,32 +144,23 @@ describe("ChildSpan", () => {
expect(traceId).toEqual(internal.trace_id)
})

it("exposes a start time", () => {
const { traceId } = span

expect(traceId).toBeDefined()
expect(internal.trace_id).toBeDefined()
expect(traceId).toEqual(internal.trace_id)
})

it("creates a new ChildSpan", () => {
const child = span.child()

expect(child).toBeDefined()
expect(child).toBeInstanceOf(ChildSpan)
})

it("sets the name", () => {
const name = "test_span"
it("sets the category", () => {
const category = "test_category"

span = new ChildSpan({
traceId: "test_trace_id",
spanId: "parent_span_id"
}).setName(name)

}).setCategory(category)
internal = JSON.parse(span.toJSON())

expect(internal.name).toEqual(name)
expect(internal.attributes!["appsignal:category"]).toEqual(category)
})

it("closes a span", () => {
Expand Down

0 comments on commit 9baec12

Please sign in to comment.