Skip to content

Commit

Permalink
link provider test
Browse files Browse the repository at this point in the history
  • Loading branch information
b-vadym committed Jan 16, 2022
1 parent f6d959f commit 683f024
Show file tree
Hide file tree
Showing 28 changed files with 3,439 additions and 52 deletions.
69 changes: 35 additions & 34 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"args": [
"${workspaceFolder}/test-fixtures/test-workspace",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
18 changes: 15 additions & 3 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';

import { runTests } from '@vscode/test-electron';
import * as cp from 'child_process';
import { downloadAndUnzipVSCode, resolveCliPathFromVSCodeExecutablePath, runTests } from '@vscode/test-electron';

async function main() {
try {
Expand All @@ -11,9 +11,21 @@ async function main() {
// The path to test runner
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');
const testWorkspace = path.resolve(__dirname, '../../test-fixtures/test-workspace');
const vscodeExecutablePath = await downloadAndUnzipVSCode('insiders');
const cliPath = resolveCliPathFromVSCodeExecutablePath(vscodeExecutablePath);

// Use cp.spawn / cp.exec for custom setup
cp.spawnSync(cliPath, ['--install-extension', 'bmewburn.vscode-intelephense-client'], {
encoding: 'utf-8',
stdio: 'inherit'
});
// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
await runTests({
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: [testWorkspace]
});
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
Expand Down
15 changes: 0 additions & 15 deletions src/test/suite/extension.test.ts

This file was deleted.

68 changes: 68 additions & 0 deletions src/test/suite/linkProvider.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import * as assert from 'assert';
import { before } from 'mocha';
import { setTimeout } from 'timers';

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
// import * as myExtension from '../../extension';

suite('Link Orivider Test Suite', function () {
this.timeout(5500);

// before(function (done) {
// setTimeout(done, 5000);
// });

test('Has link in php code', async () => {
const document = await getFileByName('src/Controller/HomePageController.php');
const documentLinks = await vscode.commands.executeCommand<vscode.DocumentLink[]>(
'vscode.executeLinkProvider',
document.uri,
);

assert.strictEqual(1, documentLinks.length);
const link = documentLinks[0];
assert.strictEqual(getWorkspaceFolder() + '/templates/homepage.html.twig', link.target?.path);
assert.deepStrictEqual(new vscode.Range(
new vscode.Position(15, 30),
new vscode.Position(15, 48)
), link.range);
});

test('Has link in twig code', async () => {
const document = await getFileByName('templates/homepage.html.twig');
const documentLinks = await vscode.commands.executeCommand<vscode.DocumentLink[]>(
'vscode.executeLinkProvider',
document.uri,
);

assert.strictEqual(1, documentLinks.length);
const link = documentLinks[0];
assert.strictEqual(getWorkspaceFolder() + '/templates/base.html.twig', link.target?.path);
assert.deepStrictEqual(new vscode.Range(
new vscode.Position(0, 12),
new vscode.Position(0, 26)
), link.range);
});
});

async function getFileByName(name: string): Promise<vscode.TextDocument> {
const files = await vscode.workspace.findFiles(name);

if (files.length === 0) {
throw new Error(`File ${name} not found`);
}

return vscode.workspace.openTextDocument(files[0]);
}

function getWorkspaceFolder(): string {
const folders = vscode.workspace.workspaceFolders;

if (!folders || folders.length === 0) {
throw new Error('Workspace folder is not defined');
}

return folders[0].uri.path;
}
4 changes: 4 additions & 0 deletions test-fixtures/test-workspace/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=03df627eabb2e845350840322b0ee29e
###< symfony/framework-bundle ###
10 changes: 10 additions & 0 deletions test-fixtures/test-workspace/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###
47 changes: 47 additions & 0 deletions test-fixtures/test-workspace/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
DOCKER_COMPOSE = docker-compose
EXEC_PHP = $(DOCKER_COMPOSE) exec php
SYMFONY = $(EXEC_PHP) bin/console
COMPOSER = $(EXEC_PHP) composer
##
## Project main
## -----------------------
.PHONY: up
up: ## docker compose up
$(DOCKER_COMPOSE) up --remove-orphans --no-recreate --detach --build

.PHONY: down
down: ## Down docker compose
$(DOCKER_COMPOSE) kill
$(DOCKER_COMPOSE) down --remove-orphans

.PHONY: clear-cache
clear-cache: ## Remove symfony cache and logs
rm -rf var/logs var/cache

.PHONY: cache-warmup
cache-warmup: clear-cache vendor ## Symfony cache warmup
$(SYMFONY) cache:warmup

.PHONY: rebuild
rebuild: vendor clear-cache cache-warmup ## Rebuild project

vendor: composer.lock ## Install vendor
$(COMPOSER) install
touch vendor

##
## run shell
## -----------------------
.PHONY: bash-php
bash-php: ## bash in php container
$(EXEC_PHP) bash

##
## help
## -----------------------

.PHONY: help
help: ## Outputs this help screen
@grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-24s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m## /[33m/' && printf "\n"

.DEFAULT_GOAL := help
17 changes: 17 additions & 0 deletions test-fixtures/test-workspace/bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env php
<?php

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;

if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

return new Application($kernel);
};
69 changes: 69 additions & 0 deletions test-fixtures/test-workspace/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=8.0.2",
"ext-ctype": "*",
"ext-iconv": "*",
"symfony/console": "6.0.*",
"symfony/dotenv": "6.0.*",
"symfony/flex": "^2",
"symfony/framework-bundle": "6.0.*",
"symfony/runtime": "6.0.*",
"symfony/twig-bundle": "6.0.*",
"symfony/yaml": "6.0.*"
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true,
"symfony/flex": true,
"symfony/runtime": true
},
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*",
"symfony/polyfill-php73": "*",
"symfony/polyfill-php74": "*",
"symfony/polyfill-php80": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "6.0.*"
}
}
}
Loading

0 comments on commit 683f024

Please sign in to comment.