Skip to content

Commit f8eea2c

Browse files
committed
chore: Deno tests cors & html
1 parent 11f6c66 commit f8eea2c

16 files changed

Lines changed: 105 additions & 57 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Collection of experimental [Elysia.js](https://elysiajs.com) polyfills:
55
| Package | [Node.js](https://nodejs.org) (v18.16.0) | [Deno](https://deno.land) (1.32.5) |
66
| -------------------------------------------------- | ---------------------------------------- | ---------------------------------- |
77
| [elysia](https://npmjs.com/package/elysia) (0.4.9) | 🔬 | 🔬 |
8-
| [@elysiajs/cors](https://www.npmjs.com/package/@elysiajs/cors) (0.3.0) || 🔬 |
9-
| [@elysiajs/html](https://www.npmjs.com/package/@elysiajs/html) (0.1.0) || 🔬 |
8+
| [@elysiajs/cors](https://www.npmjs.com/package/@elysiajs/cors) (0.3.0) || |
9+
| [@elysiajs/html](https://www.npmjs.com/package/@elysiajs/html) (0.1.0) || |
1010
| ... | ... | ... |
1111

1212
**_Legend_**

examples/deno/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.env
33
deno.lock
44

5+
tests/
56
node_modules/

examples/deno/deno.jsonc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"tasks": {
33
"dev": "deno run --import-map=import_map.json --node-modules-dir --allow-net --allow-env --watch main.ts",
44
"start": "deno run --import-map=import_map.json --node-modules-dir --allow-net --allow-env main.ts",
5-
"transpile": "npm run elysia-polyfills"
5+
"transpile": "npm run elysia-polyfills",
6+
"test": "rm -fr ./tests && cp -r ../../tests ./tests && deno run --import-map=import_map.json --node-modules-dir ./test.ts"
67
}
78
}

examples/deno/import_map.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"imports": {
33
"@bogeychan/elysia-polyfills/deno/index.js": "../../dist/env/deno/index.js",
44
"elysia": "npm:[email protected]",
5-
"@sinclair/typebox": "npm:@sinclair/[email protected]"
5+
"@sinclair/typebox": "npm:@sinclair/[email protected]",
6+
"@elysiajs/cors": "npm:@elysiajs/[email protected]",
7+
"@elysiajs/html": "npm:@elysiajs/[email protected]",
8+
"chai": "npm:chai"
69
}
710
}

examples/deno/main.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,32 @@ import '@bogeychan/elysia-polyfills/deno/index.js';
22
import '@sinclair/typebox'; // deno doesn't download peerDependencies. this one is required
33
import { Elysia } from 'elysia';
44

5+
import 'chai'; // test dependency
6+
import '@elysiajs/cors';
7+
import { html } from '@elysiajs/html';
8+
59
// import 'npm:@bogeychan/elysia-polyfills/deno/index.js';
610
// import 'npm:@sinclair/[email protected]';
711
// import { Elysia } from 'npm:[email protected]';
812

913
const app = new Elysia()
14+
.use(html())
1015
.get('/', () => ({ hello: 'Deno👋' }))
1116
.post('/:world', (ctx) => `Hello ${ctx.params.world}`)
17+
.get(
18+
'/html',
19+
() => `<!DOCTYPE html>
20+
<html lang="en">
21+
<head>
22+
<meta charset="UTF-8" />
23+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
24+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
25+
<title>Document</title>
26+
</head>
27+
<body>HTML</body>
28+
</html>
29+
`
30+
)
1231
.listen(8080);
1332

1433
console.log(`Listening on http://localhost:${app.server!.port}`);

examples/deno/prepare.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
# Cleanup
44
rm -fr node_modules deno.lock
55

6+
echo "Downloading..."
7+
68
# Try to run (this shall fail & create a `node_modules` folder)
79
deno task start &> /dev/null
810

911
# Transpile a few `node_modules` packages to conform ESM
10-
../../bin/cli.js
11-
# ./node_modules/@bogeychan/elysia-polyfills/bin/cli.js
12+
../../bin/cli.js "@elysiajs/cors" "@elysiajs/html"
13+
# ./node_modules/@bogeychan/elysia-polyfills/bin/cli.js "@elysiajs/cors" "@elysiajs/html"

examples/deno/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import '@bogeychan/elysia-polyfills/deno/index.js';
2+
3+
import './tests/index.ts';

examples/node/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.env
33
package-lock.json
44

5+
tests/
56
node_modules/

examples/node/main.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import '@bogeychan/elysia-polyfills/node/index.js';
22

33
import { Elysia } from 'elysia';
4-
import { cors } from '@elysiajs/cors';
4+
import { html } from '@elysiajs/html';
55

66
const app = new Elysia()
7+
.use(html())
78
.get('/', () => ({ hello: 'Node.js👋' }))
89
.post('/:world', (ctx) => `Hello ${ctx.params.world}`)
9-
.use(cors())
1010
.get(
1111
'/html',
1212
() => `<!DOCTYPE html>
13-
<html lang="en">
14-
<head>
15-
<meta charset="UTF-8" />
16-
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
17-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
18-
<title>Document</title>
19-
</head>
20-
<body></body>
21-
</html>
22-
`
13+
<html lang="en">
14+
<head>
15+
<meta charset="UTF-8" />
16+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
17+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
18+
<title>Document</title>
19+
</head>
20+
<body>HTML</body>
21+
</html>
22+
`
2323
)
2424
.listen(8080);
2525

examples/node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"scripts": {
55
"start": "ts-node --esm ./main.ts",
66
"transpile": "elysia-polyfills @elysiajs/cors @elysiajs/html",
7-
"test": "ts-node --esm ./test.ts"
7+
"test": "rm -fr ./tests && cp -r ../../tests ./tests && ts-node --esm ./test.ts"
88
},
99
"devDependencies": {
1010
"@elysiajs/cors": "^0.3.0",

0 commit comments

Comments
 (0)