Skip to content

Commit

Permalink
chore: added test projects.
Browse files Browse the repository at this point in the history
  • Loading branch information
eser committed Jul 16, 2024
1 parent b50f331 commit d2740e6
Show file tree
Hide file tree
Showing 38 changed files with 849 additions and 6 deletions.
13 changes: 11 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ repos:
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-json
exclude: |
(?x)^(
test/apps/vite-app/tsconfig.app.json|
test/apps/cf-workers-app/tsconfig.json
)$
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
- id: check-symlinks
Expand All @@ -27,6 +32,11 @@ repos:
args: ["--fix=lf"]
- id: pretty-format-json
args: ["--autofix", "--no-ensure-ascii", "--no-sort-keys"]
exclude: |
(?x)^(
test/apps/vite-app/tsconfig.app.json|
test/apps/cf-workers-app/tsconfig.json
)$
- id: trailing-whitespace
- repo: https://github.com/crate-ci/typos
rev: v1.23.2
Expand Down Expand Up @@ -78,13 +88,12 @@ repos:
pkg/@eser/fp/README.md|
pkg/@eser/functions/README.md|
pkg/@eser/jsx-runtime/README.md|
pkg/@eser/jsx-runtime.test/README.md|
pkg/@eser/logging/README.md|
pkg/@eser/parsing/README.md|
pkg/@eser/standards/README.md|
pkg/@cool/cli/README.md|
pkg/@cool/lime/README.md|
pkg/@cool/lime.test/README.md|
test/apps/vite-app/README.md|
Dockerfile|
LICENSE|
README.md
Expand Down
4 changes: 2 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@
"./pkg/@eser/fp",
"./pkg/@eser/functions",
"./pkg/@eser/jsx-runtime",
"./pkg/@eser/jsx-runtime.test",
"./pkg/@eser/logging",
"./pkg/@eser/parsing",
"./pkg/@eser/standards",
"./pkg/@cool/lime"
"./pkg/@cool/lime",
"./test/apps/jsx-runtime-app"
]
}
2 changes: 1 addition & 1 deletion pkg/@eser/parsing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ used extensively in compilers and source code analysis tools.

## 🛠 Usage

Here you'll find a list of features provided by `eser/parsing` along with brief
Here you'll find a list of features provided by `@eser/parsing` along with brief
descriptions and usage examples.

### Tokenizing from source
Expand Down
2 changes: 2 additions & 0 deletions scripts/validate-licenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const main = async () => {
/_etc\/coverage\/*$/,
/_etc\/temp\/*$/,
/_etc\/templates\/*$/,
/test\/apps\/cf-workers-app\/node_modules\/*$/,
/test\/apps\/cf-workers-app\/worker-configuration\.d\.ts$/,
/manifest\.gen\.ts$/,
];

Expand Down
172 changes: 172 additions & 0 deletions test/apps/cf-workers-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
\*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
\*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

\*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

\*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.cache
.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

.cache/

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp
.cache

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.\*

# wrangler project

.dev.vars
.wrangler/
6 changes: 6 additions & 0 deletions test/apps/cf-workers-app/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 140,
"singleQuote": true,
"semi": true,
"useTabs": true
}
19 changes: 19 additions & 0 deletions test/apps/cf-workers-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "cf-workers-app",
"version": "0.0.0",
"private": true,
"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"start": "wrangler dev",
"test": "vitest",
"cf-typegen": "wrangler types"
},
"devDependencies": {
"@cloudflare/vitest-pool-workers": "^0.4.5",
"@cloudflare/workers-types": "^4.20240712.0",
"typescript": "^5.5.2",
"vitest": "1.5.0",
"wrangler": "^3.60.3"
}
}
19 changes: 19 additions & 0 deletions test/apps/cf-workers-app/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
/**
* Welcome to Cloudflare Workers! This is your first worker.
*
* - Run `npm run dev` in your terminal to start a development server
* - Open a browser tab at http://localhost:8787/ to see your worker in action
* - Run `npm run deploy` to publish your worker
*
* Bind resources to your worker in `wrangler.toml`. After adding bindings, a type definition for the
* `Env` object can be regenerated with `npm run cf-typegen`.
*
* Learn more at https://developers.cloudflare.com/workers/
*/

export default {
async fetch(request, env, ctx): Promise<Response> {
return new Response("Hello World!");
},
} satisfies ExportedHandler<Env>;
30 changes: 30 additions & 0 deletions test/apps/cf-workers-app/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
import {
createExecutionContext,
env,
SELF,
waitOnExecutionContext,
} from "cloudflare:test";
import { describe, expect, it } from "vitest";
import worker from "../src/index";

// For now, you'll need to do something like this to get a correctly-typed
// `Request` to pass to `worker.fetch()`.
const IncomingRequest = Request<unknown, IncomingRequestCfProperties>;

describe("Hello World worker", () => {
it("responds with Hello World! (unit style)", async () => {
const request = new IncomingRequest("http://example.com");
// Create an empty context to pass to `worker.fetch()`.
const ctx = createExecutionContext();
const response = await worker.fetch(request, env, ctx);
// Wait for all `Promise`s passed to `ctx.waitUntil()` to settle before running test assertions
await waitOnExecutionContext(ctx);
expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
});

it("responds with Hello World! (integration style)", async () => {
const response = await SELF.fetch("https://example.com");
expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
});
});
14 changes: 14 additions & 0 deletions test/apps/cf-workers-app/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": [
"@cloudflare/workers-types/experimental",
"@cloudflare/vitest-pool-workers"
]
},
"include": [
"./**/*.ts",
"../src/env.d.ts"
],
"exclude": []
}
Loading

0 comments on commit d2740e6

Please sign in to comment.