Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Consume vscode 1.1.10 with Insiders build workaround (#231)
* Adapt system tests to also work with Insiders
* Cat log files on failure
* Add some debugging output
* Fail if executable is not available
* Inherit streams from parent process
* More verbose error output
* Update .gitignore
* Add .eslint.json config file
* Fix system tests to locate correct element
  • Loading branch information
guw committed Dec 18, 2017
1 parent f758ec3 commit ee5ac10
Show file tree
Hide file tree
Showing 18 changed files with 225 additions and 122 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,13 @@
{
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"extends": ["prettier"],
"env": {
"es6": true,
"node": true
}
}
8 changes: 7 additions & 1 deletion .gitignore
Expand Up @@ -80,4 +80,10 @@ jspm_packages/
*.key

# SalesforceDX
.sfdx/
.sfdx/

# Project test data
packages/system-tests/project_*

# Node 8 files (not yet used)
package-lock.json
5 changes: 4 additions & 1 deletion .travis.yml
Expand Up @@ -15,7 +15,6 @@ notifications:

matrix:
allow_failures:
- os: linux
- os: osx
fast_finish: true

Expand Down Expand Up @@ -92,3 +91,7 @@ script:

after_script:
- rm $SFDX_CI_KEY_LOCATION

after_failure:
- find ./ -iname '*.log' -type f -print -exec cat '{}' \;
- find /home/travis/.npm/_logs/ -iname '*.log' -type f -print -exec cat '{}' \;
6 changes: 5 additions & 1 deletion package.json
@@ -1,5 +1,7 @@
{
"devDependencies": {
"eslint": "4.13.1",
"eslint-config-prettier": "2.9.0",
"istanbul": "1.1.0-alpha.1",
"lerna": "2.4.0",
"prettier": "1.6.0",
Expand Down Expand Up @@ -29,7 +31,9 @@
"lerna exec -- shx rm -rf node_modules/@types && lerna exec --scope @salesforce/salesforcedx-* -- npm prune --production && lerna run vscode:package --concurrency 1",
"vscode:sha256": "lerna run vscode:sha256 --concurrency 1",
"vscode:publish": "lerna run vscode:publish --concurrency 1",
"watch": "lerna run --parallel watch"
"watch": "lerna run --parallel watch",
"eslint-check":
"eslint --print-config .eslintrc.json | eslint-config-prettier-check"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/salesforcedx-apex-debugger/package.json
Expand Up @@ -33,7 +33,7 @@
"nyc": "^11.0.2",
"sinon": "^2.3.6",
"typescript": "2.4.0",
"vscode": "1.1.5",
"vscode": "1.1.10",
"vscode-debugadapter-testsupport": "1.24.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/salesforcedx-slds-linter/package.json
Expand Up @@ -27,7 +27,7 @@
"sinon": "^2.3.6",
"source-map-support": "^0.4.15",
"typescript": "2.4.0",
"vscode": "1.1.8"
"vscode": "1.1.10"
},
"scripts": {
"vscode:package": "npm prune --production",
Expand Down
2 changes: 1 addition & 1 deletion packages/salesforcedx-vscode-apex-debugger/package.json
Expand Up @@ -33,7 +33,7 @@
"chai": "^4.0.2",
"mocha": "3.2.0",
"sinon": "^2.3.6",
"vscode": "1.1.5"
"vscode": "1.1.10"
},
"extensionDependencies": [
"salesforce.salesforcedx-vscode-apex",
Expand Down
2 changes: 1 addition & 1 deletion packages/salesforcedx-vscode-apex/package.json
Expand Up @@ -33,7 +33,7 @@
"nyc": "^11.0.2",
"shelljs": "^0.7.8",
"typescript": "2.4.0",
"vscode": "1.1.8"
"vscode": "1.1.10"
},
"scripts": {
"vscode:prepublish": "npm prune --production",
Expand Down
2 changes: 1 addition & 1 deletion packages/salesforcedx-vscode-core/package.json
Expand Up @@ -41,7 +41,7 @@
"nyc": "^11.0.2",
"sinon": "^2.3.6",
"typescript": "2.4.0",
"vscode": "1.1.8"
"vscode": "1.1.10"
},
"scripts": {
"vscode:prepublish": "npm prune --production",
Expand Down
2 changes: 1 addition & 1 deletion packages/salesforcedx-vscode-lightning/package.json
Expand Up @@ -35,7 +35,7 @@
"mocha": "3.2.0",
"sinon": "^2.3.6",
"typescript": "2.4.0",
"vscode": "1.1.8"
"vscode": "1.1.10"
},
"scripts": {
"vscode:prepublish": "npm prune --production",
Expand Down
2 changes: 1 addition & 1 deletion packages/salesforcedx-vscode-visualforce/package.json
Expand Up @@ -38,7 +38,7 @@
"chai": "^4.0.2",
"mocha": "3.2.0",
"sinon": "^2.3.6",
"vscode": "1.1.5"
"vscode": "1.1.10"
},
"scripts": {
"vscode:prepublish": "npm prune --production",
Expand Down
4 changes: 3 additions & 1 deletion packages/system-tests/package.json
Expand Up @@ -11,6 +11,7 @@
"devDependencies": {
"@salesforce/salesforcedx-utils-vscode": "41.12.0",
"@types/chai": "^4.0.0",
"@types/mkdirp": "0.5.2",
"@types/mocha": "2.2.38",
"@types/node": "^6.0.40",
"@types/rimraf": "0.0.28",
Expand All @@ -22,14 +23,15 @@
"electron": "^1.7.5",
"glob": "^7.1.2",
"istanbul": "^0.4.5",
"mkdirp": "0.5.1",
"mocha": "3.2.0",
"remap-istanbul": "^0.9.5",
"rimraf": "^2.6.1",
"shelljs": "^0.7.8",
"source-map-support": "^0.4.15",
"spectron": "^3.7.2",
"typescript": "2.4.0",
"vscode": "1.1.8"
"vscode": "1.1.10"
},
"scripts": {
"compile": "tsc -p ./",
Expand Down
59 changes: 27 additions & 32 deletions packages/system-tests/src/helpers/screenshot.ts
Expand Up @@ -8,49 +8,44 @@
*/

import * as fs from 'fs';
import * as mkdirp from 'mkdirp';
import * as path from 'path';
import { SpectronApplication } from '../spectron/application';
import { sanitize } from './utilities';

const TEST_TIME = new Date().toISOString();

export class Screenshot {
private index = 0;
private testPath: string;
private counter = 0;
private screenshotsDirPath: string;

constructor(
private spectron: SpectronApplication,
testName: string,
private testName: string,
testRetry: number
) {
const testTime = this.sanitizeFolderName(TEST_TIME);
testName = this.sanitizeFolderName(testName);

this.testPath = `test_data/screenshots/${testTime}/${testName}/${testRetry}`;
this.createFolder(this.testPath);
}

public async capture(): Promise<any> {
return new Promise(async (res, rej) => {
const image: Electron.NativeImage = await this.spectron.app.browserWindow.capturePage();
fs.writeFile(`${this.testPath}/${this.index}.png`, image, err => {
if (err) {
rej(err);
}
this.index++;
res();
});
});
}

private createFolder(name: string): void {
name.split('/').forEach((folderName, i, fullPath) => {
const folder = fullPath.slice(0, i + 1).join('/');
if (!fs.existsSync(folder)) {
fs.mkdirSync(folder);
}
});
this.screenshotsDirPath = path.join(
'test_data',
'screenshots',
sanitize(TEST_TIME)
);
}

private sanitizeFolderName(name: string): string {
return name.replace(/[&*:\/]/g, '');
public async capture(name?: string): Promise<any> {
const screenshotPath = path.join(
this.screenshotsDirPath,
sanitize(this.testName),
name !== undefined
? `${this.counter++}-${sanitize(name)}.png`
: `${this.counter++}.png`
);

const image = await this.spectron.app.browserWindow.capturePage();
await new Promise((c, e) =>
mkdirp(path.dirname(screenshotPath), err => (err ? e(err) : c()))
);
await new Promise((c, e) =>
fs.writeFile(screenshotPath, image, err => (err ? e(err) : c()))
);
}
}
4 changes: 4 additions & 0 deletions packages/system-tests/src/helpers/utilities.ts
Expand Up @@ -40,3 +40,7 @@ export class Util {
});
}
}

export function sanitize(name: string): string {
return name.replace(/[&*:\/]/g, '');
}
126 changes: 71 additions & 55 deletions packages/system-tests/src/main.ts
Expand Up @@ -12,54 +12,79 @@ import * as child_process from 'child_process';
import * as fs from 'fs';
import * as path from 'path';

const tempFolder = 'test_data';

// VS CODE BINARY LOCATER
/////////////////////////

const testRunFolder = '.vscode-test';
const testRunFolderAbsolute = path.join(process.cwd(), testRunFolder);

const version = process.env.CODE_VERSION || '*';
const isInsiders = version === 'insiders';

let windowsExecutable;
let darwinExecutable;
let linuxExecutable;

const darwinExecutable = path.join(
testRunFolderAbsolute,
'Visual Studio Code.app',
'Contents',
'MacOS',
'Electron'
);
let linuxExecutable = path.join(
testRunFolderAbsolute,
'VSCode-linux-x64',
'code'
);
const windowsExecutable = path.join(testRunFolderAbsolute, 'Code.exe');

if (
[
'0.10.1',
'0.10.2',
'0.10.3',
'0.10.4',
'0.10.5',
'0.10.6',
'0.10.7',
'0.10.8',
'0.10.9'
].indexOf(version) >= 0
) {
if (isInsiders) {
windowsExecutable = path.join(testRunFolderAbsolute, 'Code - Insiders.exe');
darwinExecutable = path.join(
testRunFolderAbsolute,
'Visual Studio Code - Insiders.app',
'Contents',
'MacOS',
'Electron'
);
linuxExecutable = path.join(
testRunFolderAbsolute,
'VSCode-linux-x64',
'Code'
'code-insiders'
);
} else {
windowsExecutable = path.join(testRunFolderAbsolute, 'Code.exe');
darwinExecutable = path.join(
testRunFolderAbsolute,
'Visual Studio Code.app',
'Contents',
'MacOS',
'Electron'
);
linuxExecutable = path.join(
testRunFolderAbsolute,
'VSCode-linux-x64',
'code'
);
if (
[
'0.10.1',
'0.10.2',
'0.10.3',
'0.10.4',
'0.10.5',
'0.10.6',
'0.10.7',
'0.10.8',
'0.10.9'
].indexOf(version) >= 0
) {
linuxExecutable = path.join(
testRunFolderAbsolute,
'VSCode-linux-x64',
'Code'
);
}
}

process.env.VSCODE_BINARY_PATH =
const executable =
process.platform === 'darwin'
? darwinExecutable
: process.platform === 'win32' ? windowsExecutable : linuxExecutable;
process.env.VSCODE_BINARY_PATH = executable;

if (!fs.existsSync(executable) || !fs.statSync(executable).isFile) {
throw new Error(`VS Code executable not found: ${executable}`);
}

console.log(`Using VS Code executable: ${executable}`);

// SPECTRON MOCHA RUNNER
////////////////////////
Expand All @@ -68,36 +93,27 @@ function runTests(): void {
let proc: child_process.ChildProcess;

if (process.env.DEBUG_SPECTRON) {
proc = child_process.spawn(process.execPath, [
'--inspect-brk',
path.join('out', 'src', 'mocha-runner.js')
]);
proc = child_process.spawn(
process.execPath,
['--inspect-brk', path.join('out', 'src', 'mocha-runner.js')],
{ stdio: 'inherit' }
);
} else {
proc = child_process.spawn(process.execPath, [
path.join('out', 'src', 'mocha-runner.js')
]);
proc = child_process.spawn(
process.execPath,
[path.join('out', 'src', 'mocha-runner.js')],
{ stdio: 'inherit' }
);
}

proc.stdout.on('data', data => {
console.log(data.toString());
});
proc.stderr.on('data', data => {
const date = new Date().toLocaleString();
fs.appendFile(
`${tempFolder}/errors.log`,
`${date}: ${data.toString()}`,
err => {
if (err) {
throw new Error(
`Could not write stderr to errors.log with the following error: ${err}`
);
}
}
);
});
proc.on('exit', code => {
console.log(`[mocha-runner] Mocha Runner exited with code ${code}`);
process.exit(code);
});
proc.on('error', err => {
console.log(`[mocha-runner] Error running Mocha Runner: ${err}`);
throw new Error(`Error running Mocha Runner: ${err}`);
});
}

// MAIN
Expand Down

0 comments on commit ee5ac10

Please sign in to comment.