blob: 7851503ba106249feebc2c4cb29117b32fe5e459 [file] [log] [blame] [edit]
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as path from 'path';
import * as process from 'process';
import * as fs from 'fs';
import { runTests, SilentReporter } from '@vscode/test-electron';
/**
* download vscode as necessary & run tests
*
* (needs to be a separate function because commonjs can't do top-level await)
*/
async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
// NB(sollyross): this must resolve to the directory containing package.json.
// Since our tsconfig's rootDir is ${repo_root}, this file will end up
// (when built) in ./out/src/test/, this means that's
// ../../..
const extensionDevelopmentPath = path.resolve(__dirname, '../../../');
// The path to test runner
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');
const testDataDir = path.resolve(extensionDevelopmentPath, 'testdata');
const workspaceDir = path.resolve(testDataDir, 'workspace');
// Copy configuration to disable git since `StubbedSpawn` can otherwise
// capture irrelevant git commands, resulting in flakes.
const testVscodeDir = path.join(workspaceDir, '.vscode');
fs.mkdirSync(testVscodeDir, { recursive: true });
fs.copyFileSync(
path.join(testDataDir, 'workspace_settings.json'),
path.join(testVscodeDir, 'settings.json'),
);
// Download VS Code, unzip it and run the integration test
let settings = {
extensionDevelopmentPath,
extensionTestsPath,
// NB(sollyross): keep this pinned so that infra runs are as reproducible
// as we can make them. Due to VSCode licensing issues, we can't upload
// VSCode binary distributions to CIPD, and VSCode OSS is technically
// different than binary VSCode, so we've got an exception to download
// from an external source -- see https://fxbug.dev/98159
version: '1.87.1',
// Use a silent reporter so that we don't spam CI logs
reporter: process.env.ON_CI ? new SilentReporter() : undefined,
// Disable unrelated extensions to minimize flakes.
launchArgs: ['--disable-extensions', workspaceDir],
};
await runTests(settings);
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
}
void /* cause cjs prevents top-level await */ main();