Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions bin/results.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ class TestRunner
if typeof obj[key] is 'object' and obj[key] isnt null
if obj[key]["type"]? and obj[key]["expression"]?["callee"]?["name"]?
if obj[key]["type"] is "ExpressionStatement" and obj[key]["expression"]["callee"]["name"] is "it"
if obj[key]["expression"]?["arguments"]?[0]?["value"]? and obj[key]["expression"]?["arguments"]?[1]?["loc"]?
@astData.push({name: obj[key]["expression"]["arguments"][0]["value"], loc: obj[key]["expression"]["arguments"][1]["loc"]})
name = @read_test_name(obj[key]["expression"]?["arguments"]?[0])
if name? and obj[key]["expression"]?["arguments"]?[1]?["loc"]?
@astData.push({name: name, loc: obj[key]["expression"]["arguments"][1]["loc"]})
else
console.log("incorrect")
else
Expand All @@ -93,6 +94,17 @@ class TestRunner
search_keys(obj[key])
search_keys(ast)

read_test_name: (node) =>
return unless node?
return node.value if typeof node.value is "string"
return unless node.type is "BinaryExpression" and node.operator is "+"

left = @read_test_name(node.left)
right = @read_test_name(node.right)
return unless left? and right?

left + right

write_result: (status, test_cases = [], message = "") ->
result =
version: 2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ExampleMultilineTestName
answer: -> 42

module.exports = ExampleMultilineTestName
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ExampleMultilineTestName = require './example-multiline-test-name'

describe 'Multiline test name', ->
example = new ExampleMultilineTestName()

it 'supports test descriptions that are split ' +
'across lines', ->
result = example.answer()
expect(result).toEqual 42
12 changes: 12 additions & 0 deletions tests/example-multiline-test-name/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 2,
"status": "pass",
"tests": [
{
"name": "supports test descriptions that are split across lines",
"test_code": "result = example.answer()\nexpect(result).toEqual 42",
"status": "pass",
"message": null
}
]
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing newline?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the golden tests are like that because we use JSON.stringify() to serialize the results.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does feel a bit weird now that you point it out so I can make a separate PR adding trailing newlines.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you load the files, you can strip trailing newlines 😁