UNPKG

vscode-extension-tester

Version:

ExTester is a package that is designed to help you run UI tests for your Visual Studio Code extensions using selenium-webdriver.

103 lines 4.11 kB
"use strict"; /** * 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", destination); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * https://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. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Download = void 0; const fs = __importStar(require("fs-extra")); const util_1 = require("util"); const stream_1 = __importDefault(require("stream")); const hpagent_1 = require("hpagent"); const httpProxyAgent = !process.env.HTTP_PROXY ? undefined : new hpagent_1.HttpProxyAgent({ proxy: process.env.HTTP_PROXY, }); const httpsProxyAgent = !process.env.HTTPS_PROXY ? undefined : new hpagent_1.HttpsProxyAgent({ proxy: process.env.HTTPS_PROXY, }); const options = { headers: { 'user-agent': 'nodejs', }, agent: { http: httpProxyAgent, https: httpsProxyAgent, }, }; class Download { static async getText(uri) { const got = (await import('got')).default; const body = await got(uri, options).text(); return JSON.parse(body); } static async getFile(uri, destination, progress = false) { let lastTick = 0; const got = (await import('got')).default; const dlStream = got.stream(uri, options); if (progress) { dlStream.on('downloadProgress', ({ transferred, total, percent }) => { const currentTime = Date.now(); if (total > 0 && (lastTick === 0 || transferred === total || currentTime - lastTick >= 2000)) { console.log(`progress: ${transferred}/${total} (${Math.floor(100 * percent)}%)`); lastTick = currentTime; } }); } const writeStream = fs.createWriteStream(destination); return await (0, util_1.promisify)(stream_1.default.pipeline)(dlStream, writeStream); } } exports.Download = Download; //# sourceMappingURL=download.js.map