Skip to content

Commit bc288d0

Browse files
committed
more on testing 16
1 parent 06804eb commit bc288d0

File tree

6 files changed

+178
-210
lines changed

6 files changed

+178
-210
lines changed

chapter_16_javascript.asciidoc

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -642,11 +642,12 @@ If you refresh the browser, you should see that all passes:
642642
[role="jasmine-output"]
643643
[subs="specialcharacters,quotes"]
644644
----
645-
2 specs, 0 failures, randomized with seed 12345 finished in 0.01s
645+
2 specs, 0 failures, randomized with seed 12345 finished in 0.005s
646+
646647
647648
Superlists tests
648649
* check we know how to hide things
649-
* sense check our html fixture
650+
* sense-check our html fixture
650651
----
651652
====
652653

@@ -664,7 +665,7 @@ Now that we're acquainted with our JavaScript testing tools,
664665
we can switch back to just one test and start to write the real thing:
665666

666667
[role="sourcecode small-code"]
667-
.src/lists/static/tests/spec.js (ch16l012)
668+
.src/lists/static/tests/Spec.js (ch16l012)
668669
====
669670
[source,javascript]
670671
----
@@ -706,7 +707,7 @@ That gives us our expected failure:
706707
[role="jasmine-output"]
707708
[subs="specialcharacters,quotes"]
708709
----
709-
2 specs, 1 failure, randomized with seed 12345 finished in 0.007s
710+
2 specs, 1 failure, randomized with seed 12345 finished in 0.005s
710711
711712
Spec List | Failures
712713
@@ -742,7 +743,7 @@ That doesn't work! We get an _unexpected error_:
742743
[role="jasmine-output"]
743744
[subs="specialcharacters,quotes"]
744745
----
745-
2 specs, 2 failures, randomized with seed 12345 finished in 0.008s
746+
2 specs, 2 failures, randomized with seed 12345 finished in 0.005s
746747
Error during loading: TypeError: textInput is null in file:///...goat-book/src/lists/static/lists.js line 2
747748
Spec List | Failures
748749
@@ -905,7 +906,7 @@ And that will actually get our tests passing!
905906
[role="jasmine-output"]
906907
[subs="specialcharacters,quotes"]
907908
----
908-
2 specs, 0 failures, randomized with seed 12345 finished in 0.007s
909+
2 specs, 0 failures, randomized with seed 12345 finished in 0.005s
909910
910911
911912
Superlists tests
@@ -954,7 +955,7 @@ Oh dear, sure enough the tests just pass:
954955
[role="jasmine-output"]
955956
[subs="specialcharacters,quotes"]
956957
----
957-
2 specs, 0 failures, randomized with seed 12345 finished in 0.008s
958+
2 specs, 0 failures, randomized with seed 12345 finished in 0.005s
958959
959960
960961
Superlists tests
@@ -994,7 +995,7 @@ That gives us our expected failure:
994995
[role="jasmine-output"]
995996
[subs="specialcharacters,quotes"]
996997
----
997-
3 specs, 1 failure, randomized with seed 12345 finished in 0.008s
998+
3 specs, 1 failure, randomized with seed 12345 finished in 0.005s
998999
9991000
Spec List | Failures
10001001
@@ -1128,7 +1129,7 @@ We've only refactored the tests so far, let's check they still pass:
11281129
[role="jasmine-output"]
11291130
[subs="specialcharacters,quotes"]
11301131
----
1131-
3 specs, 0 failures, randomized with seed 12345 finished in 0.006s
1132+
3 specs, 0 failures, randomized with seed 12345 finished in 0.005s
11321133
11331134
11341135
Superlists tests
@@ -1174,7 +1175,7 @@ Now we look at the tests:
11741175
[role="jasmine-output"]
11751176
[subs="specialcharacters,quotes"]
11761177
----
1177-
3 specs, 0 failures, randomized with seed 12345 finished in 0.01s
1178+
3 specs, 0 failures, randomized with seed 12345 finished in 0.005s
11781179
11791180
11801181
Superlists tests
@@ -1216,7 +1217,7 @@ And the tests still pass:
12161217
[role="jasmine-output"]
12171218
[subs="specialcharacters,quotes"]
12181219
----
1219-
3 specs, 0 failures, randomized with seed 12345 finished in 0.011s
1220+
3 specs, 0 failures, randomized with seed 12345 finished in 0.005s
12201221
----
12211222

12221223

@@ -1238,7 +1239,7 @@ Phew, that gives us a failure:
12381239
[role="jasmine-output"]
12391240
[subs="specialcharacters,quotes"]
12401241
----
1241-
3 specs, 1 failure, randomized with seed 12345 finished in 0.01s
1242+
3 specs, 1 failure, randomized with seed 12345 finished in 0.005s
12421243
12431244
Spec List | Failures
12441245
@@ -1355,7 +1356,7 @@ Oh dear, it seems like that doesn't quite work:
13551356
[role="jasmine-output"]
13561357
[subs="specialcharacters,quotes"]
13571358
----
1358-
3 specs, 1 failure, randomized with seed 12345 finished in 0.012s
1359+
3 specs, 1 failure, randomized with seed 12345 finished in 0.005s
13591360
13601361
Spec List | Failures
13611362
@@ -1397,7 +1398,7 @@ That gets us back to passing tests:
13971398
[role="jasmine-output"]
13981399
[subs="specialcharacters,quotes"]
13991400
----
1400-
3 specs, 0 failures, randomized with seed 12345 finished in 0.007s
1401+
3 specs, 0 failures, randomized with seed 12345 finished in 0.005s
14011402
14021403
14031404
Superlists tests

tests/book_parser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ def __init__(self, a_string):
9191
self.was_checked = False
9292
self.skip = False
9393
self.dofirst = None
94-
self.qunit_output = False
94+
self.jasmine_output = False
9595
self.against_server = False
9696
str.__init__(a_string)
9797

9898
@property
9999
def type(self) -> str:
100-
if self.qunit_output:
101-
return "qunit output"
100+
if self.jasmine_output:
101+
return "jasmine output"
102102
if "├" in self:
103103
return "tree"
104104
else:
@@ -182,15 +182,15 @@ def parse_listing(listing): # noqa: PLR0912
182182
listing.currentcontents = True
183183
return [listing]
184184

185-
elif "qunit-output" in classes:
185+
elif "jasmine-output" in classes:
186186
contents = (
187187
listing.cssselect(".content")[0]
188188
.text_content()
189189
.replace("\r\n", "\n")
190190
.strip("\n")
191191
)
192192
output = Output(contents)
193-
output.qunit_output = True
193+
output.jasmine_output = True
194194
output.skip = skip
195195
output.dofirst = dofirst
196196
return [output]

tests/book_tester.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from write_to_file import write_to_file
2121

2222
JASMINE_RUNNER = Path(__file__).parent / "run-js-spec.py"
23-
2423
# DO_SERVER_COMMANDS = True
2524
# if os.environ.get("CI") or os.environ.get("NO_SERVER_COMMANDS"):
2625
DO_SERVER_COMMANDS = False
@@ -349,6 +348,8 @@ def prep_database(self):
349348
self.sourcetree.run_command(f"python {self._manage_py()} migrate --noinput")
350349

351350
def assertLineIn(self, line, lines):
351+
if "\t" in line or "\t" in "\n".join(lines):
352+
print('tabz')
352353
if line not in lines:
353354
raise AssertionError(
354355
"%s not found in:\n%s" % (repr(line), "\n".join(repr(l) for l in lines))
@@ -530,14 +531,16 @@ def run_test_and_check_result(self, bdd=False):
530531
self.pos += 2
531532

532533
def run_js_tests(self, tests_path: Path):
533-
output = subprocess.check_output(
534-
[JASMINE_RUNNER, str(tests_path)],
534+
p = subprocess.run(
535+
["python", str(JASMINE_RUNNER), str(tests_path)],
536+
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
535537
# env={**os.environ, "OPENSSL_CONF": "/dev/null"},
536-
).decode()
537-
return output
538+
check=False,
539+
)
540+
return p.stdout.decode()
538541

539-
def check_qunit_output(self, expected_output):
540-
lists_tests = Path(self.tempdir) / "lists/static/tests/SpecRunner.html"
542+
def check_jasmine_output(self, expected_output):
543+
lists_tests = Path(self.tempdir) / "src/lists/static/tests/SpecRunner.html"
541544
assert lists_tests.exists()
542545
lists_run = self.run_js_tests(lists_tests)
543546
self.assert_console_output_correct(lists_run, expected_output)
@@ -850,8 +853,8 @@ def recognise_listing_and_process_it(self):
850853
elif listing.type == "server code listing":
851854
assert 0, "reimplement"
852855

853-
elif listing.type == "qunit output":
854-
self.check_qunit_output(listing)
856+
elif listing.type == "jasmine output":
857+
self.check_jasmine_output(listing)
855858
self.pos += 1
856859

857860
elif listing.type == "output":

tests/examples.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,14 @@
121121
<span class="kn">from</span> <span class="nn">django.conf.urls</span> <span class="kn">import</span> <span class="n">patterns</span><span class="p">,</span> <span class="n">include</span><span class="p">,</span> <span class="n">url</span>
122122
</pre></div></div></div>"""
123123

124-
OUTPUT_QUNIT = """
125-
<div class="listingblock qunit-output">
124+
JASMINE_OUTPUT = """
125+
<div class="listingblock jasmine-output">
126126
<div class="content">
127-
<pre>2 assertions of 2 passed, 0 failed.
128-
1. smoke test (2)</pre>
129-
</div>
127+
<pre>2 specs, 0 failures, randomized with seed 12345 finished in 0.01s
128+
129+
Superlists tests
130+
* check we know how to hide things
131+
* sense check our html fixture</pre>
130132
</div>
131133
"""
132134

tests/run-js-spec.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def run(path: Path):
3030
failed = False
3131

3232
def _el_text(sel, node: webdriver.Remote | WebElement = browser):
33-
return "\n".join(el.text for el in node.find_elements(By.CSS_SELECTOR, sel))
33+
raw = "\n".join(el.text for el in node.find_elements(By.CSS_SELECTOR, sel))
34+
return re.sub(r" 0\.\d+s", " 0.005s", raw)
3435

3536
try:
3637
browser.get(f"file:///{path}?seed=12345")
@@ -40,7 +41,7 @@ def _el_text(sel, node: webdriver.Remote | WebElement = browser):
4041
# print(entry)
4142

4243
print(
43-
f"{_el_text('.jasmine-overall-result')}\t\t{_el_text('.jasmine-duration')}"
44+
f"{_el_text('.jasmine-overall-result')} {_el_text('.jasmine-duration')}"
4445
)
4546

4647
print(_el_text(".jasmine-bar.jasmine-errored"))

0 commit comments

Comments
 (0)