From b3aeca7bfd707eb8859a485c22f563f110b7b04d Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 16 Aug 2023 14:38:26 +0100 Subject: [PATCH] [ACS-5845] remove deprecated js-api compat mode (#3387) --- .../e2e-config/utils/upload-output.js | 70 ++++++++++--------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/e2e/protractor/e2e-config/utils/upload-output.js b/e2e/protractor/e2e-config/utils/upload-output.js index e755bc437d..532d7b7f9a 100644 --- a/e2e/protractor/e2e-config/utils/upload-output.js +++ b/e2e/protractor/e2e-config/utils/upload-output.js @@ -1,6 +1,7 @@ -const path = require('path'); -const fs = require('fs'); -const AlfrescoApi = require('@alfresco/js-api').AlfrescoApiCompatibility; +const path = require('node:path'); +const fs = require('node:fs'); +const child_process = require('node:child_process'); +const { AlfrescoApi, NodesApi, UploadApi } = require('@alfresco/js-api'); const buildNumber = require('./build-number'); const outputDir = path.resolve(__dirname, '../../../e2e-output/'); @@ -8,54 +9,59 @@ async function saveScreenshots(retryCount) { const folderName = process.env.GITHUB_JOB; console.log(`Start uploading report in ${folderName}`); - let alfrescoJsApi = new AlfrescoApi({ + const alfrescoJsApi = new AlfrescoApi({ provider: 'ECM', hostEcm: process.env.SCREENSHOT_URL }); + const nodesApi = new NodesApi(alfrescoJsApi); + const uploadApi = new UploadApi(alfrescoJsApi); + await alfrescoJsApi.login(process.env.SCREENSHOT_USERNAME, process.env.SCREENSHOT_PASSWORD); let folderNode; try { - folderNode = await alfrescoJsApi.nodes.addNode('-my-', { - 'name': `retry-${retryCount}`, - 'relativePath': `Builds/ACA-${buildNumber()}/${folderName}/`, - 'nodeType': 'cm:folder' - }, {}, { - 'overwrite': true - }); + folderNode = await nodesApi.createNode( + '-my-', + { + name: `retry-${retryCount}`, + relativePath: `Builds/ACA-${buildNumber()}/${folderName}/`, + nodeType: 'cm:folder' + }, + {}, + { + overwrite: true + } + ); } catch (error) { - folderNode = await alfrescoJsApi.nodes.getNode('-my-', { - 'relativePath': `Builds/ACA-${buildNumber()}/${folderName}/retry-${retryCount}`, - 'nodeType': 'cm:folder' - }, {}, { - 'overwrite': true - }); + folderNode = await nodesApi.createNode( + '-my-', + { + relativePath: `Builds/ACA-${buildNumber()}/${folderName}/retry-${retryCount}`, + nodeType: 'cm:folder' + }, + {}, + { + overwrite: true + } + ); } fs.renameSync(outputDir, path.join(`${outputDir}-${folderName}-${retryCount}/`)); - const child_process = require("child_process"); child_process.execSync(` tar -czvf ../e2e-result-${folderName}-${retryCount}.tar .`, { cwd: `${outputDir}-${folderName}-${retryCount}/` }); - let pathFile = path.join(outputDir, `../e2e-result-${folderName}-${retryCount}.tar`); - - let file = fs.createReadStream(pathFile); - await alfrescoJsApi.upload.uploadFile( - file, - '', - folderNode.entry.id, - null, - { - 'name': `e2e-result-${folderName}-${retryCount}.tar`, - 'nodeType': 'cm:content', - 'autoRename': true - } - ); + const pathFile = path.join(outputDir, `../e2e-result-${folderName}-${retryCount}.tar`); + const file = fs.createReadStream(pathFile); + await uploadApi.uploadFile(file, '', folderNode.entry.id, null, { + name: `e2e-result-${folderName}-${retryCount}.tar`, + nodeType: 'cm:content', + autoRename: true + }); } module.exports = {