Skip to content

Add jest-runner #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
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
78 changes: 50 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,30 @@

This module helps you test VS Code extensions.

Supported:
## Table of contents

- [Installation](#installation)
- [Supported](#supported)
- [Usage](#usage)
- [`jest-runner` usage](https://github.com/microsoft/vscode-test/blob/master/jest-runner)
- [License](#license)
- [Contributing](#contributing)

## Installation

### npm

```sh
npm install vscode-test --save-dev
```

### yarn

```sh
yarn add vscode-test jest --dev
```

## Supported

- Node >= 12.x
- Windows >= Windows Server 2012+ / Win10+ (anything with Powershell >= 5.0)
Expand All @@ -18,28 +41,28 @@ See [./sample](./sample) for a runnable sample, with [Azure DevOps Pipelines](ht
```ts
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 @@ -48,8 +71,8 @@ async function go() {
version: '1.36.1',
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [testWorkspace]
})
launchArgs: [testWorkspace],
});

/**
* Use Insiders release for testing
Expand All @@ -58,33 +81,33 @@ 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 cliPath = resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath)
const cliPath = resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath);
cp.spawnSync(cliPath, ['--install-extension', 'ms-python.python'], {
encoding: 'utf-8',
stdio: 'inherit'
})
stdio: 'inherit',
});

/**
* - Add additional launch flags for VS Code
Expand All @@ -97,11 +120,11 @@ async function go() {
launchArgs: [
testWorkspace,
// This disables all extensions except the one being testing
'--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 @@ -111,17 +134,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
27 changes: 24 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,49 @@
"compile": "tsc -p ./",
"watch": "tsc -w -p ./",
"prepublish": "tsc -p ./",
"test": "eslint lib --ext ts && tsc --noEmit"
"test": "eslint lib --ext ts && tsc --noEmit && jest"
},
"bin": {
"code-jest": "./out/code-jest.js"
},
"main": "./out/index.js",
"engines": {
"node": ">=8.9.3"
"node": ">=12"
},
"dependencies": {
"http-proxy-agent": "^4.0.1",
"https-proxy-agent": "^5.0.0",
"rimraf": "^3.0.2",
"jest-environment-vscode": "^1.0.0",
"unzipper": "^0.10.11"
},
"optionalDependencies": {
"jest-cli": "^26.6.3"
},
"devDependencies": {
"jest-cli": "^26.6.3",
"@jest/test-result": "^26.6.2",
"@types/jest": "^26.0.20",
"@types/node": "^12",
"@types/rimraf": "^3.0.0",
"@types/unzipper": "^0.10.3",
"@typescript-eslint/eslint-plugin": "^4.13.0",
"@typescript-eslint/parser": "^4.13.0",
"eslint": "^7.17.0",
"eslint-plugin-header": "^3.1.0",
"eslint": "^7.17.0",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"ts-jest": "^26.5.0",
"typescript": "^4.1.3"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"testPathIgnorePatterns": [
"out",
"sample"
]
},
"license": "MIT",
"author": "Visual Studio Code Team",
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions sample/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ steps:

- task: NodeTool@0
inputs:
versionSpec: '8.x'
versionSpec: '10.x'
displayName: 'Install Node.js'

- bash: |
Expand All @@ -29,8 +29,8 @@ steps:
condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux'))

- bash: |
echo ">>> Compile vscode-test"
yarn && yarn compile
echo ">>> Compile vscode-test and run tests"
yarn && yarn compile && yarn test --ci
echo ">>> Compiled vscode-test"
cd sample
echo ">>> Run sample integration test"
Expand Down
58 changes: 58 additions & 0 deletions src/code-jest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env node

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

/* https://github.com/Stuk/eslint-plugin-header/issues/31 */
/* eslint-disable header/header */

import { resolve } from 'path';
import { runTests } from '.';

const run = async () => {
if (process.argv.includes('--help') || process.argv.includes('-h')) {
printHelp();
return 0;
}

try {
require.resolve('@jest/core');
} catch (e) {
printMissingDependency();
return 0;
}

process.env.JEST_ARGS = JSON.stringify(process.argv.slice(2));

await runTests({
extensionDevelopmentPath: process.cwd(),
extensionTestsPath: resolve(__dirname, 'jest'),
});

return 0;
}

const printMissingDependency = () => {
console.error('You need to install `jest-cli` to use `code-jest`.')
console.error('');
console.error('Run `npm install --save-dev jest-cli` or `yarn add --dev jest-cli` to do so.');
};

const printHelp = () => {
console.error(`code-jest is a command line to run vscode tests with Jest`)
console.error('');
console.error('Usage: code-jest [args...]')
console.error('');
console.error('Additional arguments will be passed to the Jest command line');
};

if (require.main === module) {
run()
.then(code => process.exit(code))
.catch(e => {
console.error(e);
process.exit(1);
});
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 2 additions & 7 deletions lib/runTest.ts → src/core/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,8 @@ async function innerRunTests(
const fullEnv = Object.assign({}, process.env, testRunnerEnv);
const cmd = cp.spawn(executable, args, { env: fullEnv });

cmd.stdout.on('data', function (data) {
console.log(data.toString());
});

cmd.stderr.on('data', function (data) {
console.error(data.toString());
});
cmd.stdout.pipe(process.stdout);
cmd.stderr.pipe(process.stderr);

cmd.on('error', function (data) {
console.log('Test error: ' + data.toString());
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

export * from './core/runTest';
46 changes: 46 additions & 0 deletions src/jest/debug-console/colorize.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { bold, black, red, green, yellow, purple, redBg, greenBg, darkGray, white } from './colorize';

test('adds bold formatting to text', () => {
expect(bold('text')).toMatchInlineSnapshot(`"text"`);
});

test('adds black formatting to text', () => {
expect(black('text')).toMatchInlineSnapshot(`"text"`);
});

test('adds red formatting to text', () => {
expect(red('text')).toMatchInlineSnapshot(`"text"`);
});

test('adds green formatting to text', () => {
expect(green('text')).toMatchInlineSnapshot(`"text"`);
});

test('adds yellow formatting to text', () => {
expect(yellow('text')).toMatchInlineSnapshot(`"text"`);
});

test('adds purple formatting to text', () => {
expect(purple('text')).toMatchInlineSnapshot(`"text"`);
});

test('adds redBg formatting to text', () => {
expect(redBg('text')).toMatchInlineSnapshot(`"text"`);
});

test('adds greenBg formatting to text', () => {
expect(greenBg('text')).toMatchInlineSnapshot(`"text"`);
});

test('adds darkGray formatting to text', () => {
expect(darkGray('text')).toMatchInlineSnapshot(`"text"`);
});

test('adds white formatting to text', () => {
expect(white('text')).toMatchInlineSnapshot(`"text"`);
});
19 changes: 19 additions & 0 deletions src/jest/debug-console/colorize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

function colorize(colorCode: string) {
return (text: string): string => `\u001B[${colorCode}m${text}\u001B[0m`;
}

export const bold = colorize('1');
export const black = colorize('30');
export const red = colorize('31');
export const green = colorize('32');
export const yellow = colorize('33');
export const purple = colorize('35');
export const redBg = colorize('41');
export const greenBg = colorize('42');
export const darkGray = colorize('90');
export const white = colorize('97');
Loading