Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 43 additions & 31 deletions src/server/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,50 +88,62 @@ async function downloadAndUntar(downloadUrl: string, destination: string, messag


export async function downloadAndUnzipVSCode(vscodeTestDir: string, quality: 'stable' | 'insider', commit: string | undefined): Promise<Static> {
let downloadURL: string | undefined;
if (!commit) {
const info = await getLatestBuild(quality);
commit = info.version;
downloadURL = info.url;
}
let retries = 3;
do {
try {
let downloadURL: string | undefined;
if (!commit) {
const info = await getLatestBuild(quality);
commit = info.version;
downloadURL = info.url;
}

const folderName = `vscode-web-${quality}-${commit}`;
const downloadedPath = path.resolve(vscodeTestDir, folderName);
if (existsSync(downloadedPath) && existsSync(path.join(downloadedPath, 'version'))) {
return { type: 'static', location: downloadedPath, quality, version: commit };
}
const folderName = `vscode-web-${quality}-${commit}`;
const downloadedPath = path.resolve(vscodeTestDir, folderName);
if (existsSync(downloadedPath) && existsSync(path.join(downloadedPath, 'version'))) {
return { type: 'static', location: downloadedPath, quality, version: commit };
}

if (!downloadURL) {
downloadURL = await getDownloadURL(quality, commit);
if (!downloadURL) {
throw Error(`Failed to find a download for ${quality} and ${commit}`);
}
}
if (!downloadURL) {
downloadURL = await getDownloadURL(quality, commit);
if (!downloadURL) {
throw Error(`Failed to find a download for ${quality} and ${commit}`);
}
}

if (existsSync(vscodeTestDir)) {
await fs.rm(vscodeTestDir, { recursive: true, maxRetries: 5 });
}
if (existsSync(vscodeTestDir)) {
await fs.rm(vscodeTestDir, { recursive: true, maxRetries: 5 });
}

await fs.mkdir(vscodeTestDir, { recursive: true });
await fs.mkdir(vscodeTestDir, { recursive: true });

const productName = `VS Code ${quality === 'stable' ? 'Stable' : 'Insiders'}`;
const productName = `VS Code ${quality === 'stable' ? 'Stable' : 'Insiders'}`;

try {
await downloadAndUntar(downloadURL, downloadedPath, `Downloading ${productName}`);
await fs.writeFile(path.join(downloadedPath, 'version'), folderName);
} catch (err) {
console.error(err);
throw Error(`Failed to download and unpack ${productName}.${commit ? ' Did you specify a valid commit?' : ''}`);
}
return { type: 'static', location: downloadedPath, quality, version: commit };
try {
await downloadAndUntar(downloadURL, downloadedPath, `Downloading ${productName}`);
await fs.writeFile(path.join(downloadedPath, 'version'), folderName);
} catch (err) {
console.error(err);
throw Error(`Failed to download and unpack ${productName}.${commit ? ' Did you specify a valid commit?' : ''}`);
}
return { type: 'static', location: downloadedPath, quality, version: commit };
} catch (e) {
retries--;
if (retries === 0) {
throw e;
}
console.log(`Download and install failed with '${e}'. Retrying... (${retries} attempts left)`);
await new Promise(resolve => setTimeout(resolve, 3000));
}
} while (true);
}

export async function fetch(api: string): Promise<string> {
return new Promise((resolve, reject) => {
const httpLibrary = api.startsWith('https') ? https : http;
httpLibrary.get(api, getAgent(api), res => {
if (res.statusCode !== 200) {
reject('Failed to get content from ');
reject('Failed to get content from ' + api + '. Status code: ' + res.statusCode );
}

let data = '';
Expand Down
103 changes: 55 additions & 48 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,57 +666,64 @@ async function cliMain(): Promise<void> {
}

if (extensionTestsPath) {
runTests({
extensionTestsPath,
extensionDevelopmentPath,
browserOptions,
browserType,
quality,
commit,
devTools,
waitForDebugger,
folderUri,
folderPath,
headless,
printServerLog,
permissions,
extensionPaths,
extensionIds,
vsCodeDevPath,
verbose,
esm,
coi,
host,
port,
testRunnerDataDir,
}).catch(e => {
try {
await runTests({
extensionTestsPath,
extensionDevelopmentPath,
browserOptions,
browserType,
quality,
commit,
devTools,
waitForDebugger,
folderUri,
folderPath,
headless,
printServerLog,
permissions,
extensionPaths,
extensionIds,
vsCodeDevPath,
verbose,
esm,
coi,
host,
port,
testRunnerDataDir,
});
} catch (e) {
console.log('Error running tests:', e);
process.exit(1);
});
}
} else {
open({
extensionDevelopmentPath,
browserOptions,
browserType,
quality,
commit,
devTools,
waitForDebugger,
folderUri,
folderPath,
headless,
printServerLog,
permissions,
extensionPaths,
extensionIds,
vsCodeDevPath,
verbose,
esm,
coi,
host,
port,
testRunnerDataDir,
});
try {
await open({
extensionDevelopmentPath,
browserOptions,
browserType,
quality,
commit,
devTools,
waitForDebugger,
folderUri,
folderPath,
headless,
printServerLog,
permissions,
extensionPaths,
extensionIds,
vsCodeDevPath,
verbose,
esm,
coi,
host,
port,
testRunnerDataDir,
});
} catch (e) {
console.log('Error opening browser:', e);
process.exit(1);
}
}
}

Expand Down