|
2 | 2 | import testRecordsJson from "../../../../dist/tests/commentTests.json?json"; |
3 | 3 | import type { TestFuncRecord } from "../../../test/commentTestUtils"; |
4 | 4 | import TestGraph from "./TestGraph.svelte"; |
5 | | - import { runTest, type TestResults } from "./utils"; |
| 5 | + import { |
| 6 | + runTest, |
| 7 | + type TestResults, |
| 8 | + initialize as initializeUtils, |
| 9 | + } from "./utils"; |
| 10 | +
|
6 | 11 | const testRecords = testRecordsJson as TestFuncRecord[]; |
7 | 12 |
|
8 | | - const testResults = testRecords.map((record) => { |
9 | | - let results: TestResults[]; |
10 | | - try { |
11 | | - results = runTest(record); |
12 | | - } catch (error) { |
13 | | - console.trace( |
14 | | - `\nFailed running tests for ${record.language}: ${record.name}\n`, |
15 | | - error, |
16 | | - ); |
17 | | - results = [ |
18 | | - { |
19 | | - reqName: "Tests", |
20 | | - reqValue: "Failed to complete", |
21 | | - failure: `${error}`, |
22 | | - }, |
23 | | - ]; |
24 | | - } |
25 | | - return { |
26 | | - record, |
27 | | - failed: !results.every((result) => result.failure === null), |
28 | | - results, |
29 | | - }; |
30 | | - }); |
| 13 | + async function runAllTests() { |
| 14 | + await initializeUtils(); |
| 15 | +
|
| 16 | + const testResults = testRecords.map((record) => { |
| 17 | + let results: TestResults[]; |
| 18 | + try { |
| 19 | + results = runTest(record); |
| 20 | + } catch (error) { |
| 21 | + console.trace( |
| 22 | + `\nFailed running tests for ${record.language}: ${record.name}\n`, |
| 23 | + error, |
| 24 | + ); |
| 25 | + results = [ |
| 26 | + { |
| 27 | + reqName: "Tests", |
| 28 | + reqValue: "Failed to complete", |
| 29 | + failure: `${error}`, |
| 30 | + }, |
| 31 | + ]; |
| 32 | + } |
| 33 | + return { |
| 34 | + record, |
| 35 | + failed: !results.every((result) => result.failure === null), |
| 36 | + results, |
| 37 | + }; |
| 38 | + }); |
31 | 39 |
|
32 | | - const failCount = testResults.filter(({ failed }) => failed).length; |
| 40 | + const failCount = testResults.filter(({ failed }) => failed).length; |
| 41 | +
|
| 42 | + return { testResults, failCount }; |
| 43 | + } |
33 | 44 |
|
34 | 45 | let simplify: boolean = true; |
35 | 46 | let verbose: boolean = false; |
|
54 | 65 | <input type="checkbox" id="showAll" bind:checked={showAll} /> |
55 | 66 | <label for="showAll">Show All</label> |
56 | 67 | </div> |
57 | | -<div class="content"> |
58 | | - <div class="summary" class:green={failCount === 0} class:red={failCount}> |
59 | | - {#if failCount === 0} |
60 | | - All tests pass. |
61 | | - {:else} |
62 | | - {failCount} failing test{failCount > 1 ? "s" : ""}. |
63 | | - {/if} |
64 | | - </div> |
65 | | - <div class="container"> |
66 | | - {#each testResults as { record, failed, results } (record)} |
67 | | - {#if failed || showAll} |
68 | | - <div class="code-side" data-failed={failed}> |
69 | | - <div class="test-name">{record.language}: {record.name}</div> |
70 | | - <div class="code"><pre>{record.code}</pre></div> |
71 | | - <div class="results"> |
72 | | - {#each results as { reqName, reqValue, failure } (reqName)} |
73 | | - {#if failure !== null} |
74 | | - <div class="result"> |
75 | | - {reqName}: {reqValue}; {failure} |
76 | | - </div> |
77 | | - {/if} |
78 | | - {/each} |
79 | | - </div> |
80 | | - </div> |
81 | | - <TestGraph {record} {simplify} {verbose} {trim} {flatSwitch} /> |
| 68 | +{#await runAllTests() then { failCount, testResults }} |
| 69 | + <div class="content"> |
| 70 | + <div class="summary" class:green={failCount === 0} class:red={failCount}> |
| 71 | + {#if failCount === 0} |
| 72 | + All tests pass. |
| 73 | + {:else} |
| 74 | + {failCount} failing test{failCount > 1 ? "s" : ""}. |
82 | 75 | {/if} |
83 | | - {/each} |
| 76 | + </div> |
| 77 | + <div class="container"> |
| 78 | + {#each testResults as { record, failed, results } (record)} |
| 79 | + {#if failed || showAll} |
| 80 | + <div class="code-side" data-failed={failed}> |
| 81 | + <div class="test-name">{record.language}: {record.name}</div> |
| 82 | + <div class="code"><pre>{record.code}</pre></div> |
| 83 | + <div class="results"> |
| 84 | + {#each results as { reqName, reqValue, failure } (reqName)} |
| 85 | + {#if failure !== null} |
| 86 | + <div class="result"> |
| 87 | + {reqName}: {reqValue}; {failure} |
| 88 | + </div> |
| 89 | + {/if} |
| 90 | + {/each} |
| 91 | + </div> |
| 92 | + </div> |
| 93 | + <TestGraph {record} {simplify} {verbose} {trim} {flatSwitch} /> |
| 94 | + {/if} |
| 95 | + {/each} |
| 96 | + </div> |
84 | 97 | </div> |
85 | | -</div> |
| 98 | +{/await} |
86 | 99 |
|
87 | 100 | <style> |
88 | 101 | .content { |
|
0 commit comments