Skip to content

Commit

Permalink
fix: bff Integration test (#6733)
Browse files Browse the repository at this point in the history
  • Loading branch information
keepview authored Jan 15, 2025
1 parent f5af01d commit 39f955f
Show file tree
Hide file tree
Showing 49 changed files with 384 additions and 455 deletions.
6 changes: 6 additions & 0 deletions .changeset/gorgeous-news-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/bff-core': patch
---

fix(bff): client bundle supplement env variables & fix bff test
fix(bff): client 产物补充环境变量 & 集成测试问题修复
3 changes: 2 additions & 1 deletion packages/cli/plugin-bff/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export const bffPlugin = (): CliPlugin<AppTools> => ({
const lambdaDir = apiRouter.getLambdaDir();
const existLambda = apiRouter.isExistLambda();

const runtime = (bff as any)?.runtime || RUNTIME_CREATE_REQUEST;
const runtime =
(bff as any)?.runtimeCreateRequest || RUNTIME_CREATE_REQUEST;
const relativeApiPath = path.relative(appDirectory, apiDirectory);
const relativeLambdaPath = path.relative(appDirectory, lambdaDir);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
exports[`bff loader should works well 1`] = `
"import { createRequest } from '/packages/cli/plugin-bff/tests/fixtures/requestCreator/client.ts';
export var get = createRequest({"path":"/api/hello","method":"GET","port":80,"httpMethodDecider":"functionName"});
export var get = createRequest({path: '/api/hello',method: 'GET',port: 80,httpMethodDecider: 'functionName'});
"
`;
25 changes: 15 additions & 10 deletions packages/server/bff-core/src/client/generateClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,22 @@ export const generateClient = async ({
};
handlersCode += `export ${exportStatement} createUploader(${JSON.stringify(requestOptions)});`;
} else {
const requestOptions = {
path: routeName,
method: upperHttpMethod,
port: process.env.PORT || port,
httpMethodDecider: httpMethodDecider || 'functionName',
domain,
...(fetcher ? { fetch: 'fetch' } : {}),
requestId,
};
const portValue =
target === 'server'
? `process.env.PORT || ${String(port)}`
: String(port);

const optionsStr = `{
path: '${routeName}',
method: '${upperHttpMethod}',
port: ${portValue},
httpMethodDecider: '${httpMethodDecider || 'functionName'}'
${domain ? `, domain: '${domain}'` : ''}
${fetcher ? ", fetch: 'fetch'" : ''}
${requestId ? `, requestId: '${requestId}'` : ''}
}`.replace(/\n\s*/g, '');

handlersCode += `export ${exportStatement} createRequest(${JSON.stringify(requestOptions)});
handlersCode += `export ${exportStatement} createRequest(${optionsStr});
`;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
exports[`client generateClient should support cross croject invocation 1`] = `
"import { createRequest } from '@modern-js/plugin-bff/runtime/create-request';
export var DELETE = createRequest({"path":"/normal/origin","method":"DELETE","port":3000,"httpMethodDecider":"functionName","requestId":"tests"});
export default createRequest({"path":"/normal/origin","method":"GET","port":3000,"httpMethodDecider":"functionName","requestId":"tests"});
export var putRepo = createRequest({"path":"/put-repo","method":"PUT","port":3000,"httpMethodDecider":"functionName","requestId":"tests"});
export var DELETE = createRequest({path: '/normal/origin',method: 'DELETE',port: 3000,httpMethodDecider: 'functionName', requestId: 'tests'});
export default createRequest({path: '/normal/origin',method: 'GET',port: 3000,httpMethodDecider: 'functionName', requestId: 'tests'});
export var putRepo = createRequest({path: '/put-repo',method: 'PUT',port: 3000,httpMethodDecider: 'functionName', requestId: 'tests'});
"
`;

exports[`client generateClient should support operator 1`] = `
"import { createRequest } from '@modern-js/plugin-bff/runtime/create-request';
export var DELETE = createRequest({"path":"/normal/origin","method":"DELETE","port":3000,"httpMethodDecider":"functionName"});
export default createRequest({"path":"/normal/origin","method":"GET","port":3000,"httpMethodDecider":"functionName"});
export var putRepo = createRequest({"path":"/put-repo","method":"PUT","port":3000,"httpMethodDecider":"functionName"});
export var DELETE = createRequest({path: '/normal/origin',method: 'DELETE',port: 3000,httpMethodDecider: 'functionName'});
export default createRequest({path: '/normal/origin',method: 'GET',port: 3000,httpMethodDecider: 'functionName'});
export var putRepo = createRequest({path: '/put-repo',method: 'PUT',port: 3000,httpMethodDecider: 'functionName'});
"
`;

exports[`client generateClient should works correctly 1`] = `
"import { createRequest } from '@modern-js/plugin-bff/runtime/create-request';
export var get = createRequest({"path":"/api/:id/origin/foo","method":"GET","port":3000,"httpMethodDecider":"functionName"});
export var post = createRequest({"path":"/api/:id/origin/foo","method":"POST","port":3000,"httpMethodDecider":"functionName"});
export var get = createRequest({path: '/api/:id/origin/foo',method: 'GET',port: 3000,httpMethodDecider: 'functionName'});
export var post = createRequest({path: '/api/:id/origin/foo',method: 'POST',port: 3000,httpMethodDecider: 'functionName'});
"
`;
60 changes: 33 additions & 27 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 0 additions & 82 deletions tests/integration/bff-api-app/tests/index.test.ts

This file was deleted.

Loading

0 comments on commit 39f955f

Please sign in to comment.