From 1aaf47e812664af2b1db1519e74119f78aa19192 Mon Sep 17 00:00:00 2001 From: Joao Date: Fri, 8 Sep 2017 17:20:04 +0200 Subject: [PATCH] smoke: better screenshot folder management --- build/tfs/darwin/smoketest.sh | 5 ++++- build/tfs/linux/smoketest.sh | 10 ++++++--- build/tfs/win32/smoketest.ps1 | 5 ++++- test/smoke/src/helpers/screenshot.ts | 4 ++-- test/smoke/src/main.ts | 28 ++++++++------------------ test/smoke/src/spectron/application.ts | 1 - 6 files changed, 25 insertions(+), 28 deletions(-) diff --git a/build/tfs/darwin/smoketest.sh b/build/tfs/darwin/smoketest.sh index 2d025ccd471..544f5b04941 100755 --- a/build/tfs/darwin/smoketest.sh +++ b/build/tfs/darwin/smoketest.sh @@ -22,8 +22,11 @@ step "Build minified & upload source maps" \ npm run gulp -- vscode-darwin-min function runSmokeTest { + SCREENSHOTS="$AGENT_BUILDDIRECTORY/smoketest-screenshots" + rm -rf $SCREENSHOTS + cd $BUILD_SOURCESDIRECTORY/test/smoke && \ - ./node_modules/.bin/mocha --build "$AGENT_BUILDDIRECTORY/VSCode-darwin/Visual Studio Code - Insiders.app/Contents/MacOS/Electron" --screenshot + ./node_modules/.bin/mocha --build "$AGENT_BUILDDIRECTORY/VSCode-darwin/Visual Studio Code - Insiders.app/Contents/MacOS/Electron" --screenshots $SCREENSHOTS } step "Run smoke test" \ diff --git a/build/tfs/linux/smoketest.sh b/build/tfs/linux/smoketest.sh index 97712d59281..84677a353c5 100644 --- a/build/tfs/linux/smoketest.sh +++ b/build/tfs/linux/smoketest.sh @@ -11,15 +11,19 @@ VSO_PAT="$2" echo "machine monacotools.visualstudio.com password $VSO_PAT" > ~/.netrc +export SCREENSHOTS="$AGENT_BUILDDIRECTORY/smoketest-screenshots" + function configureEnvironment { id -u testuser &>/dev/null || (useradd -m testuser; chpasswd <<< testuser:testpassword) sudo -i -u testuser -- sh -c 'git config --global user.name "VS Code Agent" && git config --global user.email "monacotools@microsoft.com"' - mkdir -p $AGENT_BUILDDIRECTORY/smoketest-screenshots - chown -R testuser $AGENT_BUILDDIRECTORY/smoketest-screenshots + + sudo rm -rf $SCREENSHOTS + mkdir -p $SCREENSHOTS + chown -R testuser $SCREENSHOTS } function runSmokeTest { - DISPLAY=:10 sudo -i -u testuser -- sh -c "cd $BUILD_SOURCESDIRECTORY/test/smoke && ./node_modules/.bin/mocha --build $AGENT_BUILDDIRECTORY/VSCode-linux-x64/code-insiders --screenshot" + DISPLAY=:10 sudo -i -u testuser -- sh -c "cd $BUILD_SOURCESDIRECTORY/test/smoke && ./node_modules/.bin/mocha --build $AGENT_BUILDDIRECTORY/VSCode-linux-x64/code-insiders --screenshots $SCREENSHOTS" } step "Install dependencies" \ diff --git a/build/tfs/win32/smoketest.ps1 b/build/tfs/win32/smoketest.ps1 index fa87d75876d..9cae6c97b59 100644 --- a/build/tfs/win32/smoketest.ps1 +++ b/build/tfs/win32/smoketest.ps1 @@ -38,8 +38,11 @@ step "Build minified" { } step "Run smoke test" { + $Screenshots = "$env:AGENT_BUILDDIRECTORY\smoketests-screenshots" + Remove-Item -Recurse -Force $Screenshots + exec { & Push-Location test\smoke } - exec { & .\node_modules\.bin/mocha --build "$env:AGENT_BUILDDIRECTORY\VSCode-win32-$global:arch\Code - Insiders.exe" --screenshot } + exec { & .\node_modules\.bin/mocha --build "$env:AGENT_BUILDDIRECTORY\VSCode-win32-$global:arch\Code - Insiders.exe" --screenshots "$Screenshots" } exec { & Pop-Location } } diff --git a/test/smoke/src/helpers/screenshot.ts b/test/smoke/src/helpers/screenshot.ts index e6eb82fd77c..e991a4fb9fe 100644 --- a/test/smoke/src/helpers/screenshot.ts +++ b/test/smoke/src/helpers/screenshot.ts @@ -7,7 +7,7 @@ import * as path from 'path'; import * as fs from 'fs'; import * as mkdirp from 'mkdirp'; import { Application } from 'spectron'; -import { SCREENSHOTS_DIR, CAPTURE_SCREENSHOT } from '../spectron/application'; +import { SCREENSHOTS_DIR } from '../spectron/application'; function sanitize(name: string): string { return name.replace(/[&*:\/]/g, ''); @@ -21,7 +21,7 @@ export class ScreenCapturer { constructor(private application: Application, private suiteName: string) { } async capture(name: string): Promise { - if (!CAPTURE_SCREENSHOT) { + if (!SCREENSHOTS_DIR) { return; } diff --git a/test/smoke/src/main.ts b/test/smoke/src/main.ts index 70ee3158bd2..986431b5538 100644 --- a/test/smoke/src/main.ts +++ b/test/smoke/src/main.ts @@ -11,14 +11,16 @@ import * as minimist from 'minimist'; import * as tmp from 'tmp'; import * as rimraf from 'rimraf'; import * as mkdirp from 'mkdirp'; -import { ncp } from 'ncp'; - -const [, , ...args] = process.argv; -const opts = minimist(args, { string: ['build', 'stable-build'], boolean: ['screenshot'] }); const tmpDir = tmp.dirSync() as { name: string; removeCallback: Function; }; const testDataPath = tmpDir.name; -process.once('exit', code => code === 0 && rimraf.sync(testDataPath)); +process.once('exit', () => rimraf.sync(testDataPath)); + +const [, , ...args] = process.argv; +const opts = minimist(args, { string: ['build', 'stable-build', 'screenshots'] }); + +opts.screenshots = opts.screenshots === '' ? path.join(testDataPath, 'screenshots') : opts.screenshots; +mkdirp.sync(opts.screenshots); const workspacePath = path.join(testDataPath, 'smoketest.code-workspace'); const testRepoUrl = 'https://github.com/Microsoft/vscode-smoketest-express'; @@ -77,11 +79,10 @@ if (!fs.existsSync(testCodePath)) { process.env.VSCODE_USER_DIR = path.join(testDataPath, 'user-dir'); process.env.VSCODE_EXTENSIONS_DIR = extensionsPath; -process.env.SCREENSHOTS_DIR = path.join(testDataPath, 'screenshots'); process.env.SMOKETEST_REPO = testRepoLocalDir; process.env.VSCODE_WORKSPACE_PATH = workspacePath; process.env.VSCODE_KEYBINDINGS_PATH = keybindingsPath; -process.env.CAPTURE_SCREENSHOT = opts.screenshot ? '1' : ''; +process.env.SCREENSHOTS_DIR = opts.screenshots || ''; if (process.env.VSCODE_DEV === '1') { process.env.VSCODE_EDITION = 'dev'; @@ -180,19 +181,6 @@ before(async function () { await setup(); }); -async function teardown(): Promise { - const screenshotsSourcePath = process.env.SCREENSHOTS_DIR; - - if (process.env.CAPTURE_SCREENSHOT && screenshotsSourcePath) { - const screenshotsDestinationPath = path.join(repoPath, '..', 'smoketest-screenshots'); - - rimraf.sync(screenshotsDestinationPath); - await new Promise((c, e) => ncp(screenshotsSourcePath, screenshotsDestinationPath, err => err ? e(err) : c())); - } -} - -after(teardown); - // import './areas/workbench/data-migration.test'; import './areas/workbench/data-loss.test'; import './areas/explorer/explorer.test'; diff --git a/test/smoke/src/spectron/application.ts b/test/smoke/src/spectron/application.ts index 53c5130bb2c..db5b68d0e9f 100644 --- a/test/smoke/src/spectron/application.ts +++ b/test/smoke/src/spectron/application.ts @@ -18,7 +18,6 @@ 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; export const VSCODE_EDITION = process.env.VSCODE_EDITION as string; -export const CAPTURE_SCREENSHOT = !!process.env.CAPTURE_SCREENSHOT; export const SCREENSHOTS_DIR = process.env.SCREENSHOTS_DIR as string; export enum VSCODE_BUILD {