├── .gitignore ├── .github ├── FUNDING.yml └── workflows │ └── main.yml ├── LICENSE ├── mod_test.ts ├── README.md └── mod.ts /.gitignore: -------------------------------------------------------------------------------- 1 | coverage 2 | coverage.* -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | ko_fi: v1rtl 4 | liberapay: v1rtl 5 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | # Controls when the action will run. Triggers the workflow on push or pull request 4 | # events but only for the master branch 5 | on: 6 | push: 7 | branches: [master] 8 | pull_request: 9 | branches: [master] 10 | 11 | jobs: 12 | test: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v2 16 | - uses: denoland/setup-deno@v1 17 | with: 18 | deno-version: v1.x 19 | - name: Run tests 20 | run: deno test -A --coverage=coverage 21 | - name: Create coverage report 22 | run: deno coverage ./coverage --lcov > coverage.lcov 23 | - name: Coveralls 24 | uses: coverallsapp/github-action@master 25 | with: 26 | github-token: ${{ secrets.GITHUB_TOKEN }} 27 | path-to-lcov: ./coverage.lcov 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Deno libraries 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /mod_test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it, run } from 'https://deno.land/x/tincan@0.2.1/mod.ts' 2 | import { createServer } from './mod.ts' 3 | import { makeFetch } from 'https://deno.land/x/superfetch@0.0.9/mod.ts' 4 | 5 | describe('node_http', () => { 6 | it('should start the server', async () => { 7 | const s = createServer((req) => req.respond({ body: 'Hello' })) 8 | 9 | const fetch = makeFetch(s.handler!) 10 | 11 | await fetch('/').expect('Hello') 12 | }) 13 | describe('events', () => { 14 | it('should trigger "listening" event', async () => { 15 | const s = createServer() 16 | 17 | s.on('listening', () => { 18 | expect(s.address()).toEqual({ family: 'IPv4', address: '0.0.0.0', port: 8080 }) 19 | s.close() 20 | }) 21 | 22 | await s.listen({ port: 8080 }) 23 | }) 24 | it('should trigger "request" event', async () => { 25 | const s = createServer() 26 | 27 | s.on('request', (req) => { 28 | expect(req.url).toBe('/') 29 | req.respond({ body: 'hello' }) 30 | }) 31 | 32 | const fetch = makeFetch(s) 33 | 34 | await fetch('/').expect('hello') 35 | }) 36 | }) 37 | }) 38 | 39 | run() 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |