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
Provenance
- Commit
2b57064- Tree
221c63c- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
GitHub <noreply@github.com>- Parent
fb76c36
10 files changed+94 added−99 removed
modified:examples/basic/package.json+2 added-2 removed
4 unmodified lines56789910111213141516171819194 unmodified lines "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "dev": "wrangler dev index.js", "publish": "wrangler publish index.js" "deploy": "wrangler publish index.js" }, "author": "Yusuke Wada <yusuke@kamawada.com> (https://github.com/yusukebe)", "license": "MIT", "dependencies": { "hono": "*" }, "devDependencies": { "wrangler": "^0.0.17" }}}No newline at end of filemodified:examples/basic/README.md+1 added-1 removed
5 unmodified lines67891010115 unmodified lines
```sh$ npm install$ npm run dev # Start a local server for developing your worker$ npm run publish # Publish your worker to the orange cloud$ npm run deploy # Publish your worker to the orange cloud```deleted:examples/blog/src/controller.test.ts-84 removed
1-import { app } from './index'2-import type { Post } from './model'3-4-describe('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-})13-14-describe('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- })23-24- 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')37-38- 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)44-45- 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')52-53- 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()63-64- 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')71-72- 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()79-80- 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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879import { app } from './index'import type { Post } from './model'
describe('Root', () => { it('GET /', async () => { const res = await app.request('http://localhost/') expect(res.status).toBe(200) const body = await res.json() expect(body['message']).toBe('Hello') })})
describe('Blog API', () => { it('List', async () => { const res = await app.request('http://localhost/posts') expect(res.status).toBe(200) const body = await res.json() expect(body['posts']).not.toBeUndefined() expect(body['posts'].length).toBe(0) })
it('CRUD', async () => { let payload = JSON.stringify({ title: 'Morning', body: 'Good Morning' }) let req = new Request('http://localhost/posts', { method: 'POST', body: payload, headers: { 'Content-Type': 'application/json' }, }) let res = await app.request(req) expect(res.status).toBe(201) let body = await res.json() const newPost = body['post'] as Post expect(newPost.title).toBe('Morning') expect(newPost.body).toBe('Good Morning')
res = await app.request('https://localhost/posts') expect(res.status).toBe(200) body = await res.json() expect(body['posts']).not.toBeUndefined() expect(body['posts'].length).toBe(1)
res = await app.request(`https://localhost/posts/${newPost.id}`) expect(res.status).toBe(200) body = await res.json() let post = body['post'] as Post expect(post.id).toBe(newPost.id) expect(post.title).toBe('Morning') const postId = post.id
payload = JSON.stringify({ title: 'Night', body: 'Good Night' }) req = new Request(`https://localhost/posts/${postId}`, { method: 'PUT', body: payload, headers: { 'Content-Type': 'application/json' }, }) res = await app.request(req) expect(res.status).toBe(200) body = await res.json() expect(body['ok']).toBeTruthy()
res = await app.request(`https://localhost/posts/${postId}`) expect(res.status).toBe(200) body = await res.json() post = body['post'] as Post expect(post.title).toBe('Night') expect(post.body).toBe('Good Night')
req = new Request(`https://localhost/posts/${postId}`, { method: 'DELETE', }) res = await app.request(req) expect(res.status).toBe(200) body = await res.json() expect(body['ok']).toBeTruthy()
res = await app.request(`https://localhost/posts/${postId}`) expect(res.status).toBe(404) })})modified:examples/blog/package.json+2 added-2 removed
4 unmodified lines567899101112138 unmodified lines2223242526264 unmodified lines "main": "dist/index.js", "scripts": { "build": "esbuild --bundle --outdir=dist ./src/index.ts", "dev": "miniflare --live-reload --debug", "publish": "wrangler publish dist/index.js", "deploy": "wrangler publish dist/index.js", "test": "NODE_OPTIONS=--experimental-vm-modules jest --verbose" }, "author": "Yusuke Wada <yusuke@kamawada.com> (https://github.com/yusukebe)", "license": "MIT",8 unmodified lines "jest-environment-miniflare": "^2.2.0", "jest-node-exports-resolver": "^1.1.5", "miniflare": "^2.3.0" }}}No newline at end of filemodified:examples/blog/README.md+2 added-2 removed
63 unmodified lines646566676868697071727374747563 unmodified lines
Run a development server:
```sh$ yarn run dev$ yarn dev```
Publish:
```sh$ yarn run publih$ yarn deploy```modified:examples/durable-objects/package.json+2 added-2 removed
4 unmodified lines56789910111213141516171819194 unmodified lines "main": "dist/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "dev": "wrangler dev src/index.ts", "publish": "wrangler publish src/index.ts" "deploy": "wrangler publish src/index.ts" }, "license": "MIT", "devDependencies": { "@cloudflare/workers-types": "^3.0", "wrangler": "^0.0.17" }, "dependencies": { "hono": "^0.5.1" }}}No newline at end of filemodified:examples/jsx-ssr/package.json+2 added-2 removed
4 unmodified lines5 "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 lines17 "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 lines4 "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 line14 },15 "devDependencies": {16 "wrangler": "^0.0.16"17 }18-}18+}modified:examples/serve-static/package.json+2 added-2 removed
4 unmodified lines5 "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+}