mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
77
extensions/vscode-colorize-tests/src/colorizer.test.ts
Normal file
77
extensions/vscode-colorize-tests/src/colorizer.test.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. 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');
|
||||
if (!fs.existsSync(resultsFolderPath)) {
|
||||
fs.mkdirSync(resultsFolderPath);
|
||||
}
|
||||
let resultPath = join(resultsFolderPath, fileName.replace('.', '_') + '.json');
|
||||
if (fs.existsSync(resultPath)) {
|
||||
let previousData = JSON.parse(fs.readFileSync(resultPath).toString());
|
||||
try {
|
||||
assert.deepEqual(data, previousData);
|
||||
} catch (e) {
|
||||
fs.writeFileSync(resultPath, JSON.stringify(data, null, '\t'), { flag: 'w' });
|
||||
if (Array.isArray(data) && Array.isArray(previousData) && data.length === previousData.length) {
|
||||
for (let i= 0; i < data.length; i++) {
|
||||
let d = data[i];
|
||||
let p = previousData[i];
|
||||
if (d.c !== p.c || hasThemeChange(d.r, p.r)) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
// different but no tokenization ot color change: no failure
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fs.writeFileSync(resultPath, JSON.stringify(data, null, '\t'));
|
||||
}
|
||||
done();
|
||||
} catch (e) {
|
||||
done(e);
|
||||
}
|
||||
}, done);
|
||||
}
|
||||
|
||||
function hasThemeChange(d: any, p: any) : boolean {
|
||||
let keys = Object.keys(d);
|
||||
for (let key of keys) {
|
||||
if (d[key] !== p[key]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
suite('colorization', () => {
|
||||
let extensionsFolder = normalize(join(__dirname, '../../'));
|
||||
let extensions = fs.readdirSync(extensionsFolder);
|
||||
extensions.forEach(extension => {
|
||||
let extensionColorizeFixturePath = join(extensionsFolder, extension, 'test', 'colorize-fixtures');
|
||||
if (fs.existsSync(extensionColorizeFixturePath)) {
|
||||
let fixturesFiles = fs.readdirSync(extensionColorizeFixturePath);
|
||||
fixturesFiles.forEach(fixturesFile => {
|
||||
// define a test for each fixture
|
||||
test(extension + '-' + fixturesFile, function (done) {
|
||||
assertUnchangedTokens(join(extensionColorizeFixturePath, 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 Source EULA. 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: 60000
|
||||
});
|
||||
|
||||
export = testRunner;
|
||||
7
extensions/vscode-colorize-tests/src/typings/ref.d.ts
vendored
Normal file
7
extensions/vscode-colorize-tests/src/typings/ref.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
/// <reference types='@types/mocha'/>
|
||||
/// <reference types='@types/node'/>
|
||||
Reference in New Issue
Block a user