@elizaos/test-utils 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +5 -0
- package/LICENSE +21 -0
- package/README.md +255 -0
- package/dist/index.d.ts +950 -0
- package/dist/index.js +3013 -0
- package/dist/index.js.map +1 -0
- package/package.json +75 -0
- package/tsup.config.ts +20 -0
package/.npmignore
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Shaw Walters and elizaOS Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# ElizaOS Plugin
|
|
2
|
+
|
|
3
|
+
This is an ElizaOS plugin built with the official plugin starter template.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Create a new plugin (automatically adds "plugin-" prefix)
|
|
9
|
+
elizaos create -t plugin solana
|
|
10
|
+
# This creates: plugin-solana
|
|
11
|
+
# Dependencies are automatically installed and built
|
|
12
|
+
|
|
13
|
+
# Navigate to the plugin directory
|
|
14
|
+
cd plugin-solana
|
|
15
|
+
|
|
16
|
+
# Start development immediately
|
|
17
|
+
elizaos dev
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Development
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# Start development with hot-reloading (recommended)
|
|
24
|
+
elizaos dev
|
|
25
|
+
|
|
26
|
+
# OR start without hot-reloading
|
|
27
|
+
elizaos start
|
|
28
|
+
# Note: When using 'start', you need to rebuild after changes:
|
|
29
|
+
# bun run build
|
|
30
|
+
|
|
31
|
+
# Test the plugin
|
|
32
|
+
elizaos test
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Testing
|
|
36
|
+
|
|
37
|
+
ElizaOS provides a comprehensive testing structure for plugins:
|
|
38
|
+
|
|
39
|
+
### Test Structure
|
|
40
|
+
|
|
41
|
+
- **Component Tests** (`__tests__/` directory):
|
|
42
|
+
|
|
43
|
+
- **Unit Tests**: Test individual functions/classes in isolation
|
|
44
|
+
- **Integration Tests**: Test how components work together
|
|
45
|
+
- Run with: `elizaos test component`
|
|
46
|
+
|
|
47
|
+
- **End-to-End Tests** (`__tests__/e2e/` directory):
|
|
48
|
+
|
|
49
|
+
- Test the plugin within a full ElizaOS runtime
|
|
50
|
+
- Validate complete user scenarios with a real agent
|
|
51
|
+
- Run with: `elizaos test e2e`
|
|
52
|
+
|
|
53
|
+
- **Running All Tests**:
|
|
54
|
+
- `elizaos test` runs both component and e2e tests
|
|
55
|
+
|
|
56
|
+
### Writing Tests
|
|
57
|
+
|
|
58
|
+
Component tests use Vitest:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
// Unit test example (__tests__/plugin.test.ts)
|
|
62
|
+
describe('Plugin Configuration', () => {
|
|
63
|
+
it('should have correct plugin metadata', () => {
|
|
64
|
+
expect(starterPlugin.name).toBe('plugin-starter');
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Integration test example (__tests__/integration.test.ts)
|
|
69
|
+
describe('Integration: HelloWorld Action with StarterService', () => {
|
|
70
|
+
it('should handle HelloWorld action with StarterService', async () => {
|
|
71
|
+
// Test interactions between components
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
E2E tests run in a real ElizaOS runtime:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
// E2E test example (__tests__/e2e/starter-plugin.ts)
|
|
80
|
+
export const StarterPluginTestSuite: TestSuite = {
|
|
81
|
+
name: 'plugin_starter_test_suite',
|
|
82
|
+
description: 'E2E tests for the starter plugin',
|
|
83
|
+
tests: [
|
|
84
|
+
{
|
|
85
|
+
name: 'hello_world_action_test',
|
|
86
|
+
fn: async (runtime) => {
|
|
87
|
+
// Simulate user asking agent to say hello
|
|
88
|
+
const testMessage = {
|
|
89
|
+
content: { text: 'Can you say hello?' }
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// Execute action and capture response
|
|
93
|
+
const response = await helloWorldAction.handler(runtime, testMessage, ...);
|
|
94
|
+
|
|
95
|
+
// Verify agent responds with "hello world"
|
|
96
|
+
if (!response.text.includes('hello world')) {
|
|
97
|
+
throw new Error('Expected "hello world" in response');
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### Key E2E Testing Features:
|
|
106
|
+
|
|
107
|
+
- **Real Runtime Environment**: Tests run with a fully initialized ElizaOS runtime
|
|
108
|
+
- **Plugin Interaction**: Test how your plugin behaves with the actual agent
|
|
109
|
+
- **Scenario Testing**: Validate complete user interactions, not just individual functions
|
|
110
|
+
- **No Mock Required**: Access real services, actions, and providers
|
|
111
|
+
|
|
112
|
+
#### Writing New E2E Tests:
|
|
113
|
+
|
|
114
|
+
1. Add a new test object to the `tests` array in your test suite
|
|
115
|
+
2. Each test receives the runtime instance as a parameter
|
|
116
|
+
3. Throw errors to indicate test failures (no assertion library needed)
|
|
117
|
+
4. See the comprehensive documentation in `__tests__/e2e/starter-plugin.ts` for detailed examples
|
|
118
|
+
|
|
119
|
+
The test utilities in `__tests__/test-utils.ts` provide mock objects and setup functions to simplify writing component tests.
|
|
120
|
+
|
|
121
|
+
## Publishing & Continuous Development
|
|
122
|
+
|
|
123
|
+
### Initial Setup
|
|
124
|
+
|
|
125
|
+
Before publishing your plugin, ensure you meet these requirements:
|
|
126
|
+
|
|
127
|
+
1. **npm Authentication**
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
npm login
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
2. **GitHub Repository**
|
|
134
|
+
|
|
135
|
+
- Create a public GitHub repository for this plugin
|
|
136
|
+
- Add the 'elizaos-plugins' topic to the repository
|
|
137
|
+
- Use 'main' as the default branch
|
|
138
|
+
|
|
139
|
+
3. **Required Assets**
|
|
140
|
+
- Add images to the `images/` directory:
|
|
141
|
+
- `logo.jpg` (400x400px square, <500KB)
|
|
142
|
+
- `banner.jpg` (1280x640px, <1MB)
|
|
143
|
+
|
|
144
|
+
### Initial Publishing
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
# Test your plugin meets all requirements
|
|
148
|
+
elizaos publish --test
|
|
149
|
+
|
|
150
|
+
# Publish to npm + GitHub + registry (recommended)
|
|
151
|
+
elizaos publish
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
This command will:
|
|
155
|
+
|
|
156
|
+
- Publish your plugin to npm for easy installation
|
|
157
|
+
- Create/update your GitHub repository
|
|
158
|
+
- Submit your plugin to the ElizaOS registry for discoverability
|
|
159
|
+
|
|
160
|
+
### Continuous Development & Updates
|
|
161
|
+
|
|
162
|
+
**Important**: After your initial publish with `elizaos publish`, all future updates should be done using standard npm and git workflows, not the ElizaOS CLI.
|
|
163
|
+
|
|
164
|
+
#### Standard Update Workflow
|
|
165
|
+
|
|
166
|
+
1. **Make Changes**
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
# Edit your plugin code
|
|
170
|
+
elizaos dev # Test locally with hot-reload
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
2. **Test Your Changes**
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
# Run all tests
|
|
177
|
+
elizaos test
|
|
178
|
+
|
|
179
|
+
# Run specific test types if needed
|
|
180
|
+
elizaos test component # Component tests only
|
|
181
|
+
elizaos test e2e # E2E tests only
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
3. **Update Version**
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
# Patch version (bug fixes): 1.0.0 → 1.0.1
|
|
188
|
+
npm version patch
|
|
189
|
+
|
|
190
|
+
# Minor version (new features): 1.0.1 → 1.1.0
|
|
191
|
+
npm version minor
|
|
192
|
+
|
|
193
|
+
# Major version (breaking changes): 1.1.0 → 2.0.0
|
|
194
|
+
npm version major
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
4. **Publish to npm**
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
npm publish
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
5. **Push to GitHub**
|
|
204
|
+
```bash
|
|
205
|
+
git push origin main
|
|
206
|
+
git push --tags # Push version tags
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
#### Why Use Standard Workflows?
|
|
210
|
+
|
|
211
|
+
- **npm publish**: Directly updates your package on npm registry
|
|
212
|
+
- **git push**: Updates your GitHub repository with latest code
|
|
213
|
+
- **Automatic registry updates**: The ElizaOS registry automatically syncs with npm, so no manual registry updates needed
|
|
214
|
+
- **Standard tooling**: Uses familiar npm/git commands that work with all development tools
|
|
215
|
+
|
|
216
|
+
### Alternative Publishing Options (Initial Only)
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
# Publish to npm only (skip GitHub and registry)
|
|
220
|
+
elizaos publish --npm
|
|
221
|
+
|
|
222
|
+
# Publish but skip registry submission
|
|
223
|
+
elizaos publish --skip-registry
|
|
224
|
+
|
|
225
|
+
# Generate registry files locally without publishing
|
|
226
|
+
elizaos publish --dry-run
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Configuration
|
|
230
|
+
|
|
231
|
+
The `agentConfig` section in `package.json` defines the parameters your plugin requires:
|
|
232
|
+
|
|
233
|
+
```json
|
|
234
|
+
"agentConfig": {
|
|
235
|
+
"pluginType": "elizaos:plugin:1.0.0",
|
|
236
|
+
"pluginParameters": {
|
|
237
|
+
"API_KEY": {
|
|
238
|
+
"type": "string",
|
|
239
|
+
"description": "API key for the service"
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Customize this section to match your plugin's requirements.
|
|
246
|
+
|
|
247
|
+
## Documentation
|
|
248
|
+
|
|
249
|
+
Provide clear documentation about:
|
|
250
|
+
|
|
251
|
+
- What your plugin does
|
|
252
|
+
- How to use it
|
|
253
|
+
- Required API keys or credentials
|
|
254
|
+
- Example usage
|
|
255
|
+
- Version history and changelog
|