Răsfoiți Sursa

docs: Add docs on accessing services from e2e tests

Michael Bromley 2 ani în urmă
părinte
comite
4e7b1d7c1d
1 a modificat fișierele cu 35 adăugiri și 0 ștergeri
  1. 35 0
      docs/docs/guides/developer-guide/testing/index.md

+ 35 - 0
docs/docs/guides/developer-guide/testing/index.md

@@ -210,3 +210,38 @@ describe('my plugin', () => {
 });
 ```
 :::
+
+## Accessing internal services
+
+It is possible to access any internal service of the Vendure server via the `server.app` object, which is an instance of the NestJS `INestApplication`.
+
+For example, to access the `ProductService`:
+
+```ts title="src/plugins/my-plugin/e2e/my-plugin.e2e-spec.ts"
+import { createTestEnvironment, testConfig } from '@vendure/testing';
+import { describe, beforeAll } from 'vitest';
+import { MyPlugin } from '../my-plugin.ts';
+
+describe('my plugin', () => {
+    
+    const { server, adminClient, shopClient } = createTestEnvironment({
+        ...testConfig,
+        plugins: [MyPlugin],
+    });
+    
+    // highlight-next-line
+    let productService: ProductService;
+    
+    beforeAll(async () => {
+        await server.init({
+            productsCsvPath: path.join(__dirname, 'fixtures/e2e-products.csv'),
+            initialData: myInitialData,
+            customerCount: 2,
+        });
+        await adminClient.asSuperAdmin();
+        // highlight-next-line
+        productService = server.app.get(ProductService);
+    }, 60000);
+
+});
+```