55import { generateProxyModule } from '@dd/apps-plugin/vite/proxy-codegen' ;
66
77describe ( 'Proxy Codegen - generateProxyModule' , ( ) => {
8- test ( 'Should generate a proxy module with a pre-computed query name ' , ( ) => {
8+ test ( 'Should generate a proxy module that reads executeBackendFunction off the runtime global ' , ( ) => {
99 const result = generateProxyModule ( [ { exportName : 'add' , queryName : 'a1b2c3d4e5f6.add' } ] ) ;
1010
11+ expect ( result ) . toContain ( 'export async function add(...args)' ) ;
1112 expect ( result ) . toContain (
12- "import { executeBackendFunction } from '@datadog/apps-function-query'" ,
13+ 'globalThis.DD_APPS_RUNTIME.executeBackendFunction("a1b2c3d4e5f6.add", args)' ,
1314 ) ;
14- expect ( result ) . toContain ( 'export async function add(...args)' ) ;
15- expect ( result ) . toContain ( 'executeBackendFunction("a1b2c3d4e5f6.add", args)' ) ;
15+ expect ( result ) . not . toContain ( '@datadog/apps-function-query' ) ;
16+ expect ( result ) . not . toContain ( 'virtual:dd-apps-runtime' ) ;
17+ expect ( result ) . not . toMatch ( / ^ \s * i m p o r t \s / m) ;
1618 } ) ;
1719
1820 test ( 'Should generate a proxy module for multiple exports' , ( ) => {
@@ -38,15 +40,4 @@ describe('Proxy Codegen - generateProxyModule', () => {
3840 expect ( result ) . not . toContain ( '.backend' ) ;
3941 expect ( result ) . toContain ( '"deadbeef1234.login"' ) ;
4042 } ) ;
41-
42- test ( 'Should import executeBackendFunction exactly once' , ( ) => {
43- const result = generateProxyModule ( [
44- { exportName : 'a' , queryName : 'abc123.a' } ,
45- { exportName : 'b' , queryName : 'abc123.b' } ,
46- { exportName : 'c' , queryName : 'abc123.c' } ,
47- ] ) ;
48-
49- const importCount = ( result . match ( / i m p o r t .* e x e c u t e B a c k e n d F u n c t i o n / g) || [ ] ) . length ;
50- expect ( importCount ) . toBe ( 1 ) ;
51- } ) ;
5243} ) ;
0 commit comments