Skip to content

Commit

Permalink
chore: adopt prettier and eslint hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Feb 27, 2023
1 parent 121fe1f commit d9b458c
Show file tree
Hide file tree
Showing 14 changed files with 538 additions and 121 deletions.
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.

2 changes: 1 addition & 1 deletion lib/download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('fetchTargetInferredVersion', () => {
cachePath: join(extensionsDevelopmentPath, '.cache'),
platform: 'win32-archive',
timeout: 5000,
extensionsDevelopmentPath: paths.map(p => join(extensionsDevelopmentPath, p)),
extensionsDevelopmentPath: paths.map((p) => join(extensionsDevelopmentPath, p)),
});

test('matches stable if no workspace', async () => {
Expand Down
35 changes: 28 additions & 7 deletions lib/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { tmpdir } from 'os';
import * as path from 'path';
import { pipeline, Readable } from 'stream';
import { promisify } from 'util';
import * as del from './del';
import { ConsoleReporter, ProgressReporter, ProgressReportStage } from './progress';
import * as request from './request';
import * as semver from 'semver';
Expand Down Expand Up @@ -101,7 +100,8 @@ export async function fetchTargetInferredVersion(options: IFetchInferredOptions)
return found2;
}

console.warn(`No version of VS Code satisfies all extension engine constraints (${extVersions.join(', ')}). Falling back to stable.`);
const v = extVersions.join(', ');
console.warn(`No version of VS Code satisfies all extension engine constraints (${v}). Falling back to stable.`);

return stable[0]; // 🤷
} catch (e) {
Expand Down Expand Up @@ -215,18 +215,33 @@ async function downloadVSCodeArchive(options: DownloadOptions) {
const isZip = contentType ? contentType === 'application/zip' : url.endsWith('.zip');

const timeoutCtrl = new request.TimeoutController(timeout);
options.reporter?.report({ stage: ProgressReportStage.Downloading, url, bytesSoFar: 0, totalBytes });
options.reporter?.report({
stage: ProgressReportStage.Downloading,
url,
bytesSoFar: 0,
totalBytes,
});

let bytesSoFar = 0;
download.on('data', (chunk) => {
bytesSoFar += chunk.length;
timeoutCtrl.touch();
options.reporter?.report({ stage: ProgressReportStage.Downloading, url, bytesSoFar, totalBytes });
options.reporter?.report({
stage: ProgressReportStage.Downloading,
url,
bytesSoFar,
totalBytes,
});
});

download.on('end', () => {
timeoutCtrl.dispose();
options.reporter?.report({ stage: ProgressReportStage.Downloading, url, bytesSoFar: totalBytes, totalBytes });
options.reporter?.report({
stage: ProgressReportStage.Downloading,
url,
bytesSoFar: totalBytes,
totalBytes,
});
});

timeoutCtrl.signal.addEventListener('abort', () => {
Expand Down Expand Up @@ -375,7 +390,7 @@ export async function download(options: Partial<DownloadOptions> = {}): Promise<
newDate: new Date(latestTimestamp),
newHash: latestHash,
});
await del.rmdir(downloadedPath);
await fs.promises.rm(downloadedPath, { force: true, recursive: true });
} catch (err) {
reporter.error(err);
throw Error(`Failed to remove outdated Insiders at ${downloadedPath}.`);
Expand All @@ -397,7 +412,13 @@ export async function download(options: Partial<DownloadOptions> = {}): Promise<
const downloadStaging = `${downloadedPath}.tmp`;
await fs.promises.rm(downloadStaging, { recursive: true, force: true });

const { stream, format } = await downloadVSCodeArchive({ version, platform, cachePath, reporter, timeout });
const { stream, format } = await downloadVSCodeArchive({
version,
platform,
cachePath,
reporter,
timeout,
});
// important! do not put anything async here, since unzipVSCode will need
// to start consuming the stream immediately.
await unzipVSCode(reporter, downloadStaging, extractSync, stream, format);
Expand Down
Loading

0 comments on commit d9b458c

Please sign in to comment.