Skip to content

Instantly share code, notes, and snippets.

@junkor-1011
Last active May 13, 2023 15:46
Show Gist options
  • Save junkor-1011/96efc32a454e956d468ba5516e811ca9 to your computer and use it in GitHub Desktop.
Save junkor-1011/96efc32a454e956d468ba5516e811ca9 to your computer and use it in GitHub Desktop.
deno test

test

cli install

deno install \
  -n hoge \
  --import-map=https://gist.githubusercontent.com/junkor-1011/96efc32a454e956d468ba5516e811ca9/raw/ed87f6757b1524c02db5de2d00e513b6bef00d90/import_map.json \
  # --no-check \
  https://gist.githubusercontent.com/junkor-1011/96efc32a454e956d468ba5516e811ca9/raw/ed87f6757b1524c02db5de2d00e513b6bef00d90/cli.ts
import { messageSchema, type TMessageSchema } from './mod.ts';
Deno.addSignalListener('SIGINT', () => {
console.log('interrupted, I\'ll terminate.');
Deno.exit();
});
function main(): void {
setInterval(() => {
console.log('waiting...');
}, 2 * 1000);
setInterval(() => {
const dt = new Date();
const _payload = {
message: 'Hello, World!',
date: dt.toISOString(),
} as const satisfies TMessageSchema;
const payload = messageSchema.parse(_payload);
console.log(JSON.stringify(payload, null, 2));
}, 5 * 1000);
}
main();
{
"compilerOptions": {
"allowJs": false,
"jsx": "react",
"lib": ["deno.window"],
"strict": true
},
"lint": {
"files": {
"include": ["."],
"exclude": ["public"]
},
"rules": {
"tags": ["recommended"],
"exclude": []
}
},
"fmt": {
"include": ["./"],
"exclude": [".vscode", ".env"],
"useTabs": false,
"lineWidth": 80,
"indentWidth": 2,
"singleQuote": true,
"proseWrap": "preserve"
},
"importMap": "import_map.json",
"tasks": {
// "test": "deno test"
"start": "deno run cli.ts"
}
}
{
"version": "2",
"remote": {},
"npm": {
"specifiers": {
"zod@3.21.4": "zod@3.21.4"
},
"packages": {
"zod@3.21.4": {
"integrity": "sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==",
"dependencies": {}
}
}
}
}
{
"imports": {
"zod": "npm:zod@3.21.4"
}
}
import { z } from 'zod';
export const messageSchema = z.object({
message: z.string(),
date: z.string().datetime(),
});
export type TMessageSchema = z.infer<typeof messageSchema>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment