Skip to content

Commit

Permalink
fix(cli): not to show 1 test when no tests are in the file (#7205)
Browse files Browse the repository at this point in the history
This is to fix an issue that caused `wing test` against an empty `some_file_name.w` file shows `Tests 1 passed (1)`.

See the issue #5852 for details.

Solution:
Instead of adding a dummy pass message, the function now returns early with a predefined message when there's no test case to avoid confusion later.

And I don't think it would need full E2E tests?

I am still exploring how to add test for this new test system behavior. Will mark the PR as ready after adding/updating test for it.

## Checklist

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [x] Tests added (always)
- [x] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.

Resolves #5852
  • Loading branch information
ChihweiLHBird authored Nov 6, 2024
1 parent cb705f3 commit 7f00098
Show file tree
Hide file tree
Showing 119 changed files with 179 additions and 394 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`printing test reports > results for files with no tests 1`] = `"pass ─ hello.w (no tests)"`;

exports[`printing test reports > verbose traces are not shown if debug mode is disabled 1`] = `
"fail ┌ hello.w » root/env0/test:test
│ sleeping for 500 ms
Expand Down
19 changes: 15 additions & 4 deletions packages/winglang/src/commands/test/test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { join } from "path";
import { BuiltinPlatform } from "@winglang/compiler";
import { LogLevel, TestResult, TraceType } from "@winglang/sdk/lib/std";
import chalk from "chalk";
import { describe, test, expect, beforeEach, afterEach, vi, SpyInstance } from "vitest";
import { describe, test, expect, beforeEach, afterEach, vi, MockInstance } from "vitest";
import { filterTests, renderTestReport, collectTestFiles, test as wingTest } from ".";
import * as resultsFn from "./results";
import { SnapshotMode } from "./snapshots";
Expand Down Expand Up @@ -45,10 +45,21 @@ describe("printing test reports", () => {
expect(testReport).toMatchSnapshot();
expect(testReport).toContain("Push (message=cool)");
});

test("results for files with no tests", async () => {
let inputResults: TestResult[] = [];
const testReport = await renderTestReport("hello.w", inputResults);

expect(testReport).toMatchSnapshot();
expect(testReport).toContain("(no tests)");

// verify that the the no dummy test results were added
expect(inputResults).toHaveLength(0);
});
});

describe("wing test (custom platform)", () => {
let logSpy: SpyInstance;
let logSpy: MockInstance;

beforeEach(() => {
chalk.level = 0;
Expand Down Expand Up @@ -208,7 +219,7 @@ describe("collectTestFiles", () => {
});

describe("output-file option", () => {
let writeResultsSpy: SpyInstance;
let writeResultsSpy: MockInstance;

beforeEach(() => {
chalk.level = 0;
Expand Down Expand Up @@ -304,7 +315,7 @@ describe("test-filter option", () => {
});

describe("retry and parallel options", () => {
let logSpy: SpyInstance;
let logSpy: MockInstance;

beforeEach(() => {
chalk.level = 0;
Expand Down
17 changes: 4 additions & 13 deletions packages/winglang/src/commands/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,10 @@ export async function renderTestReport(
0
);

// if there are no inflight tests, add a dummy "pass" result
// return early if there are no tests, return a pass output
// to indicate that compilation and preflight checks passed
if (results.length === 0) {
results.push({
pass: true,
path: "",
traces: [],
});
return `${chalk.green("pass")}${basename(entrypoint)} ${chalk.gray("(no tests)")}`;
}

for (const result of results.sort(sortTests)) {
Expand Down Expand Up @@ -307,13 +303,8 @@ export async function renderTestReport(
}

firstRow.push(basename(entrypoint));

if (result.path?.length > 0) {
firstRow.push(chalk.gray("»"));
firstRow.push(chalk.whiteBright(result.path.padEnd(longestPath)));
} else {
firstRow.push(chalk.gray("(no tests)"));
}
firstRow.push(chalk.gray("»"));
firstRow.push(chalk.whiteBright(result.path.padEnd(longestPath)));

// okay we are ready to print the test result

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions tests/doc_examples/valid/03-functions.md_example_1/main.w

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 0 additions & 22 deletions tests/doc_examples/valid/04-flow-controls.md_example_1/main.w

This file was deleted.

16 changes: 0 additions & 16 deletions tests/doc_examples/valid/04-flow-controls.md_example_2/main.w

This file was deleted.

23 changes: 0 additions & 23 deletions tests/doc_examples/valid/04-flow-controls.md_example_3/main.w

This file was deleted.

28 changes: 0 additions & 28 deletions tests/doc_examples/valid/04-flow-controls.md_example_4/main.w

This file was deleted.

4 changes: 0 additions & 4 deletions tests/doc_examples/valid/05-optionality.md_example_1/main.w

This file was deleted.

23 changes: 0 additions & 23 deletions tests/doc_examples/valid/06-json.md_example_1/main.w

This file was deleted.

10 changes: 0 additions & 10 deletions tests/doc_examples/valid/07-structs.md_example_1/main.w

This file was deleted.

12 changes: 0 additions & 12 deletions tests/doc_examples/valid/07-structs.md_example_2/main.w

This file was deleted.

21 changes: 0 additions & 21 deletions tests/doc_examples/valid/07-structs.md_example_3/main.w

This file was deleted.

17 changes: 0 additions & 17 deletions tests/doc_examples/valid/07-structs.md_example_4/main.w

This file was deleted.

32 changes: 0 additions & 32 deletions tests/doc_examples/valid/08-classes.md_example_4/main.w

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7f00098

Please sign in to comment.