mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-28 12:33:35 +01:00
Theme tests as extension test
This commit is contained in:
2
extensions/vscode-colorize-tests/.gitignore
vendored
Normal file
2
extensions/vscode-colorize-tests/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
out
|
||||
node_modules
|
||||
17
extensions/vscode-colorize-tests/.vscode/launch.json
vendored
Normal file
17
extensions/vscode-colorize-tests/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
// A launch configuration that compiles the extension and then opens it inside a new window
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch Tests",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": ["${workspaceRoot}/../../", "${workspaceRoot}/test", "--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out" ],
|
||||
"stopOnEntry": false,
|
||||
"sourceMaps": true,
|
||||
"outDir": "${workspaceRoot}/out",
|
||||
"preLaunchTask": "npm"
|
||||
}
|
||||
]
|
||||
}
|
||||
30
extensions/vscode-colorize-tests/.vscode/tasks.json
vendored
Normal file
30
extensions/vscode-colorize-tests/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
// Available variables which can be used inside of strings.
|
||||
// ${workspaceRoot}: the root folder of the team
|
||||
// ${file}: the current opened file
|
||||
// ${fileBasename}: the current opened file's basename
|
||||
// ${fileDirname}: the current opened file's dirname
|
||||
// ${fileExtname}: the current opened file's extension
|
||||
// ${cwd}: the current working directory of the spawned process
|
||||
|
||||
// A task runner that calls a custom npm script that compiles the extension.
|
||||
{
|
||||
"version": "0.1.0",
|
||||
|
||||
// we want to run npm
|
||||
"command": "npm",
|
||||
|
||||
// the command is a shell script
|
||||
"isShellCommand": true,
|
||||
|
||||
// show the output window only if unrecognized errors occur.
|
||||
"showOutput": "silent",
|
||||
|
||||
// we run the custom script "compile" as defined in package.json
|
||||
"args": ["run", "compile", "--loglevel", "silent"],
|
||||
|
||||
// The tsc compiler is started in watching mode
|
||||
"isWatching": true,
|
||||
|
||||
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
|
||||
"problemMatcher": "$tsc-watch"
|
||||
}
|
||||
19
extensions/vscode-colorize-tests/package.json
Normal file
19
extensions/vscode-colorize-tests/package.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "vscode-colorize-tests",
|
||||
"description": "Colorize tests for VS Code",
|
||||
"version": "0.0.1",
|
||||
"publisher": "vscode",
|
||||
"private": true,
|
||||
"engines": {
|
||||
"vscode": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./",
|
||||
"vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.js compile-extension:vscode-api-tests ./tsconfig.json",
|
||||
"postinstall": "node ./node_modules/vscode/bin/install"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^1.6.2",
|
||||
"vscode": "^0.11.1"
|
||||
}
|
||||
}
|
||||
56
extensions/vscode-colorize-tests/src/colorizer.test.ts
Normal file
56
extensions/vscode-colorize-tests/src/colorizer.test.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import {commands, Uri} from 'vscode';
|
||||
import {join, basename, normalize, dirname} from 'path';
|
||||
import * as fs from 'fs';
|
||||
|
||||
function assertUnchangedTokens(testFixurePath:string, done) {
|
||||
let fileName = basename(testFixurePath);
|
||||
|
||||
return commands.executeCommand('_workbench.captureSyntaxTokens', Uri.file(testFixurePath)).then(data => {
|
||||
try {
|
||||
let resultsFolderPath = join(dirname(dirname(testFixurePath)), 'colorize-results');
|
||||
let resultPath = join(resultsFolderPath, fileName.replace('.', '_') + '.json');
|
||||
if (fs.existsSync(resultPath)) {
|
||||
let previosData = JSON.parse(fs.readFileSync(resultPath).toString());
|
||||
try {
|
||||
assert.deepEqual(data, previosData);
|
||||
} catch (e) {
|
||||
let errorResultPath = join(resultsFolderPath, fileName.replace('.', '_') + '.error.json');
|
||||
fs.writeFileSync(errorResultPath, JSON.stringify(data, null, '\t'));
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
fs.writeFileSync(resultPath, JSON.stringify(data, null, '\t'));
|
||||
}
|
||||
done();
|
||||
} catch (e) {
|
||||
done(e);
|
||||
}
|
||||
}, done);
|
||||
}
|
||||
|
||||
suite("colorization", () => {
|
||||
let extensionsFolder = normalize(join(__dirname, '../../'));
|
||||
console.log(extensionsFolder);
|
||||
let extensions = fs.readdirSync(extensionsFolder);
|
||||
extensions.forEach(extension => {
|
||||
let extensionColorizeFixurePath = join(extensionsFolder, extension, 'test', 'colorize-fixtures');
|
||||
if (fs.existsSync(extensionColorizeFixurePath)) {
|
||||
console.log(extensionColorizeFixurePath);
|
||||
let fixturesFiles = fs.readdirSync(extensionColorizeFixurePath);
|
||||
fixturesFiles.forEach(fixturesFile => {
|
||||
// define a test for each fixture
|
||||
test(extension + '-' + fixturesFile, function(done) {
|
||||
assertUnchangedTokens(join(extensionColorizeFixurePath, fixturesFile), done);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
28
extensions/vscode-colorize-tests/src/index.ts
Normal file
28
extensions/vscode-colorize-tests/src/index.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
//
|
||||
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
|
||||
//
|
||||
// This file is providing the test runner to use when running extension tests.
|
||||
// By default the test runner in use is Mocha based.
|
||||
//
|
||||
// You can provide your own test runner if you want to override it by exporting
|
||||
// a function run(testRoot: string, clb: (error:Error) => void) that the extension
|
||||
// host can call to run the tests. The test runner is expected to use console.log
|
||||
// to report the results back to the caller. When the tests are finished, return
|
||||
// a possible error to the callback or null if none.
|
||||
|
||||
const testRunner = require('vscode/lib/testrunner');
|
||||
|
||||
// You can directly control Mocha options by uncommenting the following lines
|
||||
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
|
||||
testRunner.configure({
|
||||
ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
|
||||
useColors: process.platform !== 'win32', // colored output from test results (only windows cannot handle)
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
export= testRunner;
|
||||
10
extensions/vscode-colorize-tests/src/typings/ref.d.ts
vendored
Normal file
10
extensions/vscode-colorize-tests/src/typings/ref.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/// <reference path='../../../../src/vs/vscode.d.ts'/>
|
||||
/// <reference path='../../../../src/typings/mocha.d.ts'/>
|
||||
/// <reference path='../../../../extensions/declares.d.ts'/>
|
||||
/// <reference path='../../../../extensions/node.d.ts'/>
|
||||
/// <reference path='../../../../extensions/lib.core.d.ts'/>
|
||||
12
extensions/vscode-colorize-tests/tsconfig.json
Normal file
12
extensions/vscode-colorize-tests/tsconfig.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "ES5",
|
||||
"outDir": "out",
|
||||
"noLib": true,
|
||||
"sourceMap": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
13
extensions/vscode-colorize-tests/typings/mocha.d.ts
vendored
Normal file
13
extensions/vscode-colorize-tests/typings/mocha.d.ts
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
declare function run(): void;
|
||||
|
||||
declare function suite(name: string, fn: (err?)=>void);
|
||||
declare function test(name: string, fn: (done?: (err?)=>void)=>void);
|
||||
declare function suiteSetup(fn: (done?: (err?)=>void)=>void);
|
||||
declare function suiteTeardown(fn: (done?: (err?)=>void)=>void);
|
||||
declare function setup(fn: (done?: (err?)=>void)=>void);
|
||||
declare function teardown(fn: (done?: (err?)=>void)=>void);
|
||||
Reference in New Issue
Block a user