Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint-staged
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint"
]
}
18 changes: 10 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Place your settings in this file to overwrite default and user settings.
{
"editor.insertSpaces": true,
"editor.insertSpaces": true,
"files.eol": "\n",
"files.trimTrailingWhitespace": true,
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/*.js": {
"when": "$(basename).ts"
}
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/*.js": {
"when": "$(basename).ts"
}
},
"githubIssues.queries":[
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"githubIssues.queries": [
{
"label": "Recent Issues",
"query": "state:open repo:${owner}/${repository} sort:updated-desc"
Expand Down
18 changes: 9 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
### 1.1.0 | 2019-08-02

- Add `resolveCliPathFromVSCodeExecutablePath` that would resolve `vscodeExecutablePath` to VS Code CLI path, which can be used
for extension management features such as `--install-extension` and `--uninstall-extension`. [#31](https://github.com/microsoft/vscode-test/issues/31).
for extension management features such as `--install-extension` and `--uninstall-extension`. [#31](https://github.com/microsoft/vscode-test/issues/31).

### 1.0.2 | 2019-07-17

Expand All @@ -144,13 +144,13 @@ for extension management features such as `--install-extension` and `--uninstall
### 1.0.0-next.0 | 2019-06-24

- Updated API:
- One single set of options.
- `extensionPath` => `extensionDevelopmentPath` to align with VS Code launch flags
- `testRunnerPath` => `extensionTestsPath` to align with VS Code launch flags
- `testRunnerEnv` => `extensionTestsEnv` to align with VS Code launch flags
- `additionalLaunchArgs` => `launchArgs`
- `testWorkspace` removed. Pass path to file/folder/workspace as first argument to `launchArgs` instead.
- `locale` removed. Pass `--locale` to `launchArgs` instead.
- One single set of options.
- `extensionPath` => `extensionDevelopmentPath` to align with VS Code launch flags
- `testRunnerPath` => `extensionTestsPath` to align with VS Code launch flags
- `testRunnerEnv` => `extensionTestsEnv` to align with VS Code launch flags
- `additionalLaunchArgs` => `launchArgs`
- `testWorkspace` removed. Pass path to file/folder/workspace as first argument to `launchArgs` instead.
- `locale` removed. Pass `--locale` to `launchArgs` instead.

### 0.4.3 | 2019-05-30

Expand All @@ -163,7 +163,7 @@ for extension management features such as `--install-extension` and `--uninstall
### 0.4.1 | 2019-05-02

- Fix Linux crash because `testRunnerEnv` is not merged with `process.env` for spawning the
testing process. [#14](https://github.com/Microsoft/vscode-test/issues/14c).
testing process. [#14](https://github.com/Microsoft/vscode-test/issues/14c).

### 0.4.0 | 2019-04-18

Expand Down
49 changes: 24 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@ import { runTests } from '@vscode/test-electron';

async function go() {
try {
const extensionDevelopmentPath = path.resolve(__dirname, '../../../')
const extensionTestsPath = path.resolve(__dirname, './suite')
const extensionDevelopmentPath = path.resolve(__dirname, '../../../');
const extensionTestsPath = path.resolve(__dirname, './suite');

/**
* Basic usage
*/
await runTests({
extensionDevelopmentPath,
extensionTestsPath
})
extensionTestsPath,
});

const extensionTestsPath2 = path.resolve(__dirname, './suite2')
const testWorkspace = path.resolve(__dirname, '../../../test-fixtures/fixture1')
const extensionTestsPath2 = path.resolve(__dirname, './suite2');
const testWorkspace = path.resolve(__dirname, '../../../test-fixtures/fixture1');

/**
* Running another test suite on a specific workspace
*/
await runTests({
extensionDevelopmentPath,
extensionTestsPath: extensionTestsPath2,
launchArgs: [testWorkspace]
})
launchArgs: [testWorkspace],
});

/**
* Use 1.36.1 release for testing
Expand All @@ -50,8 +50,8 @@ async function go() {
version: '1.36.1',
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [testWorkspace]
})
launchArgs: [testWorkspace],
});

/**
* Use Insiders release for testing
Expand All @@ -60,32 +60,32 @@ async function go() {
version: 'insiders',
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [testWorkspace]
})
launchArgs: [testWorkspace],
});

/**
* Noop, since 1.36.1 already downloaded to .vscode-test/vscode-1.36.1
*/
await downloadAndUnzipVSCode('1.36.1')
await downloadAndUnzipVSCode('1.36.1');

/**
* Manually download VS Code 1.35.0 release for testing.
*/
const vscodeExecutablePath = await downloadAndUnzipVSCode('1.35.0')
const vscodeExecutablePath = await downloadAndUnzipVSCode('1.35.0');
await runTests({
vscodeExecutablePath,
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [testWorkspace]
})
launchArgs: [testWorkspace],
});

/**
* Install Python extension
*/
const [cli, ...args] = resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);
cp.spawnSync(cli, [...args, '--install-extension', 'ms-python.python'], {
encoding: 'utf-8',
stdio: 'inherit'
stdio: 'inherit',
});

/**
Expand All @@ -99,11 +99,11 @@ async function go() {
launchArgs: [
testWorkspace,
// This disables all extensions except the one being tested
'--disable-extensions'
'--disable-extensions',
],
// Custom environment variables for extension test script
extensionTestsEnv: { foo: 'bar' }
})
extensionTestsEnv: { foo: 'bar' },
});

/**
* Use win64 instead of win32 for testing Windows
Expand All @@ -113,17 +113,16 @@ async function go() {
extensionDevelopmentPath,
extensionTestsPath,
version: '1.40.0',
platform: 'win32-x64-archive'
platform: 'win32-x64-archive',
});
}

} catch (err) {
console.error('Failed to run tests')
process.exit(1)
console.error('Failed to run tests');
process.exit(1);
}
}

go()
go();
```

## Development
Expand Down
18 changes: 9 additions & 9 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ If you believe you have found a security vulnerability in any Microsoft-owned re

Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).

If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).

You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).

Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:

* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue
- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
- Full paths of source file(s) related to the manifestation of the issue
- The location of the affected source code (tag/branch/commit or direct URL)
- Any special configuration required to reproduce the issue
- Step-by-step instructions to reproduce the issue
- Proof-of-concept or exploit code (if possible)
- Impact of the issue, including how an attacker might exploit the issue

This information will help us triage your report more quickly.

Expand Down
19 changes: 0 additions & 19 deletions lib/del.ts

This file was deleted.

101 changes: 95 additions & 6 deletions lib/download.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import { spawnSync } from 'child_process';
import { existsSync, promises as fs } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
import { downloadAndUnzipVSCode } from './download';
import { dirname, join } from 'path';
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';
import {
downloadAndUnzipVSCode,
fetchInsiderVersions,
fetchStableVersions,
fetchTargetInferredVersion,
} from './download';
import { SilentReporter } from './progress';
import { resolveCliPathFromVSCodeExecutablePath, systemDefaultPlatform } from './util';

const platforms = ['darwin', 'darwin-arm64', 'win32-archive', 'win32-x64-archive', 'linux-x64', 'linux-arm64', 'linux-armhf'];
const platforms = [
'darwin',
'darwin-arm64',
'win32-archive',
'win32-x64-archive',
'linux-x64',
'linux-arm64',
'linux-armhf',
];

describe('sane downloads', () => {
const testTempDir = join(tmpdir(), 'vscode-test-download');

beforeAll(async () => {
await fs.mkdir(testTempDir, { recursive: true })
await fs.mkdir(testTempDir, { recursive: true });
});

for (const platform of platforms) {
Expand All @@ -39,7 +52,7 @@ describe('sane downloads', () => {
expect(version.status).to.equal(0);
expect(version.stdout.toString().trim()).to.not.be.empty;
}
})
});
}

afterAll(async () => {
Expand All @@ -50,3 +63,79 @@ describe('sane downloads', () => {
}
});
});

describe('fetchTargetInferredVersion', () => {
let stable: string[];
let insiders: string[];
let extensionsDevelopmentPath = join(tmpdir(), 'vscode-test-tmp-workspace');

beforeAll(async () => {
[stable, insiders] = await Promise.all([fetchStableVersions(5000), fetchInsiderVersions(5000)]);
});

afterEach(async () => {
await fs.rm(extensionsDevelopmentPath, { recursive: true, force: true });
});

const writeJSON = async (path: string, contents: object) => {
const target = join(extensionsDevelopmentPath, path);
await fs.mkdir(dirname(target), { recursive: true });
await fs.writeFile(target, JSON.stringify(contents));
};

const doFetch = (paths = ['./']) =>
fetchTargetInferredVersion({
cachePath: join(extensionsDevelopmentPath, '.cache'),
platform: 'win32-archive',
timeout: 5000,
extensionsDevelopmentPath: paths.map((p) => join(extensionsDevelopmentPath, p)),
});

test('matches stable if no workspace', async () => {
const version = await doFetch();
expect(version).to.equal(stable[0]);
});

test('matches stable by default', async () => {
await writeJSON('package.json', {});
const version = await doFetch();
expect(version).to.equal(stable[0]);
});

test('matches if stable is defined', async () => {
await writeJSON('package.json', { engines: { vscode: '^1.50.0' } });
const version = await doFetch();
expect(version).to.equal(stable[0]);
});

test('matches best', async () => {
await writeJSON('package.json', { engines: { vscode: '<=1.60.5' } });
const version = await doFetch();
expect(version).to.equal('1.60.2');
});

test('matches multiple workspaces', async () => {
await writeJSON('a/package.json', { engines: { vscode: '<=1.60.5' } });
await writeJSON('b/package.json', { engines: { vscode: '<=1.55.5' } });
const version = await doFetch(['a', 'b']);
expect(version).to.equal('1.55.2');
});

test('matches insiders to better stable if there is one', async () => {
await writeJSON('package.json', { engines: { vscode: '^1.60.0-insider' } });
const version = await doFetch();
expect(version).to.equal(stable[0]);
});

test('matches current insiders', async () => {
await writeJSON('package.json', { engines: { vscode: `^${insiders[0]}` } });
const version = await doFetch();
expect(version).to.equal(insiders[0]);
});

test('matches insiders to exact', async () => {
await writeJSON('package.json', { engines: { vscode: '1.60.0-insider' } });
const version = await doFetch();
expect(version).to.equal('1.60.0-insider');
});
});
Loading