Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Commit

Permalink
Get tests running
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTup committed Jan 3, 2020
1 parent 20896cf commit ad25921
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 123 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.test_data_dir/
.vscode-test/
.vscode/.browse.VC.db*
*.log
Expand Down
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
},
"dependencies": {},
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/mocha": "^5.2.7",
"@types/node": "^12.12.14",
"@types/vscode": "^1.40.0",
"vscode-test": "^1.2.3",
"glob": "^7.1.6",
"mocha": "^6.2.2",
"typescript": "3.4.3"
"typescript": "3.4.3",
"vscode-test": "^1.2.3"
}
}
101 changes: 6 additions & 95 deletions src/test/test_all.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,22 @@
import * as fs from "fs";
import * as path from "path";
import * as vstest from "vscode-test";

let exitCode = 0;
const cwd = process.cwd();
const testEnv = Object.create(process.env);

async function runTests(testFolder: string, workspaceFolder: string, logSuffix?: string, env?: {}): Promise<void> {
console.log(
`Running ${testFolder} tests folder in workspace ${workspaceFolder}`);
async function runTests(testFolder: string, workspaceFolder: string, env?: {}): Promise<void> {
console.log(`Running ${testFolder} tests folder in workspace ${workspaceFolder}`);

const logsName = process.env.LOGS_NAME;
const testRunName = `${testFolder.replace("/", "_")}${logSuffix ? `_${logSuffix}` : ""}_${logsName}`;

testEnv.TEST_RUN_NAME = testRunName;
testEnv.DC_TEST_LOGS = path.join(cwd, ".dart_code_test_logs", `${testRunName}`);
testEnv.COVERAGE_OUTPUT = path.join(cwd, ".nyc_output", `${testRunName}.json`);
testEnv.TEST_XML_OUTPUT = path.join(cwd, ".test_results", `${testRunName}.xml`);
testEnv.TEST_CSV_SUMMARY = path.join(cwd, ".test_results", `${testRunName}_summary.csv`);

if (!fs.existsSync(testEnv.DC_TEST_LOGS))
fs.mkdirSync(testEnv.DC_TEST_LOGS);

// The VS Code download is often flaky on GH Actions, so we want to retry
// if required - however we don't want to re-run tests if they fail, so do
// the download step separately.
let currentAttempt = 1;
const maxAttempts = 5;
while (currentAttempt <= maxAttempts) {
try {
console.log(`Attempting to download VS Code attempt #${currentAttempt}`);
await vstest.downloadAndUnzipVSCode(process.env.CODE_VERSION);
break;
} catch (e) {
if (currentAttempt >= maxAttempts)
throw e;

console.warn(`Failed to download VS Code, will retry: ${e}`);
currentAttempt++;
}
}

console.log("Running tests with pre-downloaded VS Code");
try {
const res = await vstest.runTests({
extensionDevelopmentPath: cwd,
extensionTestsEnv: { ...testEnv, ...env },
extensionTestsPath: path.join(cwd, "out", "src", "test", testFolder),
launchArgs: [
path.isAbsolute(workspaceFolder)
? workspaceFolder
: path.join(cwd, "src", "test", "test_projects", workspaceFolder),
path.join(cwd, "src", "test", "test_projects", workspaceFolder),
"--user-data-dir",
path.join(cwd, ".dart_code_test_data_dir"),
path.join(cwd, ".test_data_dir"),
],
version: process.env.CODE_VERSION,
});
Expand All @@ -61,66 +25,13 @@ async function runTests(testFolder: string, workspaceFolder: string, logSuffix?:
console.error(e);
exitCode = exitCode || 999;
}

console.log("############################################################");
console.log("\n\n");
}

async function runAllTests(): Promise<void> {
if (process.env.CI) {
console.log("\n\n");
console.log("A combined test summary will be available at:");
console.log(` https://dartcode.org/test-results/?${process.env.GITHUB_REF}/${process.env.GITHUB_SHA}`);
console.log("\n\n");
}

testEnv.DART_CODE_IS_TEST_RUN = true;
testEnv.MOCHA_FORBID_ONLY = true;

// Ensure any necessary folders exist.
if (!fs.existsSync(".nyc_output"))
fs.mkdirSync(".nyc_output");
if (!fs.existsSync(".dart_code_test_logs"))
fs.mkdirSync(".dart_code_test_logs");

try {
if (!process.env.BOT || process.env.BOT === "dart") {
await runTests("dart", "hello_world");
}
if (!process.env.BOT || process.env.BOT === "dart_debug") {
await runTests("dart_debug", "hello_world");
}
if (!process.env.BOT || process.env.BOT === "dart_web_debug") {
await runTests("web_debug", "web");
}
if (!process.env.BOT || process.env.BOT === "flutter") {
await runTests("flutter", "flutter_hello_world");
}
if (!process.env.BOT || process.env.BOT === "flutter_debug") {
await runTests("flutter_debug", "flutter_hello_world");
}
if (!process.env.BOT || process.env.BOT === "flutter_debug_chrome") {
await runTests("flutter_debug", "flutter_hello_world", "chrome", { FLUTTER_TEST_DEVICE_ID: "chrome" });
}
if (!process.env.BOT || process.env.BOT === "flutter_test_debug") {
await runTests("flutter_test_debug", "flutter_hello_world");
}
if (!process.env.BOT || process.env.BOT === "misc") {
await runTests("dart_create_tests", "dart_create_tests.code-workspace");
await runTests("not_activated/dart_create", "empty");
await runTests("multi_root", "projects.code-workspace");
await runTests("multi_project_folder", "");
await runTests("not_activated/flutter_create", "empty");
await runTests("flutter_create_tests", "flutter_create_tests.code-workspace");
}
if (!process.env.BOT || process.env.BOT === "flutter_repo") {
if (process.env.FLUTTER_REPO_PATH) {
await runTests("flutter_repository", process.env.FLUTTER_REPO_PATH);
} else {
console.error("process.env.FLUTTER_REPO_PATH not set, not running flutter_repo tests");
exitCode = 1;
}
}
await runTests("test1", "empty");
await runTests("test2", "empty");
} catch (e) {
exitCode = 1;
console.error(e);
Expand Down
29 changes: 3 additions & 26 deletions src/test/test_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,27 @@ console.log("Starting test runner...");
import * as glob from "glob";
import * as Mocha from "mocha";
import * as path from "path";
import { MultiReporter } from "./mocha_multi_reporter";

module.exports = {
run(testsRoot: string, cb: (error: any, failures?: number) => void): void {
// Create the mocha test
const mocha = new Mocha({
forbidOnly: !!process.env.MOCHA_FORBID_ONLY,
reporter: MultiReporter,
reporterOptions: {
output: process.env.TEST_XML_OUTPUT,
summaryFile: process.env.TEST_CSV_SUMMARY,
testRunName: process.env.TEST_RUN_NAME,
},
slow: 30000, // increased threshold before marking a test as slow
timeout: 360000, // increased timeout because starting up Code, Analyzer, Pub, etc. is slooow
ui: "bdd", // the TDD UI is being used in extension.test.ts (suite, test, etc.)
});
mocha.useColors(true);

// Set up source map support.
require("source-map-support").install();

const callCallback = (error: any, failures?: number) => {
setTimeout(() => {
console.error(`Test process did not quit within 10 seconds!`);
}, 10000).unref();

console.log(`Test run is complete! Calling VS Code callback with (${error}, ${failures})`);
cb(error, failures);
};

glob("**/**.test.js", { cwd: testsRoot }, (err, files) => {
if (err) {
return callCallback(err);
return cb(err);
}

// Add files to the test suite
files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));

try {
// Run the mocha test
mocha.run((failures) => callCallback(null, failures));
mocha.run((failures) => cb(null, failures));
} catch (err) {
callCallback(err);
cb(err);
}
});
},
Expand Down

0 comments on commit ad25921

Please sign in to comment.