From 6a718024b0907e5ffaacc9c5f3ac592e4f2662a2 Mon Sep 17 00:00:00 2001 From: Joao Date: Wed, 6 Sep 2017 10:13:49 +0200 Subject: [PATCH] smoke: create test_data in tmp --- build/tfs/linux/smoketest.sh | 1 - test/smoke/package.json | 3 ++- test/smoke/src/main.ts | 16 ++++++++++++---- test/smoke/src/spectron/application.ts | 12 ++++++------ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/build/tfs/linux/smoketest.sh b/build/tfs/linux/smoketest.sh index d8748a35dab..c39bf687b25 100644 --- a/build/tfs/linux/smoketest.sh +++ b/build/tfs/linux/smoketest.sh @@ -30,7 +30,6 @@ function configureEnvironment { id -u testuser &>/dev/null || (useradd -m testuser; chpasswd <<< testuser:testpassword) sudo -i -u testuser git config --global user.name "VS Code Agent" sudo -i -u testuser git config --global user.email "monacotools@microsoft.com" - chown -R testuser $AGENT_BUILDDIRECTORY } step "Configure environment" \ diff --git a/test/smoke/package.json b/test/smoke/package.json index d7c28fc1f0e..6aedcc86f93 100644 --- a/test/smoke/package.json +++ b/test/smoke/package.json @@ -20,6 +20,7 @@ "rimraf": "^2.6.1", "spectron": "~3.6.4", "strip-json-comments": "^2.0.1", + "tmp": "0.0.33", "typescript": "^2.2.2" } -} \ No newline at end of file +} diff --git a/test/smoke/src/main.ts b/test/smoke/src/main.ts index f35de669b53..e0e44fe7690 100644 --- a/test/smoke/src/main.ts +++ b/test/smoke/src/main.ts @@ -7,17 +7,21 @@ import * as fs from 'fs'; import * as https from 'https'; import * as cp from 'child_process'; import * as path from 'path'; -import * as mkdirp from 'mkdirp'; import * as minimist from 'minimist'; +import * as tmp from 'tmp'; +import * as rimraf from 'rimraf'; const [, , ...args] = process.argv; const opts = minimist(args, { string: ['build', 'stable-build'] }); -const testDataPath = path.join(__dirname, '..', 'test_data'); +const tmpDir = tmp.dirSync() as { name: string; removeCallback: Function; }; +const testDataPath = tmpDir.name; +process.once('exit', () => rimraf.sync(testDataPath)); + const workspacePath = path.join(testDataPath, 'smoketest.code-workspace'); const testRepoUrl = 'https://github.com/Microsoft/vscode-smoketest-express'; const testRepoLocalDir = path.join(testDataPath, 'vscode-smoketest-express'); -mkdirp.sync(testDataPath); +const keybindingsPath = path.join(testDataPath, 'keybindings.json'); function fail(errorMessage): void { console.error(errorMessage); @@ -67,8 +71,11 @@ if (!fs.existsSync(testCodePath)) { fail(`Can't find Code at ${testCodePath}.`); } +process.env.VSCODE_USER_DIR = path.join(testDataPath, 'user-dir'); +process.env.VSCODE_EXTENSIONS_DIR = path.join(testDataPath, 'extensions-dir'); process.env.SMOKETEST_REPO = testRepoLocalDir; process.env.VSCODE_WORKSPACE_PATH = workspacePath; +process.env.VSCODE_KEYBINDINGS_PATH = keybindingsPath; if ((testCodePath.indexOf('Code - Insiders') /* macOS/Windows */ || testCodePath.indexOf('code-insiders') /* Linux */) >= 0) { process.env.VSCODE_EDITION = 'insiders'; @@ -91,6 +98,7 @@ function toUri(path: string): string { } async function main(): Promise { + console.log('*** Test data:', testDataPath); console.log('*** Preparing smoketest setup...'); const keybindingsUrl = `https://raw.githubusercontent.com/Microsoft/vscode-docs/master/scripts/keybindings/doc.keybindings.${getKeybindingPlatform()}.json`; @@ -98,7 +106,7 @@ async function main(): Promise { await new Promise((c, e) => { https.get(keybindingsUrl, res => { - const output = fs.createWriteStream(path.join(testDataPath, 'keybindings.json')); + const output = fs.createWriteStream(keybindingsPath); res.on('error', e); output.on('error', e); output.on('close', c); diff --git a/test/smoke/src/spectron/application.ts b/test/smoke/src/spectron/application.ts index 642e5dc242a..59473234d25 100644 --- a/test/smoke/src/spectron/application.ts +++ b/test/smoke/src/spectron/application.ts @@ -10,12 +10,12 @@ import { Workbench } from '../areas/workbench/workbench'; import * as fs from 'fs'; import * as path from 'path'; -export const LATEST_PATH = process.env.VSCODE_PATH || ''; +export const LATEST_PATH = process.env.VSCODE_PATH as string; export const STABLE_PATH = process.env.VSCODE_STABLE_PATH || ''; -export const WORKSPACE_PATH = process.env.SMOKETEST_REPO || ''; -export const CODE_WORKSPACE_PATH = process.env.VSCODE_WORKSPACE_PATH || ''; -export const USER_DIR = path.resolve(path.join(__dirname, '../../test_data/temp_user_dir')); -export const EXTENSIONS_DIR = path.resolve(path.join(__dirname, '../../test_data/temp_extensions_dir')); +export const WORKSPACE_PATH = process.env.SMOKETEST_REPO as string; +export const CODE_WORKSPACE_PATH = process.env.VSCODE_WORKSPACE_PATH as string; +export const USER_DIR = process.env.VSCODE_USER_DIR as string; +export const EXTENSIONS_DIR = process.env.VSCODE_EXTENSIONS_DIR as string; /** * Wraps Spectron's Application instance with its used methods. @@ -129,7 +129,7 @@ export class SpectronApplication { } private retrieveKeybindings() { - fs.readFile(path.join(__dirname, '../../test_data/keybindings.json'), 'utf8', (err, data) => { + fs.readFile(process.env.VSCODE_KEYBINDINGS_PATH as string, 'utf8', (err, data) => { if (err) { throw err; }