-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add import tests for @roo-code/types, fix the build #4060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+209
−7
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,64 @@ | ||
| // npx vitest run src/__tests__/cjs-import.test.ts | ||
|
|
||
| import { resolve } from "path" | ||
|
|
||
| describe("CommonJS Import Tests", () => { | ||
| const packageRoot = resolve(__dirname, "../..") | ||
| const cjsPath = resolve(packageRoot, "dist", "index.js") | ||
|
|
||
| it("should import types using require() syntax", () => { | ||
| // Clear require cache to ensure fresh import. | ||
| delete require.cache[cjsPath] | ||
|
|
||
| // Use require to test CJS functionality. | ||
| // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
| const module = require(cjsPath) | ||
|
|
||
| // Verify that key exports are available | ||
| expect(module.GLOBAL_STATE_KEYS).toBeDefined() | ||
| expect(Array.isArray(module.GLOBAL_STATE_KEYS)).toBe(true) | ||
| expect(module.GLOBAL_STATE_KEYS.length).toBeGreaterThan(0) | ||
| }) | ||
|
|
||
| it("should import specific exports using destructuring", () => { | ||
| // Clear require cache. | ||
| delete require.cache[cjsPath] | ||
|
|
||
| // Test destructured require. | ||
| // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
| const { GLOBAL_STATE_KEYS, SECRET_STATE_KEYS } = require(cjsPath) | ||
|
|
||
| expect(GLOBAL_STATE_KEYS).toBeDefined() | ||
| expect(SECRET_STATE_KEYS).toBeDefined() | ||
| expect(Array.isArray(GLOBAL_STATE_KEYS)).toBe(true) | ||
| expect(Array.isArray(SECRET_STATE_KEYS)).toBe(true) | ||
| }) | ||
|
|
||
| it("should have default export available", () => { | ||
| // Clear require cache | ||
| delete require.cache[cjsPath] | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
| const module = require(cjsPath) | ||
|
|
||
| // Check if module has expected structure | ||
| expect(typeof module).toBe("object") | ||
| expect(module).not.toBeNull() | ||
| }) | ||
|
|
||
| it("should maintain consistency between multiple require calls", () => { | ||
| // Clear require cache first. | ||
| delete require.cache[cjsPath] | ||
|
|
||
| // Multiple require calls should return the same cached module. | ||
| // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
| const firstRequire = require(cjsPath) | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
| const secondRequire = require(cjsPath) | ||
|
|
||
| // Should be the exact same object (cached). | ||
| expect(firstRequire).toBe(secondRequire) | ||
| expect(firstRequire.GLOBAL_STATE_KEYS).toBe(secondRequire.GLOBAL_STATE_KEYS) | ||
| }) | ||
| }) |
This file contains hidden or 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,35 @@ | ||
| // npx vitest run src/__tests__/esm-import.test.ts | ||
|
|
||
| describe("ESM Import Tests", () => { | ||
| it("should import types using ESM syntax", async () => { | ||
| // Dynamic import to test ESM functionality. | ||
| const module = await import("../index.js") | ||
|
|
||
| // Verify that key exports are available. | ||
| expect(module.GLOBAL_STATE_KEYS).toBeDefined() | ||
| expect(Array.isArray(module.GLOBAL_STATE_KEYS)).toBe(true) | ||
| expect(module.GLOBAL_STATE_KEYS.length).toBeGreaterThan(0) | ||
| }) | ||
|
|
||
| it("should import specific exports using ESM syntax", async () => { | ||
| // Test named imports. | ||
| const { GLOBAL_STATE_KEYS, SECRET_STATE_KEYS } = await import("../index.js") | ||
|
|
||
| expect(GLOBAL_STATE_KEYS).toBeDefined() | ||
| expect(SECRET_STATE_KEYS).toBeDefined() | ||
| expect(Array.isArray(GLOBAL_STATE_KEYS)).toBe(true) | ||
| expect(Array.isArray(SECRET_STATE_KEYS)).toBe(true) | ||
| }) | ||
|
|
||
| it("should have consistent exports between static and dynamic imports", async () => { | ||
| // Static import. | ||
| const staticImport = await import("../index.js") | ||
|
|
||
| // Dynamic import. | ||
| const dynamicImport = await import("../index.js") | ||
|
|
||
| // Both should have the same exports. | ||
| expect(Object.keys(staticImport)).toEqual(Object.keys(dynamicImport)) | ||
| expect(staticImport.GLOBAL_STATE_KEYS).toEqual(dynamicImport.GLOBAL_STATE_KEYS) | ||
| }) | ||
| }) |
This file contains hidden or 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,83 @@ | ||
| // npx vitest run src/__tests__/package-exports.test.ts | ||
|
|
||
| import { resolve } from "path" | ||
|
|
||
| describe("Package Exports Integration Tests", () => { | ||
| const packageRoot = resolve(__dirname, "../..") | ||
| const distPath = resolve(packageRoot, "dist") | ||
|
|
||
| it("should import from built ESM file", async () => { | ||
| const esmPath = resolve(distPath, "index.mjs") | ||
|
|
||
| // Dynamic import of the built ESM file | ||
| const module = await import(esmPath) | ||
|
|
||
| expect(module.GLOBAL_STATE_KEYS).toBeDefined() | ||
| expect(Array.isArray(module.GLOBAL_STATE_KEYS)).toBe(true) | ||
| expect(module.GLOBAL_STATE_KEYS.length).toBeGreaterThan(0) | ||
| }) | ||
|
|
||
| it("should import from built CJS file", () => { | ||
| const cjsPath = resolve(distPath, "index.js") | ||
|
|
||
| // Clear require cache to ensure fresh import | ||
| delete require.cache[cjsPath] | ||
|
|
||
| // Require the built CJS file | ||
| // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
| const module = require(cjsPath) | ||
|
|
||
| expect(module.GLOBAL_STATE_KEYS).toBeDefined() | ||
| expect(Array.isArray(module.GLOBAL_STATE_KEYS)).toBe(true) | ||
| expect(module.GLOBAL_STATE_KEYS.length).toBeGreaterThan(0) | ||
| }) | ||
|
|
||
| it("should have consistent exports between ESM and CJS builds", async () => { | ||
| const esmPath = resolve(distPath, "index.mjs") | ||
| const cjsPath = resolve(distPath, "index.js") | ||
|
|
||
| // Clear require cache. | ||
| delete require.cache[cjsPath] | ||
|
|
||
| // Import both versions. | ||
| const esmModule = await import(esmPath) | ||
| // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
| const cjsModule = require(cjsPath) | ||
|
|
||
| // Compare key exports. | ||
| expect(esmModule.GLOBAL_STATE_KEYS).toEqual(cjsModule.GLOBAL_STATE_KEYS) | ||
| expect(esmModule.SECRET_STATE_KEYS).toEqual(cjsModule.SECRET_STATE_KEYS) | ||
|
|
||
| // Ensure both have the same export keys. | ||
| const esmKeys = Object.keys(esmModule).sort() | ||
| const cjsKeys = Object.keys(cjsModule).sort() | ||
| expect(esmKeys).toEqual(cjsKeys) | ||
| }) | ||
|
|
||
| it("should import using package name resolution (simulated)", async () => { | ||
| // This simulates how the package would be imported by consumers. | ||
| // We test the source files since we can't easily test the published package. | ||
| const module = await import("../index.js") | ||
|
|
||
| // Verify the main exports that consumers would use. | ||
| expect(module.GLOBAL_STATE_KEYS).toBeDefined() | ||
| expect(module.SECRET_STATE_KEYS).toBeDefined() | ||
|
|
||
| // Test some common type exports exist. | ||
| expect(typeof module.GLOBAL_STATE_KEYS).toBe("object") | ||
| expect(typeof module.SECRET_STATE_KEYS).toBe("object") | ||
| }) | ||
|
|
||
| it("should have TypeScript definitions available", () => { | ||
| const dtsPath = resolve(distPath, "index.d.ts") | ||
| // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
| const fs = require("fs") | ||
|
|
||
| // Check that the .d.ts file exists and has content. | ||
| expect(fs.existsSync(dtsPath)).toBe(true) | ||
|
|
||
| const dtsContent = fs.readFileSync(dtsPath, "utf8") | ||
| expect(dtsContent.length).toBeGreaterThan(0) | ||
| expect(dtsContent).toContain("export") | ||
| }) | ||
| }) |
This file contains hidden or 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
This file contains hidden or 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 @@ | ||
| import { defineConfig } from "vitest/config" | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| globals: true, | ||
| }, | ||
| }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.