mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
* test setup, add initializer tests * test sending messages * add script to check latest version * add github action * use env vars * configure environment with .env file * add test for sticker name and author * add DownloadManager model * test chats and contacts * test for number utility functions * throw error if no remote id has been set * Update .version
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
const path = require('path');
|
|
const Client = require('../src/Client');
|
|
const Util = require('../src/util/Util');
|
|
|
|
require('dotenv').config();
|
|
|
|
const remoteId = process.env.WWEBJS_TEST_REMOTE_ID;
|
|
if(!remoteId) throw new Error('The WWEBJS_TEST_REMOTE_ID environment variable has not been set.');
|
|
|
|
function getSessionFromEnv() {
|
|
const envSession = process.env.WWEBJS_TEST_SESSION;
|
|
if(envSession) return JSON.parse(envSession);
|
|
|
|
const envSessionPath = process.env.WWEBJS_TEST_SESSION_PATH;
|
|
if(envSessionPath) {
|
|
const absPath = path.resolve(process.cwd(), envSessionPath);
|
|
return require(absPath);
|
|
}
|
|
|
|
throw new Error('No session found in environment.');
|
|
}
|
|
|
|
function createClient({withSession, options: additionalOpts}={}) {
|
|
const options = {};
|
|
if(withSession) {
|
|
options.session = getSessionFromEnv();
|
|
}
|
|
|
|
return new Client(Util.mergeDefault(options, additionalOpts || {}));
|
|
}
|
|
|
|
function sleep(ms) {
|
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
}
|
|
|
|
module.exports = {
|
|
sleep,
|
|
createClient,
|
|
remoteId
|
|
}; |