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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This folder contains integration tests for the reporter. They don't use `node:test` as driver of the test runs, as you can't run `node:test` within `node:test`.

Instead, the script `index.ts` runs all the tests in each fixture folder, comparing the reporter's results with `result.txt`.
Instead, the script `index.ts` runs all the tests in each fixture folder, comparing the reporter's results with `result.$NODE_MAJOR_VERSION.txt` (or `result.txt` as a fallback if a node-specific result file does not exist).

## Running all tests

Expand Down

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
7) level 0


3 passing (132ms)
3 passing (140ms)
7 failing
1 cancelled

Expand Down Expand Up @@ -64,9 +64,9 @@
+ 1

 at TestContext.<anonymous> (integration-tests/fixture-tests/nested-test/test.ts:29:22)
 at Test.runInAsyncScope (node:async_hooks:211:14)
 at Test.run (node:internal/test_runner/test:979:25)
 at Test.start (node:internal/test_runner/test:877:17)
 at Test.runInAsyncScope (node:async_hooks:214:14)
 at Test.run (node:internal/test_runner/test:1047:25)
 at Test.start (node:internal/test_runner/test:944:17)
 at startSubtestAfterBootstrap (node:internal/test_runner/harness:296:17)
 at run (node:internal/test_runner/harness:307:12)
 at test (node:internal/test_runner/harness:316:12)
Expand All @@ -82,18 +82,18 @@

Error: error with cause
 at TestContext.<anonymous> (integration-tests/fixture-tests/nested-test/test.ts:33:21)
 at Test.runInAsyncScope (node:async_hooks:211:14)
 at Test.run (node:internal/test_runner/test:979:25)
 at Test.start (node:internal/test_runner/test:877:17)
 at Test.runInAsyncScope (node:async_hooks:214:14)
 at Test.run (node:internal/test_runner/test:1047:25)
 at Test.start (node:internal/test_runner/test:944:17)
 at startSubtestAfterBootstrap (node:internal/test_runner/harness:296:17)
 at run (node:internal/test_runner/harness:307:12)
 at test (node:internal/test_runner/harness:316:12)
 at TestContext.<anonymous> (integration-tests/fixture-tests/nested-test/test.ts:32:19)
[cause]: Error: cause
 at TestContext.<anonymous> (integration-tests/fixture-tests/nested-test/test.ts:34:24)
 at Test.runInAsyncScope (node:async_hooks:211:14)
 at Test.run (node:internal/test_runner/test:979:25)
 at Test.start (node:internal/test_runner/test:877:17)
 at Test.runInAsyncScope (node:async_hooks:214:14)
 at Test.run (node:internal/test_runner/test:1047:25)
 at Test.start (node:internal/test_runner/test:944:17)
 at startSubtestAfterBootstrap (node:internal/test_runner/harness:296:17)
 at run (node:internal/test_runner/harness:307:12)
 at test (node:internal/test_runner/harness:316:12)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
level 0
level 1
level 2
✔ nested test
1) assertion error in nested test
2) error with cause in nested test
level 0
level 1
level 2
✔ nested test
3) assertion error in nested test
4) error with cause in nested test
✔ unawaited test 1
✔ unawaited test 2

5) level 2

6) level 1

7) level 0


4 passing (139ms)
7 failing

1) level 0
level 1
level 2
assertion error in nested test:

AssertionError: Expected values to be strictly equal
- Expected
+ Received

- 2
+ 1

 at TestContext.<anonymous> (integration-tests/fixture-tests/nested-test/test.ts:12:16)

2) level 0
level 1
level 2
error with cause in nested test:

Error: error with cause
 at TestContext.<anonymous> (integration-tests/fixture-tests/nested-test/test.ts:16:15)
[cause]: Error: cause
 at TestContext.<anonymous> (integration-tests/fixture-tests/nested-test/test.ts:17:18)

3) level 0
level 1
level 2
level 0
level 1
level 2
assertion error in nested test:

AssertionError: Expected values to be strictly equal
- Expected
+ Received

- 2
+ 1

 at TestContext.<anonymous> (integration-tests/fixture-tests/nested-test/test.ts:29:22)

4) level 0
level 1
level 2
level 0
level 1
level 2
error with cause in nested test:

Error: error with cause
 at TestContext.<anonymous> (integration-tests/fixture-tests/nested-test/test.ts:33:21)
[cause]: Error: cause
 at TestContext.<anonymous> (integration-tests/fixture-tests/nested-test/test.ts:34:24)

5) level 0
level 1
level 2
level 0
level 1
level 2:

Error: 2 subtests failed

6) level 0
level 1
level 2
level 0
level 1:

Error: 1 subtest failed

7) level 0
level 1
level 2
level 0:

Error: 1 subtest failed

11 changes: 9 additions & 2 deletions v-next/hardhat-node-test-reporter/integration-tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,16 @@ for (const entry of entries) {
const start = lines.findIndex((l) => l.startsWith("Node.js"));
const output = lines.slice(start + 1).join("\n");

// We're saving the actual outptu in case one needs to access it. It is .gitignored.
// We're saving the actual outptut in case one needs to access it. It is .gitignored.
writeFileSync(entryPath + "/result.actual.txt", output);
const expectedOutput = readFileSync(entryPath + "/result.txt", "utf8");
// First, we try to access node version specific result file. If it doesn't
// exist, we fallback to the generic result file.
const nodeMajorVersion = process.version.split(".")[0];
let resultTxt = path.join(entryPath, `result.${nodeMajorVersion}.txt`);
if (!existsSync(resultTxt)) {
resultTxt = path.join(entryPath, "result.txt");
}
const expectedOutput = readFileSync(resultTxt, "utf8");

const normalizedOutput = normalizeOutput(entry, output);
const normalizedExpectedOutput = normalizeOutput(entry, expectedOutput);
Expand Down
25 changes: 19 additions & 6 deletions v-next/hardhat-node-test-reporter/scripts/regenerate-fixtures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,28 @@ for dir in $dirs; do
fi
fi

node --import tsx/esm --test --test-reporter=./dist/src/reporter.js $options $dir/*.ts --color > $dir/result.txt || true # Ignore failures, as they are expected
# TODO: If we ever encounter more tests that are sensitive to the node version,
# we should either add a more robust way of detecting such tests or version
# all the test result files.
result_file_name="result"
if [ "$dir" == "integration-tests/fixture-tests/nested-test" ]; then
node_major_version="$(node --version | cut -d. -f1)"
result_file_name="result.$node_major_version"
fi

result_txt="$dir/$result_file_name.txt"
result_html="$dir/$result_file_name.html"
result_svg="$dir/$result_file_name.svg"

node --import tsx/esm --test --test-reporter=./dist/src/reporter.js $options $dir/*.ts --color > "$result_txt" || true # Ignore failures, as they are expected

if grep -q '^Node\.js' $dir/result.txt; then
sed -i '1,/^Node\.js/d' $dir/result.txt;
if grep -q '^Node\.js' "$result_txt"; then
sed -i '1,/^Node\.js/d' "$result_txt";
fi

cat $dir/result.txt | aha --black > $dir/result.html;
cat "$result_txt" | aha --black > "$result_html";

wkhtmltoimage --quiet --format svg $dir/result.html $dir/result.svg;
wkhtmltoimage --quiet --format svg "$result_html" "$result_svg";

rm $dir/result.html
rm "$result_html";
done