Skip to content

Commit

Permalink
Front end testing (#336)
Browse files Browse the repository at this point in the history
* adding tests

* karma setup

* got tests working

* mocking working

* set up coverage

* cleaned up commit

* moved tasks to appropriate places

* added task for jenkins

* change jenkins to cproc

* testing jenkins build

* testing builds

* combined testing

* finished build error

* fixed testing reporting
  • Loading branch information
Anthony Dresser authored Nov 17, 2016
1 parent d7fc17b commit 2e24ff2
Show file tree
Hide file tree
Showing 34 changed files with 1,829 additions and 402 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ packages
tools
examples
sqltoolsservice
coverage/
coverage
test-reports
4 changes: 2 additions & 2 deletions coverconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"enabled": false,
"relativeSourcePath": "../src",
"relativeCoverageDir": "../../coverage",
"ignorePatterns": ["**/node_modules/**", "**/libs/**", "**/lib/**", "**/*.min.js", "**/*.bundle.js"],
"ignorePatterns": ["**/node_modules/**", "**/libs/**", "**/lib/**", "**/htmlcontent/**/*.js", "**/*.bundle.js"],
"includePid": false,
"reports": ["lcov", "cobertura"],
"reports": ["json"],
"verbose": false
}
11 changes: 10 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const path = require('path');

require('./tasks/htmltasks')
require('./tasks/packagetasks')
require('./tasks/covertasks')

gulp.task('ext:lint', () => {
return gulp.src([
Expand Down Expand Up @@ -117,6 +116,16 @@ gulp.task('ext:copy', gulp.series('ext:copy-tests', 'ext:copy-js', 'ext:copy-con

gulp.task('ext:build', gulp.series('ext:lint', 'ext:compile', 'ext:copy'));

gulp.task('ext:test', (done) => {
process.env.JUNIT_REPORT_PATH = process.env['WORKSPACE'] + '\\test-reports\\ext_xunit.xml';
cproc.execSync('code --extensionDevelopmentPath="%WORKSPACE%" --extensionTestsPath="%WORKSPACE%/out/test" --verbose');
done();
});

gulp.task('test', gulp.series('html:test', 'ext:test'));

require('./tasks/covertasks');

gulp.task('clean', function (done) {
return del('out', done);
});
Expand Down
88 changes: 88 additions & 0 deletions karma-test-shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// #docregion
// /*global jasmine, __karma__, window*/
Error.stackTraceLimit = 0; // "No stacktrace"" is usually best for app testing.

// Uncomment to get full stacktrace output. Sometimes helpful, usually not.
Error.stackTraceLimit = Infinity; //

var builtPath = '/base/out/src/views/htmlcontent/dist/js/';

__karma__.loaded = function () { };

function isJsFile(path) {
return path.slice(-3) == '.js';
}

function isSpecFile(path) {
return /\.spec\.(.*\.)?js$/.test(path);
}

function isBuiltFile(path) {
return isJsFile(path) && (path.substr(0, builtPath.length) == builtPath);
}

var allSpecFiles = Object.keys(window.__karma__.files)
.filter(isSpecFile);

System.config({
baseURL: 'base/out/src/views/htmlcontent',
// Extend usual application package list with test folder
packages: { 'testing': { main: 'index.js', defaultExtension: 'js' } },

// Assume npm: is set in `paths` in systemjs.config
// Map the angular testing umd bundles
map: {
'@angular/core/testing': 'lib/js/@angular/core/bundles/core-testing.umd.js',
'@angular/common/testing': 'lib/js/@angular/common/bundles/common-testing.umd.js',
'@angular/compiler/testing': 'lib/js/@angular/compiler/bundles/compiler-testing.umd.js',
'@angular/platform-browser/testing': 'lib/js/@angular/platform-browser/bundles/platform-browser-testing.umd.js',
'@angular/platform-browser-dynamic/testing': 'lib/js/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
'@angular/http/testing': 'lib/js/@angular/http/bundles/http-testing.umd.js',
'@angular/router/testing': 'lib/js/@angular/router/bundles/router-testing.umd.js',
'@angular/forms/testing': 'ib/js/@angular/forms/bundles/forms-testing.umd.js',
},
});

System.import('lib/js/systemjs.config.js')
.then(importSystemJsExtras)
.then(initTestBed)
.then(initTesting);

/** Optional SystemJS configuration extras. Keep going w/o it */
function importSystemJsExtras(){
return System.import('lib/js/systemjs.config.extras.js')
.catch(function(reason) {
console.log(
'Warning: System.import could not load the optional "systemjs.config.extras.js". Did you omit it by accident? Continuing without it.'
);
console.log(reason);
});
}

function initTestBed(){
return Promise.all([
System.import('@angular/core/testing'),
System.import('@angular/platform-browser-dynamic/testing')
])

.then(function (providers) {
var coreTesting = providers[0];
var browserTesting = providers[1];

jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;

coreTesting.TestBed.initTestEnvironment(
browserTesting.BrowserDynamicTestingModule,
browserTesting.platformBrowserDynamicTesting());
})
}

// Import all spec files and start karma
function initTesting () {
return Promise.all(
allSpecFiles.map(function (moduleName) {
return System.import(moduleName);
})
)
.then(__karma__.start, __karma__.error);
}
141 changes: 141 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// #docregion
const path = require('path');

module.exports = function(config) {

var appBase = 'out/src/views/htmlcontent/dist/'; // transpiled app JS and map files
var appSrcBase = 'src/views/htmlcontent/src/js/'; // app source TS files
var appAssets = 'base/out/src/views/htmlcontent/'; // component assets fetched by Angular's compiler

var testBase = 'out/test/angular/'; // transpiled test JS and map files
var testSrcBase = 'test/angular/'; // test source TS files

config.set({
basePath: path.join(__dirname),
frameworks: ['jasmine'],
plugins: [
require('karma-remap-istanbul'),
require('karma-coverage'),
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'), // click "Debug" in browser to see it
require('karma-htmlfile-reporter'), // crashing w/ strange socket error
require('karma-junit-reporter')
],

customLaunchers: {
// From the CLI. Not used here but interesting
// chrome setup for travis CI using chromium
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
files: [
'out/src/views/htmlcontent/lib/js/jquery-1.7.min.js',
'out/src/views/htmlcontent/lib/js/jquery.event.drag-2.2.js',
'out/src/views/htmlcontent/lib/js/jquery-ui-1.8.16.custom.min.js',
'out/src/views/htmlcontent/lib/js/underscore-min.js',
'out/src/views/htmlcontent/lib/js/slick.core.js',
'out/src/views/htmlcontent/lib/js/slick.grid.js',
'out/src/views/htmlcontent/lib/js/slick.editors.js',
'out/src/views/htmlcontent/lib/js/slick.autosizecolumn.js',
'out/src/views/htmlcontent/lib/js/slick.dragrowselector.js',
// System.js for module loading
'out/src/views/htmlcontent/lib/js/system.src.js',

// Polyfills
'out/src/views/htmlcontent/lib/js/shim.min.js',
'out/src/views/htmlcontent/lib/js/Reflect.js',

// zone.js
'out/src/views/htmlcontent/lib/js/zone.js/dist/zone.js',
'out/src/views/htmlcontent/lib/js/zone.js/dist/long-stack-trace-zone.js',
'out/src/views/htmlcontent/lib/js/zone.js/dist/proxy.js',
'out/src/views/htmlcontent/lib/js/zone.js/dist/sync-test.js',
'out/src/views/htmlcontent/lib/js/zone.js/dist/jasmine-patch.js',
'out/src/views/htmlcontent/lib/js/zone.js/dist/async-test.js',
'out/src/views/htmlcontent/lib/js/zone.js/dist/fake-async-test.js',

// RxJs
{ pattern: 'out/src/views/htmlcontent/lib/js/rxjs/**/*.js', included: false, watched: false },
{ pattern: 'out/src/views/htmlcontent/lib/js/rxjs/**/*.js.map', included: false, watched: false },


{ pattern: 'out/src/views/htmlcontent/lib/js/angular2-slickgrid/**/*.js', included: false, watched: false },
{ pattern: 'out/src/views/htmlcontent/lib/js/angular2-slickgrid/**/*.js.map', included: false, watched: false },

{ pattern: 'out/src/views/htmlcontent/lib/js/json.js', included: false, watched: false},

// Paths loaded via module imports:
// Angular itself
{ pattern: 'out/src/views/htmlcontent/lib/js/@angular/**/*.js', included: false, watched: false },
{ pattern: 'out/src/views/htmlcontent/lib/js/@angular/**/*.js.map', included: false, watched: false },

{ pattern: 'out/src/views/htmlcontent/lib/js/systemjs.config.js', included: false, watched: false },
{ pattern: 'out/src/views/htmlcontent/lib/js/systemjs.config.extras.js', included: false, watched: false },
'karma-test-shim.js',

// transpiled application & spec code paths loaded via module imports
{ pattern: appBase + '**/*.js', included: false, watched: true },
{ pattern: appBase + '**/*.json', included: false, watched: false },
{ pattern: testBase + '**/*.js', included: false, watched: false },


// Asset (HTML & CSS) paths loaded via Angular's component compiler
// (these paths need to be rewritten, see proxies section)
{ pattern: appBase + '**/*.html', included: false, watched: false },
{ pattern: appBase + '**/*.css', included: false, watched: false },

// Paths for debugging with source maps in dev tools
{ pattern: appSrcBase + '**/*.ts', included: false, watched: false },
{ pattern: appBase + '**/*.js.map', included: false, watched: false },
{ pattern: testSrcBase + '**/*.ts', included: false, watched: false },
{ pattern: testBase + '**/*.js.map', included: false, watched: false }
],

// Proxied base paths for loading assets
proxies: {
// required for component assets fetched by Angular's compiler
"/dist/": 'base/out/src/views/htmlcontent/dist/'
},

exclude: [],
preprocessors: {
'out/src/views/htmlcontent/dist/**/!(*spec)*.js': 'coverage',
},
// disabled HtmlReporter; suddenly crashing w/ strange socket error
reporters: ['progress', 'coverage', 'karma-remap-istanbul', 'junit'],//'html'],

// HtmlReporter configuration
htmlReporter: {
// Open this file to see results in browser
outputFile: '_test-output/tests.html',

// Optional
pageTitle: 'Unit Tests',
subPageTitle: __dirname
},
coverageReporter: {
dir : 'coverage/',
reporters: [
{type: 'json'}
]
},
remapIstanbulReporter: {
reports: {
json: 'coverage/coverage-html.json'
}
},
junitReporter: {
outputDir: 'test-reports/'
},

port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: true
})
}
20 changes: 16 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,33 @@
"gulp-clean-css": "^2.0.13",
"gulp-concat": "^2.6.0",
"gulp-install": "^0.6.0",
"gulp-istanbul-report": "0.0.1",
"gulp-json-editor": "^2.2.1",
"gulp-rename": "^1.2.2",
"gulp-shell": "^0.5.2",
"gulp-sourcemaps": "^1.6.0",
"gulp-tslint": "^6.0.2",
"gulp-typescript": "^2.13.6",
"istanbul": "^0.4.5",
"remap-istanbul": "^0.6.4",
"gulp-uglify": "^2.0.0",
"istanbul": "^0.4.5",
"jasmine-core": "~2.4.1",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
"karma-htmlfile-reporter": "^0.3.4",
"karma-jasmine": "^1.0.2",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-junit-reporter": "^1.1.0",
"karma-remap-istanbul": "^0.2.1",
"pm-mocha-jenkins-reporter": "^0.2.6",
"remap-istanbul": "^0.6.4",
"systemjs-builder": "^0.15.32",
"tslint": "^3.14.0",
"typemoq": "^0.3.2",
"typescript": "^1.8.9",
"uglify-js": "mishoo/UglifyJS2#harmony",
"vscode": "^0.11.0"
"vscode": "^0.11.0",
"yargs": "https://registry.npmjs.org/yargs/-/yargs-3.32.0.tgz"
},
"dependencies": {
"applicationinsights": "^0.15.0",
Expand Down Expand Up @@ -223,7 +235,7 @@
"type": "string",
"default": "{{put-username-here}}",
"description": "[Optional] Specify the user name for SQL Server authentication. If user name is not specified, when you connect, you will be asked again."
},
},
"password": {
"type": "string",
"default": "{{put-password-here}}",
Expand Down
11 changes: 10 additions & 1 deletion src/models/SqlOutputContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import StatusView from '../views/statusView';
import VscodeWrapper from './../controllers/vscodeWrapper';
import { ISelectionData } from './interfaces';
const pd = require('pretty-data').pd;
const fs = require('fs');

const deletionTimeoutTime = 1.8e6; // in ms, currently 30 minutes

Expand Down Expand Up @@ -70,6 +71,13 @@ export class SqlOutputContentProvider implements vscode.TextDocumentContentProvi
let theme: string = req.query.theme;
let backgroundcolor: string = req.query.backgroundcolor;
let color: string = req.query.color;
let prod;
try {
fs.accessSync(path.join(LocalWebService.staticContentPath, Constants.contentProviderMinFile), fs.F_OK);
prod = true;
} catch (e) {
prod = false;
}
let editorConfig = self._vscodeWrapper.getConfiguration('editor');
let fontfamily = editorConfig.get<string>('fontFamily').split('\'').join('').split('"').join('');
let fontsize = editorConfig.get<number>('fontSize') + 'px';
Expand All @@ -82,7 +90,8 @@ export class SqlOutputContentProvider implements vscode.TextDocumentContentProvi
color: color,
fontfamily: fontfamily,
fontsize: fontsize,
fontweight: fontweight
fontweight: fontweight,
prod: prod
}
);
});
Expand Down
1 change: 1 addition & 0 deletions src/models/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const outputContentTypeShowError = 'showError';
export const outputContentTypeShowWarning = 'showWarning';
export const outputServiceLocalhost = 'http://localhost:';
export const msgContentProviderSqlOutputHtml = 'dist/html/sqlOutput.ejs';
export const contentProviderMinFile = 'dist/js/app.min.js';

export const configLogDebugInfo = 'logDebugInfo';
export const configMyConnections = 'connections';
Expand Down
5 changes: 5 additions & 0 deletions src/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ export interface IDbColumn {
isHidden?: boolean;
isIdentity?: boolean;
isKey?: boolean;
isBytes?: boolean;
isChars?: boolean;
isSqlVariant?: boolean;
isUdt?: boolean;
dataType: string;
isXml?: boolean;
isJson?: boolean;
isLong?: boolean;
Expand Down
Loading

0 comments on commit 2e24ff2

Please sign in to comment.