-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge external-package-resolution and internal-module-resolution exam…
…ple with guidelines on readme
- Loading branch information
1 parent
dc74937
commit b73d6cf
Showing
21 changed files
with
63 additions
and
52 deletions.
There are no files selected for viewing
9 changes: 0 additions & 9 deletions
9
fixtures/vitest-pool-workers-examples/external-package-resolution/test/index.spec.ts
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
fixtures/vitest-pool-workers-examples/external-package-resolution/test/tsconfig.json
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
fixtures/vitest-pool-workers-examples/internal-module-resolution/README.md
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
fixtures/vitest-pool-workers-examples/internal-module-resolution/test/index.spec.ts
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
fixtures/vitest-pool-workers-examples/internal-module-resolution/tsconfig.json
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
fixtures/vitest-pool-workers-examples/internal-module-resolution/vitest.config.ts
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
fixtures/vitest-pool-workers-examples/internal-module-resolution/wrangler.toml
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
fixtures/vitest-pool-workers-examples/module-resolution/README.md
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,34 @@ | ||
# ⚡ module-resolution | ||
|
||
This fixture demonstrates that the Vitest integration correctly resolves modules, including: | ||
|
||
- A CommonJS package that requires a directory rather than a specific file. | ||
- A package without a main entrypoint or with browser field mapping, handled via [Dependency Pre-Bundling](#dependency-pre-bundling). | ||
|
||
## Dependency Pre-Bundling | ||
|
||
[Dependency Pre-Bundling](https://vite.dev/guide/dep-pre-bundling) is a Vite feature that converts dependencies shipped as CommonJS or UMD into ESM. If you encounter module resolution issues—such as: `Error: Cannot use require() to import an ES Module` or `Error: No such module`—you can pre-bundle these dependencies using the [deps.optimizer](https://vitest.dev/config/#deps-optimizer) option: | ||
|
||
```ts | ||
import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config"; | ||
|
||
export default defineWorkersConfig({ | ||
test: { | ||
deps: { | ||
optimizer: { | ||
ssr: { | ||
enabled: true, | ||
include: ["your-package-name"], | ||
}, | ||
}, | ||
}, | ||
poolOptions: { | ||
workers: { | ||
// ... | ||
}, | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
See our [vitest config](./vitest.config.ts) for an example of how we pre-bundled `discord-api-types/v10` and `@microlabs/otel-cf-workers`. |
4 changes: 2 additions & 2 deletions
4
.../external-package-resolution/src/index.ts → ...s-examples/module-resolution/src/index.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
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
fixtures/vitest-pool-workers-examples/module-resolution/test/index.spec.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,20 @@ | ||
import { instrument } from "@microlabs/otel-cf-workers"; | ||
import { Utils } from "discord-api-types/v10"; | ||
import dep from "ext-dep"; | ||
import { assert, describe, test } from "vitest"; | ||
|
||
describe("test", () => { | ||
test("resolves commonjs directory dependencies correctly", async () => { | ||
assert.equal(dep, 123); | ||
}); | ||
|
||
// This requires the `deps.optimizer` option to be set in the vitest config | ||
test("resolves dependency without a default entrypoint", async () => { | ||
assert.isFunction(Utils.isDMInteraction); | ||
}); | ||
|
||
// This requires the `deps.optimizer` option to be set in the vitest config | ||
test("resolves dependency with mapping on the browser field", async () => { | ||
assert.isFunction(instrument); | ||
}); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...external-package-resolution/wrangler.toml → ...-examples/module-resolution/wrangler.toml
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
name = "external-package-resolution" | ||
name = "module-resolution" | ||
main = "src/index.ts" | ||
compatibility_date = "2024-04-05" |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.