diff --git a/src/vs/code/electron-main/windows.ts b/src/vs/code/electron-main/windows.ts index b53d7843d5d..17f00c6fac5 100644 --- a/src/vs/code/electron-main/windows.ts +++ b/src/vs/code/electron-main/windows.ts @@ -410,7 +410,8 @@ export class WindowsManager implements IWindowsMainService { // Handle files to open/diff or to create when we dont open a folder and we do not restore any folder/untitled from hot-exit const usedWindows: CodeWindow[] = []; - if (!foldersToOpen.length && !foldersToRestore.length && !emptyToRestore.length && (filesToOpen.length > 0 || filesToCreate.length > 0 || filesToDiff.length > 0)) { + const potentialWindowsCount = foldersToOpen.length + foldersToRestore.length + workspacesToOpen.length + workspacesToRestore.length + emptyToRestore.length; + if (potentialWindowsCount === 0 && (filesToOpen.length > 0 || filesToCreate.length > 0 || filesToDiff.length > 0)) { // Find suitable window or folder path to open files in const fileToCheck = filesToOpen[0] || filesToCreate[0] || filesToDiff[0]; diff --git a/test/smoke/README.md b/test/smoke/README.md index 0950d9e5c58..85437ac633d 100644 --- a/test/smoke/README.md +++ b/test/smoke/README.md @@ -3,7 +3,7 @@ - Run `npm install` - Start the tests: `npm test -- --latest "path/to/binary"`. -If you want to include 'Data Migration' area tests use `npm test -- --latest path/to/binary --stable path/to/currentStable` respectively. +If you want to include 'Data Migration' area tests use `npm test -- --latest path/to/binary --stable path/to/currentStable` respectively. Detailed prerequisites and running steps are described [in our smoke test wiki](https://github.com/Microsoft/vscode/wiki/Smoke-Test#automated-smoke-test). @@ -48,3 +48,15 @@ To add new test, `./test/${area}.ts` should be updated. The same instruction-sty # Screenshots Almost on every automated test action it captures a screenshot. These help to determine an issue, if smoke test fails. The normal workflow is that you understand what code is doing and then try to match it up with screenshots obtained from the test. + +# Running "Out of Sources" +If you did a fix in VS Code that you need in order for the smoke test to succeed, here is how you can run the smoke test against the sources of VS Code: +* Set related environment variables in the console: + * `export NODE_ENV=development` + * `export VSCODE_DEV=1` + * `export VSCODE_CLI=1` +* open `application.ts` + * pass in the vscode folder as argument to the application + * e.g. instead of `args: args` type `args: ['/Users/bpasero/Development/vscode', ...args]` +* run `npm test -- --latest ` + * e.g. on macOS: `npm test -- --latest /.build/electron/Code\ -\ OSS.app/Contents/MacOS/Electron` \ No newline at end of file diff --git a/test/smoke/src/main.ts b/test/smoke/src/main.ts index 79bd1aff9b9..214713f213d 100644 --- a/test/smoke/src/main.ts +++ b/test/smoke/src/main.ts @@ -11,6 +11,7 @@ const child_process = require('child_process'); const path = require('path'); const tempFolder = 'test_data'; +const codeWorkspace = path.join(process.cwd(), tempFolder, 'smoketest.code-workspace'); const testRepoUrl = 'https://github.com/Microsoft/vscode-smoketest-express'; const testRepoLocalDir = path.join(process.cwd(), `${tempFolder}/vscode-smoketest-express`); const keybindingsUrl = 'https://raw.githubusercontent.com/Microsoft/vscode-docs/master/scripts/keybindings'; @@ -50,6 +51,7 @@ process.env.SMOKETEST_REPO = testRepoLocalDir; if (program.stable && program.stable.toLowerCase().startsWith('insiders')) { process.env.VSCODE_EDITION = 'insiders'; } +process.env.VSCODE_WORKSPACE_PATH = codeWorkspace; // Setting up 'vscode-smoketest-express' project let os = process.platform.toString(); @@ -63,6 +65,11 @@ else if (os === 'win32') { var promises: Promise[] = []; promises.push(getKeybindings(`${keybindingsUrl}/doc.keybindings.${os}.json`, `${tempFolder}/keybindings.json`)); +promises.push(createWorkspaceFile(codeWorkspace, [ + toUri(path.join(testRepoLocalDir, 'public')), + toUri(path.join(testRepoLocalDir, 'routes')), + toUri(path.join(testRepoLocalDir, 'views')) +])); promises.push(cleanOrClone(testRepoUrl, testRepoLocalDir)); Promise.all(promises) @@ -77,6 +84,14 @@ function fail(errorMessage): void { process.exit(1); } +function toUri(path: string): string { + if (os === 'win') { + return `file:///${path.replace(/\\/g, '/')}`; + } + + return `file://${path}`; +} + function runTests(): void { console.log('Running tests...'); var proc = child_process.spawn(process.execPath, [ @@ -183,6 +198,30 @@ function getKeybindings(url: string, location: string): Promise { }); } +function createWorkspaceFile(path: string, folders: string[]): Promise { + console.log(`Creating workspace file at ${path}...`); + return new Promise((resolve, reject) => { + fs.exists(path, exists => { + if (exists) { + return resolve(); + } + + const workspace = { + id: (Date.now() + Math.round(Math.random() * 1000)).toString(), + folders + }; + + fs.writeFile(path, JSON.stringify(workspace, null, '\t'), error => { + if (error) { + reject(error); + } else { + resolve(); + } + }); + }); + }); +} + function folderExists(folder: string): boolean { try { fs.accessSync(folder, 'rw'); diff --git a/test/smoke/src/spectron/application.ts b/test/smoke/src/spectron/application.ts index e94ccb5a10f..2e67dded6c4 100644 --- a/test/smoke/src/spectron/application.ts +++ b/test/smoke/src/spectron/application.ts @@ -12,6 +12,7 @@ var path = require('path'); export const LATEST_PATH = process.env.VSCODE_LATEST_PATH; 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 = 'test_data/temp_user_dir'; export const EXTENSIONS_DIR = 'test_data/temp_extensions_dir'; diff --git a/test/smoke/src/test.ts b/test/smoke/src/test.ts index 998616c0297..0febbce1012 100644 --- a/test/smoke/src/test.ts +++ b/test/smoke/src/test.ts @@ -17,6 +17,7 @@ import { testStatusbar } from "./tests/statusbar"; import { testTasks } from "./tests/tasks"; import { testExtensions } from "./tests/extensions"; import { testLocalization } from "./tests/localization"; +import { testMultiRoot } from "./tests/multiroot"; describe('Smoke Test Suite', () => { testDataMigration(); @@ -33,4 +34,5 @@ describe('Smoke Test Suite', () => { testTasks(); testExtensions(); testLocalization(); + testMultiRoot(); }); \ No newline at end of file diff --git a/test/smoke/src/tests/multiroot.ts b/test/smoke/src/tests/multiroot.ts new file mode 100644 index 00000000000..b5aaf175978 --- /dev/null +++ b/test/smoke/src/tests/multiroot.ts @@ -0,0 +1,42 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as assert from 'assert'; + +import { SpectronApplication, LATEST_PATH, CODE_WORKSPACE_PATH } from "../spectron/application"; +import { CommonActions } from '../areas/common'; + +let app: SpectronApplication; +let common: CommonActions; + +export function testMultiRoot() { + context('Multi Root', () => { + + beforeEach(async function () { + app = new SpectronApplication(LATEST_PATH, this.currentTest.fullTitle(), (this.currentTest as any).currentRetry(), [CODE_WORKSPACE_PATH]); + common = new CommonActions(app); + + return await app.start(); + }); + + afterEach(async function () { + return await app.stop(); + }); + + it('shows results from all folders', async function () { + await common.openQuickOpen(); + await common.type('*.*'); + await app.wait(); + const elCount = await common.getQuickOpenElements(); + assert.equal(elCount, 6); + }); + + it('shows workspace name in title', async function () { + await app.wait(); + const title = await common.getWindowTitle(); + assert.ok(title.indexOf('smoketest (Workspace)') >= 0); + }); + }); +} \ No newline at end of file