Skip to content

Commit b42e649

Browse files
committed
Added comments and error formatting
1 parent 52fb95f commit b42e649

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

utils/js/runtimeTests.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @license
2+
* @license Apache-2.0
33
* Copyright 2020 The Closure Compiler Authors.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -74,15 +74,37 @@ describe('Runtime tests', () => {
7474

7575
it(`should pass test suite ${path.basename(testUrl)}`, async () => {
7676
const { window } = new JSDOM(TEST_DOC, {
77+
/**
78+
* This does not actually run a server of any kind, it only informs the
79+
* DOM what to put in `window.location.origin`. By default, this is
80+
* `null`, and any non-HTTPS URL field here will throw an error in the
81+
* test suite
82+
*/
7783
url: 'https://localhost:42',
84+
/**
85+
* This flag will allow the execution of `<script>` tags that are added
86+
* to the DOM after the `onload` event, i.e., those that are added by
87+
* `goog.module` and `goog.require`.
88+
*/
7889
runScripts: 'dangerously',
90+
/**
91+
* Pipe `console.log` to our virtual console.
92+
*/
7993
virtualConsole
8094
});
8195

8296
try {
8397
await TestIsFinished;
8498
} catch (e) {
85-
fail(`Failed test in suite ${testName}: \n${chalk.red(e)}\n`);
99+
// Format the error a bit: first line red, rest unformatted.
100+
const errorLines = e.toString().split('\n');
101+
let formattedError;
102+
for (let i = 0; i < errorLines.length; i++) {
103+
formattedError += i === 0
104+
? chalk.red(errorLines[i])
105+
: errorLines[i];
106+
}
107+
fail(`Failed test in suite ${testName}: \n${formattedError}\n`);
86108
}
87109
console.log(`Passed all tests in suite ${testName}`);
88110
});

0 commit comments

Comments
 (0)