-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4529d2
commit 0bf2da7
Showing
10 changed files
with
315 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# import-npm example | ||
|
||
This is an npm workspace within pnpm in order to test dependencies managed through npm can also be resolved by wrangler |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "import-npm", | ||
"private": true, | ||
"description": "", | ||
"author": "", | ||
"scripts": { | ||
"check:type": "npm run check:type --workspaces", | ||
"test:ci": "npm install && npm run test:ci --workspaces", | ||
"test:watch": "npm install && npm run test:watch --workspaces", | ||
"type:tests": "npm run type:tests --workspaces" | ||
}, | ||
"workspaces": [ | ||
"packages/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "import-example", | ||
"private": true, | ||
"description": "", | ||
"author": "", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"check:type": "tsc", | ||
"test:ci": "vitest run", | ||
"test:watch": "vitest", | ||
"type:tests": "tsc -p ./tests/tsconfig.json" | ||
}, | ||
"dependencies": { | ||
"import-wasm-static": "../../../../fixtures/import-wasm-static" | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/workers-tsconfig": "../../../../packages/workers-tsconfig", | ||
"undici": "^5.28.4", | ||
"wrangler": "../../../../packages/wrangler" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// this is from the `import-wasm-static` fixture defined above | ||
// and setup inside package.json to mimic an npm package | ||
import multiply from "import-wasm-static/multiply.wasm"; | ||
import otherMultiple from "import-wasm-static/wasm/not-exported.wasm"; | ||
|
||
export default { | ||
async fetch(request) { | ||
// just instantiate and return something | ||
// we're really just testing the imports at the top of this file | ||
const multiplyModule = await WebAssembly.instantiate(multiply); | ||
const otherModule = await WebAssembly.instantiate(otherMultiple); | ||
|
||
const results = [ | ||
multiplyModule.exports.multiply(7, 3), | ||
otherModule.exports.multiply(7, 3), | ||
]; | ||
return new Response(results.join(", ")); | ||
}, | ||
}; |
26 changes: 26 additions & 0 deletions
26
fixtures/import-npm/packages/import-example/tests/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { resolve } from "path"; | ||
import { fetch } from "undici"; | ||
import { afterAll, beforeAll, describe, it } from "vitest"; | ||
import { runWranglerDev } from "../../../../shared/src/run-wrangler-long-lived"; | ||
|
||
describe("wrangler correctly imports wasm files with npm resolution", () => { | ||
let ip: string, port: number, stop: (() => Promise<unknown>) | undefined; | ||
|
||
beforeAll(async () => { | ||
({ ip, port, stop } = await runWranglerDev(resolve(__dirname, ".."), [ | ||
"--port=0", | ||
"--inspector-port=0", | ||
])); | ||
}); | ||
|
||
afterAll(async () => { | ||
await stop?.(); | ||
}); | ||
|
||
// if the worker compiles, is running, and returns 21 (7 * 3) we can assume that the wasm module was imported correctly | ||
it("responds", async ({ expect }) => { | ||
const response = await fetch(`http://${ip}:${port}/`); | ||
const text = await response.text(); | ||
expect(text).toBe("21, 21"); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
fixtures/import-npm/packages/import-example/tests/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "@cloudflare/workers-tsconfig/tsconfig.json", | ||
"compilerOptions": { | ||
"types": ["node"] | ||
}, | ||
"include": ["**/*.ts", "../../../../../node-types.d.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"esModuleInterop": true, | ||
"module": "CommonJS", | ||
"lib": ["ES2020"], | ||
"types": ["node"], | ||
"moduleResolution": "node", | ||
"noEmit": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": ["tests", "../../../../node-types.d.ts"] | ||
} |
9 changes: 9 additions & 0 deletions
9
fixtures/import-npm/packages/import-example/vitest.config.mts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { defineProject, mergeConfig } from "vitest/config"; | ||
import configShared from "../../../../vitest.shared"; | ||
|
||
export default mergeConfig( | ||
configShared, | ||
defineProject({ | ||
test: {}, | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name = "import-example" | ||
compatibility_date = "2024-10-31" | ||
|
||
main = "src/index.js" |