Skip to content
Myr

chore: update examples (#137)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* chore(example): update blog test * `deploy` instead `publish`

authored by Yusuke Wada · committed by GitHub · parent fb76c36 · Browse files · 10 files+94 added−99 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

10 files+94 added−99 removed

  • tests:+79 added−84 removed
  • other:+15 added−15 removed

10 files+94 added−99 removed

modified:examples/basic/package.json+2 added-2 removed
modified:examples/basic/README.md+1 added-1 removed
deleted:examples/blog/src/controller.test.ts-84 removed
1import { app } from './index'2import type { Post } from './model'34describe('Root', () => {5 it('GET /', async () => {6 const req = new Request('http://localhost/')7 const res = await app.dispatch(req)8 expect(res.status).toBe(200)9 const body = (await res.json()) as any10 expect(body['message']).toBe('Hello')11 })12})1314describe('Blog API', () => {15 it('List', async () => {16 const req = new Request('http://localhost/posts')17 const res = await app.dispatch(req)18 expect(res.status).toBe(200)19 const body = (await res.json()) as any20 expect(body['posts']).not.toBeUndefined()21 expect(body['posts'].length).toBe(0)22 })2324 it('CRUD', async () => {25 let payload = JSON.stringify({ title: 'Morning', body: 'Good Morning' })26 let req = new Request('http://localhost/posts', {27 method: 'POST',28 body: payload,29 headers: { 'Content-Type': 'application/json' },30 })31 let res = await app.dispatch(req)32 expect(res.status).toBe(201)33 let body = (await res.json()) as any34 const newPost = body['post'] as Post35 expect(newPost.title).toBe('Morning')36 expect(newPost.body).toBe('Good Morning')3738 req = new Request('https://localhost/posts')39 res = await app.dispatch(req)40 expect(res.status).toBe(200)41 body = (await res.json()) as any42 expect(body['posts']).not.toBeUndefined()43 expect(body['posts'].length).toBe(1)4445 req = new Request(`https://localhost/posts/${newPost.id}`)46 res = await app.dispatch(req)47 expect(res.status).toBe(200)48 body = (await res.json()) as any49 let post = body['post'] as Post50 expect(post.id).toBe(newPost.id)51 expect(post.title).toBe('Morning')5253 payload = JSON.stringify({ title: 'Night', body: 'Good Night' })54 req = new Request(`https://localhost/posts/${post.id}`, {55 method: 'PUT',56 body: payload,57 headers: { 'Content-Type': 'application/json' },58 })59 res = await app.dispatch(req)60 expect(res.status).toBe(200)61 body = (await res.json()) as any62 expect(body['ok']).toBeTruthy()6364 req = new Request(`https://localhost/posts/${post.id}`)65 res = await app.dispatch(req)66 expect(res.status).toBe(200)67 body = (await res.json()) as any68 post = body['post'] as Post69 expect(post.title).toBe('Night')70 expect(post.body).toBe('Good Night')7172 req = new Request(`https://localhost/posts/${post.id}`, {73 method: 'DELETE',74 })75 res = await app.dispatch(req)76 expect(res.status).toBe(200)77 body = (await res.json()) as any78 expect(body['ok']).toBeTruthy()7980 req = new Request(`https://localhost/posts/${post.id}`)81 res = await app.dispatch(req)82 expect(res.status).toBe(404)83 })84})
added:examples/blog/src/index.test.ts+79 added
modified:examples/blog/package.json+2 added-2 removed
modified:examples/blog/README.md+2 added-2 removed
modified:examples/durable-objects/package.json+2 added-2 removed
modified:examples/jsx-ssr/package.json+2 added-2 removed
4 unmodified lines
5 "main": "dist/index.js",6 "scripts": {7 "build": "esbuild --bundle --sourcemap --outdir=dist ./src/index.tsx",8 "dev": "miniflare --live-reload --debug",9 "publish": "wrangler publish dist/index.js"9 "deploy": "wrangler publish dist/index.js"10 },11 "license": "MIT",12 "dependencies": {13 "hono": "^0.5.1",
3 unmodified lines
17 "esbuild": "^0.14.25",18 "miniflare": "2.2.0",19 "wrangler": "^0.0.16"20 }21}21}
modified:examples/mustache/package.json+2 added-2 removed
3 unmodified lines
4 "main": "src/index.js",5 "scripts": {6 "test": "echo \"Error: no test specified\" && exit 1",7 "dev": "wrangler dev src/index.js",8 "publish": "wrangler publish src/index.js"8 "deploy": "wrangler publish src/index.js"9 },10 "license": "MIT",11 "dependencies": {12 "hono": "^0.5.1",
1 unmodified line
14 },15 "devDependencies": {16 "wrangler": "^0.0.16"17 }18}18}
modified:examples/serve-static/package.json+2 added-2 removed
4 unmodified lines
5 "main": "src/index.js",6 "scripts": {7 "test": "echo \"Error: no test specified\" && exit 1",8 "dev": "wrangler dev src/index.js",9 "publish": "wrangler publish src/index.js"9 "deploy": "wrangler publish src/index.js"10 },11 "license": "MIT",12 "dependencies": {13 "hono": "^0.5.1"14 },15 "devDependencies": {16 "wrangler": "^0.0.16"17 }18}18}