Skip to content

Commit 39f955f

Browse files
authored
fix: bff Integration test (#6733)
1 parent f5af01d commit 39f955f

File tree

49 files changed

+384
-455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+384
-455
lines changed

.changeset/gorgeous-news-change.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@modern-js/bff-core': patch
3+
---
4+
5+
fix(bff): client bundle supplement env variables & fix bff test
6+
fix(bff): client 产物补充环境变量 & 集成测试问题修复

packages/cli/plugin-bff/src/cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ export const bffPlugin = (): CliPlugin<AppTools> => ({
8484
const lambdaDir = apiRouter.getLambdaDir();
8585
const existLambda = apiRouter.isExistLambda();
8686

87-
const runtime = (bff as any)?.runtime || RUNTIME_CREATE_REQUEST;
87+
const runtime =
88+
(bff as any)?.runtimeCreateRequest || RUNTIME_CREATE_REQUEST;
8889
const relativeApiPath = path.relative(appDirectory, apiDirectory);
8990
const relativeLambdaPath = path.relative(appDirectory, lambdaDir);
9091

packages/cli/plugin-bff/tests/__snapshots__/loader.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
exports[`bff loader should works well 1`] = `
44
"import { createRequest } from '/packages/cli/plugin-bff/tests/fixtures/requestCreator/client.ts';
55
6-
export var get = createRequest({"path":"/api/hello","method":"GET","port":80,"httpMethodDecider":"functionName"});
6+
export var get = createRequest({path: '/api/hello',method: 'GET',port: 80,httpMethodDecider: 'functionName'});
77
"
88
`;

packages/server/bff-core/src/client/generateClient.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,22 @@ export const generateClient = async ({
7676
};
7777
handlersCode += `export ${exportStatement} createUploader(${JSON.stringify(requestOptions)});`;
7878
} else {
79-
const requestOptions = {
80-
path: routeName,
81-
method: upperHttpMethod,
82-
port: process.env.PORT || port,
83-
httpMethodDecider: httpMethodDecider || 'functionName',
84-
domain,
85-
...(fetcher ? { fetch: 'fetch' } : {}),
86-
requestId,
87-
};
79+
const portValue =
80+
target === 'server'
81+
? `process.env.PORT || ${String(port)}`
82+
: String(port);
83+
84+
const optionsStr = `{
85+
path: '${routeName}',
86+
method: '${upperHttpMethod}',
87+
port: ${portValue},
88+
httpMethodDecider: '${httpMethodDecider || 'functionName'}'
89+
${domain ? `, domain: '${domain}'` : ''}
90+
${fetcher ? ", fetch: 'fetch'" : ''}
91+
${requestId ? `, requestId: '${requestId}'` : ''}
92+
}`.replace(/\n\s*/g, '');
8893

89-
handlersCode += `export ${exportStatement} createRequest(${JSON.stringify(requestOptions)});
94+
handlersCode += `export ${exportStatement} createRequest(${optionsStr});
9095
`;
9196
}
9297
}

packages/server/bff-core/tests/client/__snapshots__/generateClient.test.ts.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
exports[`client generateClient should support cross croject invocation 1`] = `
44
"import { createRequest } from '@modern-js/plugin-bff/runtime/create-request';
55
6-
export var DELETE = createRequest({"path":"/normal/origin","method":"DELETE","port":3000,"httpMethodDecider":"functionName","requestId":"tests"});
7-
export default createRequest({"path":"/normal/origin","method":"GET","port":3000,"httpMethodDecider":"functionName","requestId":"tests"});
8-
export var putRepo = createRequest({"path":"/put-repo","method":"PUT","port":3000,"httpMethodDecider":"functionName","requestId":"tests"});
6+
export var DELETE = createRequest({path: '/normal/origin',method: 'DELETE',port: 3000,httpMethodDecider: 'functionName', requestId: 'tests'});
7+
export default createRequest({path: '/normal/origin',method: 'GET',port: 3000,httpMethodDecider: 'functionName', requestId: 'tests'});
8+
export var putRepo = createRequest({path: '/put-repo',method: 'PUT',port: 3000,httpMethodDecider: 'functionName', requestId: 'tests'});
99
"
1010
`;
1111

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

2121
exports[`client generateClient should works correctly 1`] = `
2222
"import { createRequest } from '@modern-js/plugin-bff/runtime/create-request';
2323
24-
export var get = createRequest({"path":"/api/:id/origin/foo","method":"GET","port":3000,"httpMethodDecider":"functionName"});
25-
export var post = createRequest({"path":"/api/:id/origin/foo","method":"POST","port":3000,"httpMethodDecider":"functionName"});
24+
export var get = createRequest({path: '/api/:id/origin/foo',method: 'GET',port: 3000,httpMethodDecider: 'functionName'});
25+
export var post = createRequest({path: '/api/:id/origin/foo',method: 'POST',port: 3000,httpMethodDecider: 'functionName'});
2626
"
2727
`;

pnpm-lock.yaml

Lines changed: 33 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/bff-api-app/tests/index.test.ts

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)