Skip to content

Commit

Permalink
First cut at URL structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Sep 27, 2023
1 parent 31ce925 commit 5dfd5eb
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/src/pages/go/advanced-usage.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Advanced usage TODO.
1 change: 1 addition & 0 deletions docs/src/pages/go/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Getting started TODO.
94 changes: 94 additions & 0 deletions docs/src/pages/go/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
## selfie is literal

Sure, you could write your assertions like this.

```java
@Test
public void login_then_redirect() {
given().redirects().follow(false)
.post("/confirm/login/erjchFbCXxMlUfFXx3oYiO-Rj6zM7tRGdRV8ziqRn5Jh")
.then()
.cookie("login", AuthRequest.authTokenValue(dev, InitialData.LUKE));
}
```

But isn't this easier to read? And also more complete?

```java
@Test
public void login_then_redirect() {
expectSelfie(given().redirects().follow(false)
.post("/confirm/login/erjchFbCXxMlUfFXx3oYiO-Rj6zM7tRGdRV8ziqRn5Jh"))
.toBe()

}
```

The only reason we don't test that way already is that it's too tedious to write out that big string literal. Buf if you write this...

```java
@Test
public void blah() {
expectSelfie("blah").toBe_TODO();
}
```

... then selfie will rewrite the string literal for you when you run your tests. Unless you run the test on a CI server, in which case ERROR.

## selfie is lensable

Some snapshots are so big that it would be cumbersome to put them inline into your test code. So selfie helps you put them on disk.

```java
@Test
public void should_redirect() {
}
```

Here is a very simple test which snapshots the HTML served at various URLs.

```java
@Test public void gzipFavicon() {
expectSelfie(get("/favicon.ico", ContentEncoding.GZIP)).toMatchDisk();
}
@Test public void orderFlow() {
expectSelfie(get("/orders")).toMatchDisk("initial");
postOrder();
expectSelfie(get("/orders")).toMatchDisk("ordered");
}
```

This will generate a snapshot file like so:

```
╔═ gzipFavicon ═╗ base64 length 823 bytes
H4sIAAAAAAAA/8pIzcnJVyjPL8pJUQQAlQYXAAAA
╔═ orderFlow/initial ═╗
<html><body>
<button>Submit order</button>
</body></html>
╔═ orderFlow/ordered ═╗
<html><body>
<p>Thanks for your business!</p>
<details>
<summary>Order information</summary>
<p>Tracking #ABC123</p>
</details>
</body></html>
```

## selfie is like a filesystem

A great thing about snapshots is that they are fast to write and update. A downside is that the asserted value is opaque. But it doesn't have to be! Just swap `toMatchDisk` for `toBe`.

```java
@Test public void preventCssBloat() {
// selfie can update this literal value for you ▼
int size = expectSelfie(get("/index.css").length).toBe(5_236);
if (size > 100_000) {
Assert.fail("CSS has gotten too big!");
}
}
```

Now we can see at a glance how a PR has affected the bundled size of our CSS. We can easily automate manual processes and turn "test execution time" values into source code constants, without wasting programmer time on fragile manual workflows.
1 change: 1 addition & 0 deletions docs/src/pages/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Redirect to `/jvm`, or straight-up copy of `/jvm`.
1 change: 1 addition & 0 deletions docs/src/pages/js/advanced-usage.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Advanced usage TODO.
1 change: 1 addition & 0 deletions docs/src/pages/js/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Getting started TODO.
94 changes: 94 additions & 0 deletions docs/src/pages/js/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
## selfie is literal

Sure, you could write your assertions like this.

```java
@Test
public void login_then_redirect() {
given().redirects().follow(false)
.post("/confirm/login/erjchFbCXxMlUfFXx3oYiO-Rj6zM7tRGdRV8ziqRn5Jh")
.then()
.cookie("login", AuthRequest.authTokenValue(dev, InitialData.LUKE));
}
```

But isn't this easier to read? And also more complete?

```java
@Test
public void login_then_redirect() {
expectSelfie(given().redirects().follow(false)
.post("/confirm/login/erjchFbCXxMlUfFXx3oYiO-Rj6zM7tRGdRV8ziqRn5Jh"))
.toBe()

}
```

The only reason we don't test that way already is that it's too tedious to write out that big string literal. Buf if you write this...

```java
@Test
public void blah() {
expectSelfie("blah").toBe_TODO();
}
```

... then selfie will rewrite the string literal for you when you run your tests. Unless you run the test on a CI server, in which case ERROR.

## selfie is lensable

Some snapshots are so big that it would be cumbersome to put them inline into your test code. So selfie helps you put them on disk.

```java
@Test
public void should_redirect() {
}
```

Here is a very simple test which snapshots the HTML served at various URLs.

```java
@Test public void gzipFavicon() {
expectSelfie(get("/favicon.ico", ContentEncoding.GZIP)).toMatchDisk();
}
@Test public void orderFlow() {
expectSelfie(get("/orders")).toMatchDisk("initial");
postOrder();
expectSelfie(get("/orders")).toMatchDisk("ordered");
}
```

This will generate a snapshot file like so:

```
╔═ gzipFavicon ═╗ base64 length 823 bytes
H4sIAAAAAAAA/8pIzcnJVyjPL8pJUQQAlQYXAAAA
╔═ orderFlow/initial ═╗
<html><body>
<button>Submit order</button>
</body></html>
╔═ orderFlow/ordered ═╗
<html><body>
<p>Thanks for your business!</p>
<details>
<summary>Order information</summary>
<p>Tracking #ABC123</p>
</details>
</body></html>
```

## selfie is like a filesystem

A great thing about snapshots is that they are fast to write and update. A downside is that the asserted value is opaque. But it doesn't have to be! Just swap `toMatchDisk` for `toBe`.

```java
@Test public void preventCssBloat() {
// selfie can update this literal value for you ▼
int size = expectSelfie(get("/index.css").length).toBe(5_236);
if (size > 100_000) {
Assert.fail("CSS has gotten too big!");
}
}
```

Now we can see at a glance how a PR has affected the bundled size of our CSS. We can easily automate manual processes and turn "test execution time" values into source code constants, without wasting programmer time on fragile manual workflows.
1 change: 1 addition & 0 deletions docs/src/pages/jvm/advanced-usage.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Advanced usage TODO.
1 change: 1 addition & 0 deletions docs/src/pages/jvm/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Getting started TODO.
94 changes: 94 additions & 0 deletions docs/src/pages/jvm/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
## selfie is literal

Sure, you could write your assertions like this.

```java
@Test
public void login_then_redirect() {
given().redirects().follow(false)
.post("/confirm/login/erjchFbCXxMlUfFXx3oYiO-Rj6zM7tRGdRV8ziqRn5Jh")
.then()
.cookie("login", AuthRequest.authTokenValue(dev, InitialData.LUKE));
}
```

But isn't this easier to read? And also more complete?

```java
@Test
public void login_then_redirect() {
expectSelfie(given().redirects().follow(false)
.post("/confirm/login/erjchFbCXxMlUfFXx3oYiO-Rj6zM7tRGdRV8ziqRn5Jh"))
.toBe()

}
```

The only reason we don't test that way already is that it's too tedious to write out that big string literal. Buf if you write this...

```java
@Test
public void blah() {
expectSelfie("blah").toBe_TODO();
}
```

... then selfie will rewrite the string literal for you when you run your tests. Unless you run the test on a CI server, in which case ERROR.

## selfie is lensable

Some snapshots are so big that it would be cumbersome to put them inline into your test code. So selfie helps you put them on disk.

```java
@Test
public void should_redirect() {
}
```

Here is a very simple test which snapshots the HTML served at various URLs.

```java
@Test public void gzipFavicon() {
expectSelfie(get("/favicon.ico", ContentEncoding.GZIP)).toMatchDisk();
}
@Test public void orderFlow() {
expectSelfie(get("/orders")).toMatchDisk("initial");
postOrder();
expectSelfie(get("/orders")).toMatchDisk("ordered");
}
```

This will generate a snapshot file like so:

```
╔═ gzipFavicon ═╗ base64 length 823 bytes
H4sIAAAAAAAA/8pIzcnJVyjPL8pJUQQAlQYXAAAA
╔═ orderFlow/initial ═╗
<html><body>
<button>Submit order</button>
</body></html>
╔═ orderFlow/ordered ═╗
<html><body>
<p>Thanks for your business!</p>
<details>
<summary>Order information</summary>
<p>Tracking #ABC123</p>
</details>
</body></html>
```

## selfie is like a filesystem

A great thing about snapshots is that they are fast to write and update. A downside is that the asserted value is opaque. But it doesn't have to be! Just swap `toMatchDisk` for `toBe`.

```java
@Test public void preventCssBloat() {
// selfie can update this literal value for you ▼
int size = expectSelfie(get("/index.css").length).toBe(5_236);
if (size > 100_000) {
Assert.fail("CSS has gotten too big!");
}
}
```

Now we can see at a glance how a PR has affected the bundled size of our CSS. We can easily automate manual processes and turn "test execution time" values into source code constants, without wasting programmer time on fragile manual workflows.

0 comments on commit 5dfd5eb

Please sign in to comment.