@objectstack/plugin-msw 0.8.2 → 0.9.0

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.
@@ -144,7 +144,7 @@ ObjectStackServer.logger = null;
144
144
  export class MSWPlugin {
145
145
  constructor(options = {}) {
146
146
  this.name = 'com.objectstack.plugin.msw';
147
- this.version = '1.0.0';
147
+ this.version = '0.9.0';
148
148
  this.handlers = [];
149
149
  this.options = {
150
150
  enableBrowser: true,
package/package.json CHANGED
@@ -1,24 +1,26 @@
1
1
  {
2
2
  "name": "@objectstack/plugin-msw",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "description": "MSW (Mock Service Worker) Plugin for ObjectStack Runtime",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "dependencies": {
8
8
  "msw": "^2.0.0",
9
- "@objectstack/spec": "0.8.2",
10
- "@objectstack/types": "0.8.2",
11
- "@objectstack/objectql": "0.8.2"
9
+ "@objectstack/spec": "0.9.0",
10
+ "@objectstack/types": "0.9.0",
11
+ "@objectstack/objectql": "0.9.0"
12
12
  },
13
13
  "devDependencies": {
14
14
  "@types/node": "^25.1.0",
15
15
  "typescript": "^5.0.0",
16
- "@objectstack/runtime": "0.8.2"
16
+ "vitest": "^4.0.18",
17
+ "@objectstack/runtime": "0.9.0"
17
18
  },
18
19
  "peerDependencies": {
19
- "@objectstack/runtime": "^0.8.2"
20
+ "@objectstack/runtime": "^0.9.0"
20
21
  },
21
22
  "scripts": {
22
- "build": "tsc"
23
+ "build": "tsc",
24
+ "test": "vitest run"
23
25
  }
24
26
  }
@@ -0,0 +1,41 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { MSWPlugin, ObjectStackServer } from './msw-plugin';
3
+
4
+ describe('MSWPlugin', () => {
5
+ it('should initialize correctly', () => {
6
+ const plugin = new MSWPlugin({ enableBrowser: false });
7
+ expect(plugin.name).toBe('com.objectstack.plugin.msw');
8
+ expect(plugin.version).toBe('0.9.0');
9
+ });
10
+
11
+ it('should handle protocol dynamic loading gracefully', async () => {
12
+ // Mock context
13
+ const context: any = {
14
+ logger: { info: vi.fn(), debug: vi.fn(), warn: vi.fn() },
15
+ getService: vi.fn().mockReturnValue(null), // No protocol service initially
16
+ registerService: vi.fn()
17
+ };
18
+
19
+ const plugin = new MSWPlugin();
20
+ await plugin.init(context);
21
+ // It should try to load ObjectStackProtocolImplementation dynamically
22
+ // Since we are in test environment, the dynamic import might fail or succeed depending on build
23
+ // But we expect it not to crash
24
+ });
25
+ });
26
+
27
+ describe('ObjectStackServer', () => {
28
+ it('should throw if used before init', async () => {
29
+ await expect(ObjectStackServer.findData('test')).rejects.toThrow('ObjectStackServer not initialized');
30
+ });
31
+
32
+ it('should delegate to protocol after init', async () => {
33
+ const protocolMock: any = {
34
+ findData: vi.fn().mockResolvedValue({ records: [] })
35
+ };
36
+ ObjectStackServer.init(protocolMock);
37
+
38
+ await ObjectStackServer.findData('test');
39
+ expect(protocolMock.findData).toHaveBeenCalled();
40
+ });
41
+ });
package/src/msw-plugin.ts CHANGED
@@ -185,7 +185,7 @@ export class ObjectStackServer {
185
185
  */
186
186
  export class MSWPlugin implements Plugin {
187
187
  name = 'com.objectstack.plugin.msw';
188
- version = '1.0.0';
188
+ version = '0.9.0';
189
189
 
190
190
  private options: MSWPluginOptions;
191
191
  private worker: any;
package/tsconfig.json CHANGED
@@ -10,5 +10,6 @@
10
10
  "skipLibCheck": true,
11
11
  "forceConsistentCasingInFileNames": true
12
12
  },
13
- "include": ["src/**/*"]
13
+ "include": ["src/**/*"],
14
+ "exclude": ["node_modules", "dist", "**/*.test.ts"]
14
15
  }