16115: Fixes cypress tests.
[arvados-workbench2.git] / cypress / plugins / index.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 /// <reference types="cypress" />
6 // ***********************************************************
7 // This example plugins/index.js can be used to load plugins
8 //
9 // You can change the location of this file or turn off loading
10 // the plugins file with the 'pluginsFile' configuration option.
11 //
12 // You can read more here:
13 // https://on.cypress.io/plugins-guide
14 // ***********************************************************
15
16 // This function is called when a project is opened or re-opened (e.g. due to
17 // the project's config changing)
18
19 const fs = require('fs');
20 const path = require('path');
21
22 /**
23  * @type {Cypress.PluginConfig}
24  */
25 module.exports = (on, config) => {
26   // `on` is used to hook into various events Cypress emits
27   // `config` is the resolved Cypress config
28   on("before:browser:launch", (browser = {}, launchOptions) => {
29     const downloadDirectory = path.join(__dirname, "..", "downloads");
30     if (browser.family === 'chromium' && browser.name !== 'electron') {
31      launchOptions.preferences.default["download"] = {
32       default_directory: downloadDirectory
33      };
34     }
35     return launchOptions;
36   });
37
38   on('task', {
39     clearDownload({ filename }) {
40       fs.unlinkSync(filename);
41       return null;
42     }
43   });
44 }