How can we change the chrome default download directory in Testcafe? - testing

Kindly provide the steps to set the download file path in Testcafe.

If you need to find and check a downloaded file, you can use the following ways:
Use the RequestLogger: Check the Downloaded File Name and Content example
Obtain a "Downloads" folder path from the system environment variables or use the downloads-folder package:
import fs from 'fs';
import downloadsFolder from 'downloads-folder';
fixture('fixture')
.page('http://example.com/');
test('test', async t => {
await t.click('#download');
const filePath = downloadsFolder() + '/my-file.txt';
await t.expect(fs.existsSync(filePath)).ok();
});
Also, TestCafe internal API allows you to change the downloads path: https://stackoverflow.com/a/65732040/10684943. Note that this approach is not recommended. Use it at your own risk.

Related

get file type after downloading from IPFS

I'm using ipfs to download files... but ipfs does not have filenames or extensions.
How can I properly set the extension for the saved file, based on the downloaded data?
You can add files with ipfs add -w to "wrap" them in a directory. This will preserve the filename.
There are also plans to record metadata like mime types along with files but, unfortunately, progress has gotten a bit stuck on this front.
There is no way to conclusively get the file extension in IPFS, so instead, you can look at the contents of the file to infer its file type (using file-type, for example)
When you have the full contents of the file in a buffer, you can do:
import {fileTypeFromBuffer} from 'file-type';
let buffer = /* buffer of file from IPFS */;
// undefined or string of file extension
let ext = (await fileTypeFromBuffer(buffer))?.ext;
If you wan't to do this in a React app on the frontend this works :
let contentType = await fetch(imageUrl)
.then(response => {
return response.blob().then(blob => {
return {
contentType: response.headers.get("Content-Type"),
raw: blob
}
})
})
.then(data => {
return data.contentType
})
file-type is intended for use in Node apps, not on the client side.
If you try to use a library intended for Node then you will get errors that relate to the library's internal dependencies on built-in Node modules which are not available in the browser. You should use a different library for making HTTP requests from the browser; I'd suggest using the browser's built-in fetch.
you must get the program file type, then import the extension name on the program name you downloaded from the buffer
i hope you understand this

In a VS Code Extension, open the markdown preview of the README.md of the extension

I would like to be able to show a markdown preview of the README.md file from the extension with a command palette option. I understand how to open a file from the open folder of the active VS Code window, but how do I access a file from the repo of the extension?
I have this, but it gives an error
context.subscriptions.push(
vscode.commands.registerCommand('new-extension.showReadMe', async () => {
const docs = await vscode.workspace.openTextDocument('../README.md')
await vscode.window.showTextDocument(docs)
})
)
Use the asAbsolutePath function provided by the ExtensionContext type to generate an absolute path to a file that is part of the extension.
An instance of ExtensionContext is passed into an extension's activate function.
In the following example, the Markdown preview of an extension's README.md file is displayed as the extension is activated:
export async function activate(context: vscode.ExtensionContext) {
const readmePath = context.asAbsolutePath("README.md");
vscode.commands.executeCommand("markdown.showPreview", vscode.Uri.file(readmePath));
}

Get launch configurations from vscode extension

How can I get all launch configurations?
I considered reading the launch.json file in the .vscode folder, but then I realized that there are some launch configurations that are created dynamically and others that are available without any launch.json file present anywhere. How do I get these configurations?
You can use below code to fetch all the launch configurations:
let workspace = workspace.uri.path;
const config = vscode.workspace.getConfiguration("launch", workspace);
const configurations = config.get<any[]>("configurations");
if (!configurations) {
return;
}
configurations.forEach((config) => {
// read or modify the config
})

mongoose and express not reading from .env file

I am having some trouble importing a .env file into my project. I have fallbacks in place so I didn't notice the issue until I was almost done with my project and was having trouble implementing a paypal button that wouldn't load. Now I am testing and I realize that all my env files have not been importing :/
I am new to using express but I think I did everything correctly as far as I can tell (but obviously not lol). I have imported all my dependencies and I am using dotenv:
import express from "express";
import mongoose from "mongoose";
import dotenv from "dotenv";
My code for importing my paypal .env file:
app.get("/api/config/paypal", (req, res) => {
res.send(process.env.PAYPAL_CLIENT_ID || "sb");
});
my .env file (located at the root of my folder structure)
PAYPAL_CLIENT_ID= my key info here without quotes
Where the code is eventually being called
const addPayPalScript = async () => {
}, [dispatch, orderId]); const { data } = await Axios.get('/api/config/paypal');
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = `https://www.paypal.com/sdk/js?client-id=${data}`;
script.async = true;
I am not sure why this configuration is not working. I have tried to move the env file to the same folder as the file that is calling it but this just fails to compile with an error. (I have a frontend and a backend folder) I have tried to move the env file to the root of the backend folder and it fails to compile with the same error message. It seems like the root of the project file is the correct location for the env file and all the information I can find online seems like my code is okay, but I still can not load the link for the paypal button when it is clicked on.
Any help would be greatly appreciated. Thank you!
Here is what you should do :
Instead of import dotenv from "dotenv";
Use :
import {config} from "dotenv";
config()
The only function you need from the dotenv library to read your .env configuration is config, to invoke it i've done config()
Now you can access values by doing : process.env.YOUR_ENV_VARIABLE_NAME

How to use passwords with Hapi/Glue/Compose?

I have a project which configures a Hapi web server via glue and compose.
Excerpt from TypeScript file:
import { compose as glue } from 'glue';
import { Store } from 'confidence';
import config from './config.json';
const manifest = new Store(config).get('/', {
env: process.env.NODE_ENV,
});
const options = {
relativeTo: __dirname,
};
const server = await glue(manifest, options);
The problem now is that all passwords are directly stored in the config.json file.
Does confidence support the injection of passwords, for example from environment variables?
Or do I somehow have to inject them afterwards, for example using nconf?
I thought same and added my small modification to manifest file. You can use external config library. I am using node-config.
Now I can separate my development and production passwords/keys/secrets.
To .gitignore file I added
config/development.json
config/test.json
config/production.json
Local development uses development.json and production uses production.json. This way I don't need to put my secrets to a file and push to the repo.
Here you can find implementation details. It will give you an idea of how this works.