You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2022/10/07 08:20:02 UTC

[incubator-streampipes] 01/02: [STREAMPIPES-583] Add cypress command to delete download folder

This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch STREAMPIPES-583
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git

commit 141809ca12acbbd6166f0494b4381a2a37f5e214
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Fri Oct 7 09:56:14 2022 +0200

    [STREAMPIPES-583] Add cypress command to delete download folder
---
 ui/cypress/plugins/index.ts                        | 57 ++++++++++++++++------
 .../support/general/removeDownloadDirectory.ts     | 31 ++++++++++++
 ui/cypress/support/index.ts                        |  3 +-
 3 files changed, 74 insertions(+), 17 deletions(-)

diff --git a/ui/cypress/plugins/index.ts b/ui/cypress/plugins/index.ts
index da86e8090..036d5aab7 100644
--- a/ui/cypress/plugins/index.ts
+++ b/ui/cypress/plugins/index.ts
@@ -29,6 +29,11 @@
 // the project's config changing)
 import * as fs from 'fs';
 import { ProcessorTest } from '../support/model/ProcessorTest';
+
+// tslint:disable-next-line:no-var-requires
+const { rmdir } = require('fs');
+
+// tslint:disable-next-line:no-var-requires no-implicit-dependencies
 const webpackPreprocessor = require('@cypress/webpack-batteries-included-preprocessor');
 
 function readProcessingElements(): ProcessorTest[] {
@@ -39,23 +44,23 @@ function readProcessingElements(): ProcessorTest[] {
   allPipelineTests.forEach(dir => {
     const subfolder = fs.readdirSync('cypress/fixtures/pipelineElement/' + dir);
     subfolder.forEach(test => {
-    const testDescription = fs.readFileSync('cypress/fixtures/pipelineElement/' + dir + '/' + test + '/description.json');
-    // @ts-ignore
-    const pt = new ProcessorTest();
-    pt.name = test;
-    pt.dir = dir + '/' + test;
-
-    const configDir = fs.readdirSync('cypress/fixtures/pipelineElement/' + pt.dir );
-    configDir.forEach(file => {
-      if (file.startsWith('input')) {
-        pt.inputFile = file;
-      }
-    });
+      const testDescription = fs.readFileSync('cypress/fixtures/pipelineElement/' + dir + '/' + test + '/description.json');
+      // @ts-ignore
+      const pt = new ProcessorTest();
+      pt.name = test;
+      pt.dir = dir + '/' + test;
 
-    // @ts-ignore
-    pt.processor = JSON.parse(testDescription);
+      const configDir = fs.readdirSync('cypress/fixtures/pipelineElement/' + pt.dir);
+      configDir.forEach(file => {
+        if (file.startsWith('input')) {
+          pt.inputFile = file;
+        }
+      });
 
-    result.push(pt);
+      // @ts-ignore
+      pt.processor = JSON.parse(testDescription);
+
+      result.push(pt);
     });
   });
 
@@ -66,7 +71,7 @@ module.exports = (on, config) => {
 
   const webpackOptions = webpackPreprocessor.defaultOptions.webpackOptions;
 
-  webpackOptions.resolve.fallback = { "stream": require.resolve("stream-browserify") };
+  webpackOptions.resolve.fallback = {'stream': require.resolve('stream-browserify')};
   webpackOptions.module.rules.unshift({
     test: /[/\\]@angular[/\\].+\.m?js$/,
     resolve: {
@@ -89,6 +94,26 @@ module.exports = (on, config) => {
 
   config.env.processingElements = readProcessingElements();
 
+  on('task', {
+    deleteFolder(folderName) {
+      console.log('deleting folder %s', folderName);
+      return new Promise((resolve, reject) => {
+        if (fs.existsSync(folderName)) {
+          rmdir(folderName, {maxRetries: 10, recursive: true}, (err) => {
+            if (err) {
+              console.error(err);
+              return reject(err);
+            }
+            resolve(null);
+          });
+        } else {
+          console.log('download folder %s does not exist', folderName);
+          resolve(null);
+        }
+      });
+    }
+  });
+
   return config;
 };
 
diff --git a/ui/cypress/support/general/removeDownloadDirectory.ts b/ui/cypress/support/general/removeDownloadDirectory.ts
new file mode 100644
index 000000000..05a9bd768
--- /dev/null
+++ b/ui/cypress/support/general/removeDownloadDirectory.ts
@@ -0,0 +1,31 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+declare global {
+  namespace Cypress {
+    interface Chainable {
+      removeDownloadDirectory: typeof removeDownloadDirectory;
+    }
+  }
+}
+
+export const removeDownloadDirectory = () => {
+  const downloadsFolder = Cypress.config('downloadsFolder');
+  cy.task('deleteFolder', downloadsFolder);
+};
+
diff --git a/ui/cypress/support/index.ts b/ui/cypress/support/index.ts
index b56ef9c19..561b34f7c 100644
--- a/ui/cypress/support/index.ts
+++ b/ui/cypress/support/index.ts
@@ -24,6 +24,7 @@ import { switchUser } from './general/switchUser';
 import 'cypress-file-upload';
 import { resetStreamPipes } from './general/resetStreamPipes';
 import { initStreamPipesTest } from './general/InitStreamPipesTest';
+import { removeDownloadDirectory } from './general/removeDownloadDirectory';
 
 // General commands
 Cypress.Commands.add('login', login);
@@ -32,4 +33,4 @@ Cypress.Commands.add('switchUser', switchUser);
 Cypress.Commands.add('dataCy', dataCy);
 Cypress.Commands.add('resetStreamPipes', resetStreamPipes);
 Cypress.Commands.add('initStreamPipesTest', initStreamPipesTest);
-// Cypress.Commands.add('readDir', readDir);
+Cypress.Commands.add('removeDownloadDirectory', removeDownloadDirectory);