Skip to content

Commit

Permalink
fix: load changes from workspace in Preview after deployment (#2650)
Browse files Browse the repository at this point in the history
* fix: load changes from workspace in preview

* chore: create changeset

* fix: build errors

* fix: unneeded comment change
  • Loading branch information
mmilko01 authored Dec 12, 2024
1 parent b761137 commit 77cf576
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-clocks-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sap-ux/preview-middleware": patch
---

Load changes from workspace in Preview after deployment
1 change: 1 addition & 0 deletions packages/preview-middleware/src/base/flp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export class FlpSandbox {

// add route for the sandbox html
this.router.get(this.config.path, (async (req: EnhancedRequest, res: Response, next: NextFunction) => {
await this.setApplicationDependencies();
// inform the user if a html file exists on the filesystem
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const file = await this.project.byPath(this.config.path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,136 @@ exports[`FlpSandbox router editor with config 1`] = `
exports[`FlpSandbox router rta 1`] = `"Found. Redirecting to /my/rta.html?sap-ui-xx-viewCache=false&fiori-tools-rta-mode=true&sap-ui-rta-skip-flex-validation=true&sap-ui-xx-condense-changes=true"`;
exports[`FlpSandbox router rta with adp instance - preview 1`] = `
Object {
"apps": Object {
"app-preview": Object {
"additionalInformation": "SAPUI5.Component=myComponent",
"applicationType": "URL",
"description": "",
"title": "my.id",
"url": "..",
},
"testfev2other-preview": Object {
"additionalInformation": "SAPUI5.Component=test.fe.v2.other",
"applicationType": "URL",
"description": "This is a very simple application.",
"title": "My Other App",
"url": "/yet/another/app",
},
},
"basePath": "..",
"init": undefined,
"locateReuseLibsScript": false,
"ui5": Object {
"bootstrapOptions": "",
"flex": Array [
Object {
"connector": "LrepConnector",
"layers": Array [],
"url": "/sap/bc/lrep",
},
Object {
"applyConnector": "custom.connectors.WorkspaceConnector",
"custom": true,
"writeConnector": "custom.connectors.WorkspaceConnector",
},
Object {
"connector": "LocalStorageConnector",
"layers": Array [
"CUSTOMER",
"USER",
],
},
],
"libs": "sap.m,sap.ui.core,sap.ushell",
"resources": Object {
"my.id": "..",
"myResources1": "myResourcesUrl1",
"myResources2": "myResourcesUrl2",
"open.ux.preview.client": "../preview/client",
"test.fe.v2.other": "/yet/another/app",
},
"theme": "sap_horizon",
},
}
`;
exports[`FlpSandbox router rta with adp instance - preview 2`] = `
"<!DOCTYPE HTML>
<html lang=\\"en\\">
<!-- Copyright (c) 2015 SAP AG, All Rights Reserved -->
<head>
<meta http-equiv=\\"X-UA-Compatible\\" content=\\"IE=edge\\">
<meta charset=\\"UTF-8\\">
<meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1.0\\">
<title>Local FLP Sandbox</title>
<!-- Bootstrap the unified shell in sandbox mode for standalone usage.
The renderer is specified in the global Unified Shell configuration object \\"sap-ushell-config\\".
The fiori2 renderer will render the shell header allowing, for instance,
testing of additional application setting buttons.
The navigation target resolution service is configured in a way that the empty URL hash is
resolved to our own application.
This example uses relative path references for the SAPUI5 resources and test-resources;
it might be necessary to adapt them depending on the target runtime platform.
The sandbox platform is restricted to development or demo use cases and must NOT be used
for productive scenarios.
-->
<script type=\\"text/javascript\\">
window[\\"sap-ushell-config\\"] = {
defaultRenderer: \\"fiori2\\",
renderers: {
fiori2: {
componentData: {
config: {
search: \\"hidden\\",
enableSearch: false
}
}
}
},
applications: {\\"app-preview\\":{\\"title\\":\\"my.id\\",\\"description\\":\\"\\",\\"additionalInformation\\":\\"SAPUI5.Component=myComponent\\",\\"applicationType\\":\\"URL\\",\\"url\\":\\"..\\",\\"applicationDependencies\\":{\\"manifest\\":{},\\"name\\":\\"descriptorName\\",\\"url\\":\\"http://sap.example\\",\\"asyncHints\\":{\\"requests\\":[]}}},\\"testfev2other-preview\\":{\\"title\\":\\"My Other App\\",\\"description\\":\\"This is a very simple application.\\",\\"additionalInformation\\":\\"SAPUI5.Component=test.fe.v2.other\\",\\"applicationType\\":\\"URL\\",\\"url\\":\\"/yet/another/app\\"}}
};
</script>
<script type=\\"text/javascript\\">
window[\\"data-open-ux-preview-basePath\\"] = \\"..\\";
</script>
<script src=\\"../test-resources/sap/ushell/bootstrap/sandbox.js\\" id=\\"sap-ushell-bootstrap\\"></script>
<!-- Bootstrap the UI5 core library. 'data-sap-ui-frameOptions=\\"allow\\"' is a NON-SECURE setting for test environments -->
<script id=\\"sap-ui-bootstrap\\"
src=\\"../resources/sap-ui-core.js\\"
data-sap-ui-libs=\\"sap.m,sap.ui.core,sap.ushell\\"
data-sap-ui-async=\\"true\\"
data-sap-ui-preload=\\"async\\"
data-sap-ui-theme=\\"sap_horizon\\"
data-sap-ui-compatVersion=\\"edge\\"
data-sap-ui-language=\\"en\\"
data-sap-ui-bindingSyntax=\\"complex\\"
data-sap-ui-flexibilityServices='[{\\"connector\\":\\"LrepConnector\\",\\"layers\\":[],\\"url\\":\\"/sap/bc/lrep\\"},{\\"applyConnector\\":\\"custom.connectors.WorkspaceConnector\\",\\"writeConnector\\":\\"custom.connectors.WorkspaceConnector\\",\\"custom\\":true},{\\"connector\\":\\"LocalStorageConnector\\",\\"layers\\":[\\"CUSTOMER\\",\\"USER\\"]}]'
data-sap-ui-resourceroots='{\\"myResources1\\":\\"myResourcesUrl1\\",\\"myResources2\\":\\"myResourcesUrl2\\",\\"open.ux.preview.client\\":\\"../preview/client\\",\\"my.id\\":\\"..\\",\\"test.fe.v2.other\\":\\"/yet/another/app\\"}'
data-sap-ui-frameOptions=\\"allow\\"
data-sap-ui-xx-componentPreload=\\"off\\"
data-sap-ui-oninit=\\"module:open/ux/preview/client/flp/init\\">
</script>
</head>
<!-- UI Content -->
<body class=\\"sapUiBody\\" id=\\"content\\">
</body>
</html>"
`;
exports[`FlpSandbox router rta with adp instance 1`] = `
Object {
"apps": Object {
Expand Down
46 changes: 46 additions & 0 deletions packages/preview-middleware/test/unit/base/flp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,52 @@ describe('FlpSandbox', () => {
expect(response.text).toMatchSnapshot();
});

test('rta with adp instance - preview', async () => {
const flp = new FlpSandbox(
mockConfig as unknown as Partial<MiddlewareConfig>,
mockProject,
mockUtils,
logger
);
const manifest = {
'sap.app': { id: 'my.id' }
} as Manifest;
const componendId = 'myComponent';
const resources = {
'myResources1': 'myResourcesUrl1',
'myResources2': 'myResourcesUrl2'
};
const url = 'http://sap.example';
const syncSpy = jest.fn().mockResolvedValueOnce({});
const adpToolingMock = {
init: () => {
return 'CUSTOMER_BASE';
},
descriptor: {
manifest: {},
name: 'descriptorName',
url,
asyncHints: {
requests: []
}
},
resources: [],
proxy: jest.fn(),
sync: syncSpy,
onChangeRequest: jest.fn(),
addApis: jest.fn()
} as unknown as adpTooling.AdpPreview;

await flp.init(manifest, componendId, resources, adpToolingMock as unknown as adpTooling.AdpPreview);
const app = express();
app.use(flp.router);
const server = await supertest(app);

expect(flp.templateConfig).toMatchSnapshot();
const response = await server.get('/test/flp.html').expect(200);
expect(response.text).toMatchSnapshot();
});

test('livereload port from environment', async () => {
process.env.FIORI_TOOLS_LIVERELOAD_PORT = '8080';
let response = await server.get('/my/editor.html').expect(200);
Expand Down

0 comments on commit 77cf576

Please sign in to comment.