Skip to content

Commit 9857fbf

Browse files
feat: jest-environment-wrangler (#715)
A starting point for a jest environment powered by wrangler. This is just a proxy for `jest-environment-miniflare` right now, but we'll add features as we go along.
1 parent 754f6c6 commit 9857fbf

File tree

13 files changed

+360
-8
lines changed

13 files changed

+360
-8
lines changed

Diff for: .changeset/config.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"access": "public",
1010
"baseBranch": "main",
1111
"updateInternalDependencies": "patch",
12-
"ignore": []
12+
"ignore": [],
13+
"fixed": [["wrangler", "jest-environment-wrangler"]]
1314
}

Diff for: .changeset/poor-hotels-drum.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"jest-environment-wrangler": patch
3+
---
4+
5+
feat: `jest-environment-wrangler`
6+
7+
A starting point for a jest environment powered by wrangler. This is just a proxy for `jest-environment-miniflare` right now, but we'll add features as we go along.

Diff for: .prettierignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
packages/wrangler/vendor/
22
packages/wrangler/wrangler-dist/
33
packages/wrangler/miniflare-dist/
4+
packages/wrangler/CHANGELOG.md
45
packages/example-worker-app/dist/
56
packages/example-remix-pages-app/build
67
packages/example-remix-pages-app/public/
78
packages/prerelease-registry/_worker.js
8-
packages/wrangler/CHANGELOG.md
9+
packages/jest-environment-wrangler/dist/
10+

Diff for: package-lock.json

+61
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"check:type": "npm run check:type --workspaces --if-present",
3737
"check:lint": "eslint \"packages/**/*.[tj]s?(x)\" --cache --cache-strategy content --max-warnings=0",
3838
"check:format": "prettier packages/** .changeset docs --check --ignore-unknown",
39-
"build": "npm run build --workspace=wrangler",
39+
"build": "npm run build --workspace=wrangler --workspace=jest-environment-wrangler",
4040
"test": "npm run test --workspaces --if-present",
4141
"prettify": "prettier packages/** --write --ignore-unknown"
4242
},
@@ -50,7 +50,8 @@
5050
"packages/wrangler/*-dist",
5151
"packages/wrangler/pages/functions/template-worker.ts",
5252
"packages/wrangler/templates",
53-
"example-remix-pages-app/public"
53+
"example-remix-pages-app/public",
54+
"packages/jest-environment-wrangler/dist"
5455
],
5556
"parser": "@typescript-eslint/parser",
5657
"parserOptions": {

Diff for: packages/example-worker-app/package.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
"name": "example-worker-app",
33
"version": "1.0.0",
44
"description": "",
5-
"main": "index.js",
6-
"scripts": {},
5+
"main": "src/index.js",
6+
"scripts": {
7+
"test": "npx jest"
8+
},
79
"author": "",
810
"license": "ISC",
9-
"private": true
11+
"private": true,
12+
"jest": {
13+
"testRegex": ".*.test\\.[jt]sx?$",
14+
"testEnvironment": "wrangler"
15+
}
1016
}

Diff for: packages/example-worker-app/tests/index.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
it("should run", () => {
2+
console.log(Request);
3+
});

Diff for: packages/jest-environment-wrangler/.gitignore

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional stylelint cache
58+
.stylelintcache
59+
60+
# Microbundle cache
61+
.rpt2_cache/
62+
.rts2_cache_cjs/
63+
.rts2_cache_es/
64+
.rts2_cache_umd/
65+
66+
# Optional REPL history
67+
.node_repl_history
68+
69+
# Output of 'npm pack'
70+
*.tgz
71+
72+
# Yarn Integrity file
73+
.yarn-integrity
74+
75+
# dotenv environment variable files
76+
.env
77+
.env.development.local
78+
.env.test.local
79+
.env.production.local
80+
.env.local
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# vuepress v2.x temp and cache directory
104+
.temp
105+
.cache
106+
107+
# Docusaurus cache and generated files
108+
.docusaurus
109+
110+
# Serverless directories
111+
.serverless/
112+
113+
# FuseBox cache
114+
.fusebox/
115+
116+
# DynamoDB Local files
117+
.dynamodb/
118+
119+
# TernJS port file
120+
.tern-port
121+
122+
# Stores VSCode versions used for testing VSCode extensions
123+
.vscode-test
124+
125+
# yarn v2
126+
.yarn/cache
127+
.yarn/unplugged
128+
.yarn/build-state.yml
129+
.yarn/install-state.gz
130+
.pnp.*
131+
132+
133+
dist

Diff for: packages/jest-environment-wrangler/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## EXPERIMENTAL jest-environment-wrangler
2+
3+
A jest environment for Cloudflare Workers, powered by wrangler.
4+
5+
```
6+
// jest.setup.js
7+
8+
export default {
9+
testEnvironment: "wrangler"
10+
}
11+
```

Diff for: packages/jest-environment-wrangler/package.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "jest-environment-wrangler",
3+
"version": "0.0.23",
4+
"description": "A jest environment for Cloudflare Workers, powered by wrangler.",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"build": "esbuild src/index.ts --outfile=dist/index.js --target=es2020 --sourcemap --platform=node --format=cjs",
8+
"check:type": "tsc"
9+
},
10+
"prepublishOnly": "npm run build",
11+
"keywords": [
12+
"jest",
13+
"wrangler",
14+
"cloudflare",
15+
"cloudflare-workers"
16+
],
17+
"author": "[email protected]",
18+
"license": "ISC",
19+
"dependencies": {
20+
"jest-environment-miniflare": "2.3.0",
21+
"wrangler": "0.0.23"
22+
}
23+
}

Diff for: packages/jest-environment-wrangler/src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import MiniflareEnvironment from "jest-environment-miniflare";
2+
3+
export default class WranglerEnvironment extends MiniflareEnvironment {}

0 commit comments

Comments
 (0)