-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b2896b8
commit 0b5d89e
Showing
8 changed files
with
200 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: 2 | ||
updates: | ||
|
||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
# Check for updates to GitHub Actions every week | ||
interval: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: ci | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
test: | ||
runs-on: ${{ matrix.os }} | ||
timeout-minutes: 10 | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
deno: ["canary", "v1.x"] | ||
os: [macOS-latest, windows-latest, ubuntu-latest] | ||
include: | ||
- os: ubuntu-latest | ||
cache_path: ~/.cache/deno/ | ||
- os: macos-latest | ||
cache_path: ~/Library/Caches/deno/ | ||
- os: windows-latest | ||
cache_path: ~\AppData\Local\deno\ | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Deno | ||
uses: denoland/setup-deno@v1 | ||
with: | ||
deno-version: ${{ matrix.deno }} | ||
|
||
- name: Verify formatting | ||
run: deno fmt --check | ||
|
||
- name: Run linter | ||
run: deno lint | ||
|
||
- name: Cache dependencies and Chrome | ||
uses: actions/cache@v4 | ||
with: | ||
path: | | ||
${{ matrix.cache_path }}deps | ||
${{ matrix.cache_path }}deno_puppeteer | ||
key: ${{ runner.os }}-${{ hashFiles('**/*deps.ts', 'tests/fixture_twind_hydrate/twind.config.ts') }} | ||
|
||
- name: Install Chromium | ||
run: deno run -A --unstable https://deno.land/x/puppeteer@16.2.0/install.ts | ||
env: | ||
PUPPETEER_PRODUCT: chrome | ||
|
||
- name: Type check project | ||
run: deno task check | ||
|
||
- name: Run tests | ||
run: deno task test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ | |
_fresh/ | ||
# npm dependencies | ||
node_modules/ | ||
# test coverage directory | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { assertEquals, assertMatch } from "$std/assert/mod.ts"; | ||
import { createId } from "utils/id.ts"; | ||
|
||
Deno.test("returns a string of length 8 by default", () => { | ||
const id = createId(); | ||
assertEquals(id.length, 8); | ||
}); | ||
|
||
Deno.test("returns a string of custom length when specified", () => { | ||
const id = createId(12); | ||
assertEquals(id.length, 12); | ||
}); | ||
|
||
Deno.test("returns a string containing letters and numbers", () => { | ||
const id = createId(); | ||
assertMatch(id, /^[a-zA-Z0-9]+$/); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { createHandler, ServeHandlerInfo } from "$fresh/server.ts"; | ||
import manifest from "../fresh.gen.ts"; | ||
import config from "../fresh.config.ts"; | ||
import { assertEquals, assertExists } from "$std/assert/mod.ts"; | ||
|
||
const CONNECTION_INFO: ServeHandlerInfo = { | ||
remoteAddr: { | ||
hostname: "127.0.0.1", | ||
port: 53496, | ||
transport: "tcp", | ||
}, | ||
}; | ||
|
||
const handler = await createHandler(manifest, config); | ||
|
||
Deno.test("GET /", async () => { | ||
const response = await handler( | ||
new Request("http://127.0.0.1/"), | ||
CONNECTION_INFO, | ||
); | ||
|
||
assertEquals(response.status, 200); | ||
}); | ||
|
||
Deno.test("POST /", async () => { | ||
const formData = new FormData(); | ||
formData.append("content", "Hello, Deno!"); | ||
|
||
const response = await handler( | ||
new Request("http://127.0.0.1/", { method: "POST", body: formData }), | ||
CONNECTION_INFO, | ||
); | ||
|
||
assertEquals(response.status, 302); | ||
assertExists(response.headers.get("Location")); | ||
}); | ||
|
||
Deno.test("POST / invalid request", async () => { | ||
const formData = new FormData(); | ||
formData.append("content", new Blob([JSON.stringify({ hello: "deno" })])); | ||
|
||
const response = await handler( | ||
new Request("http://127.0.0.1/", { method: "POST", body: formData }), | ||
CONNECTION_INFO, | ||
); | ||
|
||
assertEquals(response.status, 400); | ||
const body = await response.text(); | ||
assertEquals(body, "invalid request"); | ||
}); | ||
|
||
Deno.test("POST / request body too large", async () => { | ||
const formData = new FormData(); | ||
const paste = await new Blob(["deno".repeat(64 * 1024)]).text(); | ||
formData.append("content", paste); | ||
|
||
const response = await handler( | ||
new Request("http://127.0.0.1/", { method: "POST", body: formData }), | ||
CONNECTION_INFO, | ||
); | ||
|
||
assertEquals(response.status, 400); | ||
const body = await response.text(); | ||
assertEquals(body, "paste contents cannot exceed 64 KiB"); | ||
}); | ||
|
||
Deno.test("POST / error", async () => { | ||
const response = await handler( | ||
new Request("http://127.0.0.1/", { method: "POST" }), | ||
CONNECTION_INFO, | ||
); | ||
|
||
assertEquals(response.status, 500); | ||
const body = await response.text(); | ||
assertEquals(body, "server error"); | ||
}); | ||
|
||
Deno.test("GET /:id", async () => { | ||
const formData = new FormData(); | ||
formData.append("content", "Hello, Deno!"); | ||
|
||
let response = await handler( | ||
new Request("http://127.0.0.1/", { method: "POST", body: formData }), | ||
CONNECTION_INFO, | ||
); | ||
|
||
const id = response.headers.get("Location")?.split("/").pop(); | ||
assertExists(id); | ||
|
||
response = await handler( | ||
new Request(`http://127.0.0.1/${id}`), | ||
CONNECTION_INFO, | ||
); | ||
|
||
assertEquals(response.status, 200); | ||
const body = await response.text(); | ||
assertEquals(body, "Hello, Deno!"); | ||
}); | ||
|
||
Deno.test("GET /:id not found", async () => { | ||
const response = await handler( | ||
new Request(`http://127.0.0.1/1234`), | ||
CONNECTION_INFO, | ||
); | ||
|
||
assertEquals(response.status, 404); | ||
const body = await response.text(); | ||
assertEquals(body, "paste not found"); | ||
}); |