Skip to content

Commit

Permalink
fix: update docs to show global regex & add test
Browse files Browse the repository at this point in the history
Signed-off-by: Chapman Pendery <[email protected]>
  • Loading branch information
cpendery committed Feb 29, 2024
1 parent 8ddbcde commit 7d81e1b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ import { test, expect } from "@microsoft/tui-test";
test("make a regex assertion", async ({ terminal }) => {
terminal.write("ls -l\r")

await expect(terminal.getByText(/total [0-9]{3}/m)).toBeVisible();
await expect(terminal.getByText(/total [0-9]{3}/g)).toBeVisible();
});
```

Expand Down
2 changes: 1 addition & 1 deletion examples/assertions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test.use({ shell: Shell.Powershell });
test("make a regex assertion", async ({ terminal }) => {
terminal.write("dir | measure\r");

await expect(terminal.getByText(/Count\s*:\s*[0-9]{2}/m)).toBeVisible();
await expect(terminal.getByText(/Count\s*:\s*[0-9]{2}/g)).toBeVisible();
});

test("make a text assertion", async ({ terminal }) => {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

40 changes: 40 additions & 0 deletions test/__snapshots__/e2e.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
// TUI Test Snapshot v1

exports[`ctrl+c 1`] = String.raw`
╭────────────────────────────────────────────────────────────────────────────────╮
│> │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
╰────────────────────────────────────────────────────────────────────────────────╯
`;

exports[`ctrl+c 1 1`] = String.raw`
╭────────────────────────────────────────────────────────────────────────────────╮
│> ^C │
│> │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
╰────────────────────────────────────────────────────────────────────────────────╯
`;

exports[`resize 1`] = String.raw`
╭────────────────────────────────────────────────────────────────────────────────╮
│> foo │
Expand Down
16 changes: 16 additions & 0 deletions test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ const isWindows = os.platform() == "win32";
const isNotMacOS = os.platform() != "darwin";
const isLinux = os.platform() == "linux";

test.describe("locators", () => {
test.describe("getByText", () => {
test("string driven", async ({ terminal }) => {
await expect(terminal.getByText(">")).toBeVisible();
});

test("regex driven", async ({ terminal }) => {
await expect(terminal.getByText(/>/g)).toBeVisible();
});

test.fail("regex driven non-global regex", async ({ terminal }) => {
await expect(terminal.getByText(/>/m)).toBeVisible();
});
});
});

test.describe("key controls", () => {
test("left key", async ({ terminal }) => {
terminal.write("bar");
Expand Down

0 comments on commit 7d81e1b

Please sign in to comment.