Skip to content

Commit 2e24ff2

Browse files
author
Anthony Dresser
authored
Front end testing (#336)
* 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
1 parent d7fc17b commit 2e24ff2

34 files changed

+1829
-402
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ packages
1313
tools
1414
examples
1515
sqltoolsservice
16-
coverage/
16+
coverage
17+
test-reports

coverconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"enabled": false,
33
"relativeSourcePath": "../src",
44
"relativeCoverageDir": "../../coverage",
5-
"ignorePatterns": ["**/node_modules/**", "**/libs/**", "**/lib/**", "**/*.min.js", "**/*.bundle.js"],
5+
"ignorePatterns": ["**/node_modules/**", "**/libs/**", "**/lib/**", "**/htmlcontent/**/*.js", "**/*.bundle.js"],
66
"includePid": false,
7-
"reports": ["lcov", "cobertura"],
7+
"reports": ["json"],
88
"verbose": false
99
}

gulpfile.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const path = require('path');
1818

1919
require('./tasks/htmltasks')
2020
require('./tasks/packagetasks')
21-
require('./tasks/covertasks')
2221

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

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

119+
gulp.task('ext:test', (done) => {
120+
process.env.JUNIT_REPORT_PATH = process.env['WORKSPACE'] + '\\test-reports\\ext_xunit.xml';
121+
cproc.execSync('code --extensionDevelopmentPath="%WORKSPACE%" --extensionTestsPath="%WORKSPACE%/out/test" --verbose');
122+
done();
123+
});
124+
125+
gulp.task('test', gulp.series('html:test', 'ext:test'));
126+
127+
require('./tasks/covertasks');
128+
120129
gulp.task('clean', function (done) {
121130
return del('out', done);
122131
});

karma-test-shim.js

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// #docregion
2+
// /*global jasmine, __karma__, window*/
3+
Error.stackTraceLimit = 0; // "No stacktrace"" is usually best for app testing.
4+
5+
// Uncomment to get full stacktrace output. Sometimes helpful, usually not.
6+
Error.stackTraceLimit = Infinity; //
7+
8+
var builtPath = '/base/out/src/views/htmlcontent/dist/js/';
9+
10+
__karma__.loaded = function () { };
11+
12+
function isJsFile(path) {
13+
return path.slice(-3) == '.js';
14+
}
15+
16+
function isSpecFile(path) {
17+
return /\.spec\.(.*\.)?js$/.test(path);
18+
}
19+
20+
function isBuiltFile(path) {
21+
return isJsFile(path) && (path.substr(0, builtPath.length) == builtPath);
22+
}
23+
24+
var allSpecFiles = Object.keys(window.__karma__.files)
25+
.filter(isSpecFile);
26+
27+
System.config({
28+
baseURL: 'base/out/src/views/htmlcontent',
29+
// Extend usual application package list with test folder
30+
packages: { 'testing': { main: 'index.js', defaultExtension: 'js' } },
31+
32+
// Assume npm: is set in `paths` in systemjs.config
33+
// Map the angular testing umd bundles
34+
map: {
35+
'@angular/core/testing': 'lib/js/@angular/core/bundles/core-testing.umd.js',
36+
'@angular/common/testing': 'lib/js/@angular/common/bundles/common-testing.umd.js',
37+
'@angular/compiler/testing': 'lib/js/@angular/compiler/bundles/compiler-testing.umd.js',
38+
'@angular/platform-browser/testing': 'lib/js/@angular/platform-browser/bundles/platform-browser-testing.umd.js',
39+
'@angular/platform-browser-dynamic/testing': 'lib/js/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
40+
'@angular/http/testing': 'lib/js/@angular/http/bundles/http-testing.umd.js',
41+
'@angular/router/testing': 'lib/js/@angular/router/bundles/router-testing.umd.js',
42+
'@angular/forms/testing': 'ib/js/@angular/forms/bundles/forms-testing.umd.js',
43+
},
44+
});
45+
46+
System.import('lib/js/systemjs.config.js')
47+
.then(importSystemJsExtras)
48+
.then(initTestBed)
49+
.then(initTesting);
50+
51+
/** Optional SystemJS configuration extras. Keep going w/o it */
52+
function importSystemJsExtras(){
53+
return System.import('lib/js/systemjs.config.extras.js')
54+
.catch(function(reason) {
55+
console.log(
56+
'Warning: System.import could not load the optional "systemjs.config.extras.js". Did you omit it by accident? Continuing without it.'
57+
);
58+
console.log(reason);
59+
});
60+
}
61+
62+
function initTestBed(){
63+
return Promise.all([
64+
System.import('@angular/core/testing'),
65+
System.import('@angular/platform-browser-dynamic/testing')
66+
])
67+
68+
.then(function (providers) {
69+
var coreTesting = providers[0];
70+
var browserTesting = providers[1];
71+
72+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
73+
74+
coreTesting.TestBed.initTestEnvironment(
75+
browserTesting.BrowserDynamicTestingModule,
76+
browserTesting.platformBrowserDynamicTesting());
77+
})
78+
}
79+
80+
// Import all spec files and start karma
81+
function initTesting () {
82+
return Promise.all(
83+
allSpecFiles.map(function (moduleName) {
84+
return System.import(moduleName);
85+
})
86+
)
87+
.then(__karma__.start, __karma__.error);
88+
}

karma.conf.js

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// #docregion
2+
const path = require('path');
3+
4+
module.exports = function(config) {
5+
6+
var appBase = 'out/src/views/htmlcontent/dist/'; // transpiled app JS and map files
7+
var appSrcBase = 'src/views/htmlcontent/src/js/'; // app source TS files
8+
var appAssets = 'base/out/src/views/htmlcontent/'; // component assets fetched by Angular's compiler
9+
10+
var testBase = 'out/test/angular/'; // transpiled test JS and map files
11+
var testSrcBase = 'test/angular/'; // test source TS files
12+
13+
config.set({
14+
basePath: path.join(__dirname),
15+
frameworks: ['jasmine'],
16+
plugins: [
17+
require('karma-remap-istanbul'),
18+
require('karma-coverage'),
19+
require('karma-jasmine'),
20+
require('karma-chrome-launcher'),
21+
require('karma-jasmine-html-reporter'), // click "Debug" in browser to see it
22+
require('karma-htmlfile-reporter'), // crashing w/ strange socket error
23+
require('karma-junit-reporter')
24+
],
25+
26+
customLaunchers: {
27+
// From the CLI. Not used here but interesting
28+
// chrome setup for travis CI using chromium
29+
Chrome_travis_ci: {
30+
base: 'Chrome',
31+
flags: ['--no-sandbox']
32+
}
33+
},
34+
files: [
35+
'out/src/views/htmlcontent/lib/js/jquery-1.7.min.js',
36+
'out/src/views/htmlcontent/lib/js/jquery.event.drag-2.2.js',
37+
'out/src/views/htmlcontent/lib/js/jquery-ui-1.8.16.custom.min.js',
38+
'out/src/views/htmlcontent/lib/js/underscore-min.js',
39+
'out/src/views/htmlcontent/lib/js/slick.core.js',
40+
'out/src/views/htmlcontent/lib/js/slick.grid.js',
41+
'out/src/views/htmlcontent/lib/js/slick.editors.js',
42+
'out/src/views/htmlcontent/lib/js/slick.autosizecolumn.js',
43+
'out/src/views/htmlcontent/lib/js/slick.dragrowselector.js',
44+
// System.js for module loading
45+
'out/src/views/htmlcontent/lib/js/system.src.js',
46+
47+
// Polyfills
48+
'out/src/views/htmlcontent/lib/js/shim.min.js',
49+
'out/src/views/htmlcontent/lib/js/Reflect.js',
50+
51+
// zone.js
52+
'out/src/views/htmlcontent/lib/js/zone.js/dist/zone.js',
53+
'out/src/views/htmlcontent/lib/js/zone.js/dist/long-stack-trace-zone.js',
54+
'out/src/views/htmlcontent/lib/js/zone.js/dist/proxy.js',
55+
'out/src/views/htmlcontent/lib/js/zone.js/dist/sync-test.js',
56+
'out/src/views/htmlcontent/lib/js/zone.js/dist/jasmine-patch.js',
57+
'out/src/views/htmlcontent/lib/js/zone.js/dist/async-test.js',
58+
'out/src/views/htmlcontent/lib/js/zone.js/dist/fake-async-test.js',
59+
60+
// RxJs
61+
{ pattern: 'out/src/views/htmlcontent/lib/js/rxjs/**/*.js', included: false, watched: false },
62+
{ pattern: 'out/src/views/htmlcontent/lib/js/rxjs/**/*.js.map', included: false, watched: false },
63+
64+
65+
{ pattern: 'out/src/views/htmlcontent/lib/js/angular2-slickgrid/**/*.js', included: false, watched: false },
66+
{ pattern: 'out/src/views/htmlcontent/lib/js/angular2-slickgrid/**/*.js.map', included: false, watched: false },
67+
68+
{ pattern: 'out/src/views/htmlcontent/lib/js/json.js', included: false, watched: false},
69+
70+
// Paths loaded via module imports:
71+
// Angular itself
72+
{ pattern: 'out/src/views/htmlcontent/lib/js/@angular/**/*.js', included: false, watched: false },
73+
{ pattern: 'out/src/views/htmlcontent/lib/js/@angular/**/*.js.map', included: false, watched: false },
74+
75+
{ pattern: 'out/src/views/htmlcontent/lib/js/systemjs.config.js', included: false, watched: false },
76+
{ pattern: 'out/src/views/htmlcontent/lib/js/systemjs.config.extras.js', included: false, watched: false },
77+
'karma-test-shim.js',
78+
79+
// transpiled application & spec code paths loaded via module imports
80+
{ pattern: appBase + '**/*.js', included: false, watched: true },
81+
{ pattern: appBase + '**/*.json', included: false, watched: false },
82+
{ pattern: testBase + '**/*.js', included: false, watched: false },
83+
84+
85+
// Asset (HTML & CSS) paths loaded via Angular's component compiler
86+
// (these paths need to be rewritten, see proxies section)
87+
{ pattern: appBase + '**/*.html', included: false, watched: false },
88+
{ pattern: appBase + '**/*.css', included: false, watched: false },
89+
90+
// Paths for debugging with source maps in dev tools
91+
{ pattern: appSrcBase + '**/*.ts', included: false, watched: false },
92+
{ pattern: appBase + '**/*.js.map', included: false, watched: false },
93+
{ pattern: testSrcBase + '**/*.ts', included: false, watched: false },
94+
{ pattern: testBase + '**/*.js.map', included: false, watched: false }
95+
],
96+
97+
// Proxied base paths for loading assets
98+
proxies: {
99+
// required for component assets fetched by Angular's compiler
100+
"/dist/": 'base/out/src/views/htmlcontent/dist/'
101+
},
102+
103+
exclude: [],
104+
preprocessors: {
105+
'out/src/views/htmlcontent/dist/**/!(*spec)*.js': 'coverage',
106+
},
107+
// disabled HtmlReporter; suddenly crashing w/ strange socket error
108+
reporters: ['progress', 'coverage', 'karma-remap-istanbul', 'junit'],//'html'],
109+
110+
// HtmlReporter configuration
111+
htmlReporter: {
112+
// Open this file to see results in browser
113+
outputFile: '_test-output/tests.html',
114+
115+
// Optional
116+
pageTitle: 'Unit Tests',
117+
subPageTitle: __dirname
118+
},
119+
coverageReporter: {
120+
dir : 'coverage/',
121+
reporters: [
122+
{type: 'json'}
123+
]
124+
},
125+
remapIstanbulReporter: {
126+
reports: {
127+
json: 'coverage/coverage-html.json'
128+
}
129+
},
130+
junitReporter: {
131+
outputDir: 'test-reports/'
132+
},
133+
134+
port: 9876,
135+
colors: true,
136+
logLevel: config.LOG_INFO,
137+
autoWatch: true,
138+
browsers: ['Chrome'],
139+
singleRun: true
140+
})
141+
}

package.json

+16-4
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,33 @@
4747
"gulp-clean-css": "^2.0.13",
4848
"gulp-concat": "^2.6.0",
4949
"gulp-install": "^0.6.0",
50+
"gulp-istanbul-report": "0.0.1",
5051
"gulp-json-editor": "^2.2.1",
5152
"gulp-rename": "^1.2.2",
53+
"gulp-shell": "^0.5.2",
5254
"gulp-sourcemaps": "^1.6.0",
5355
"gulp-tslint": "^6.0.2",
5456
"gulp-typescript": "^2.13.6",
55-
"istanbul": "^0.4.5",
56-
"remap-istanbul": "^0.6.4",
5757
"gulp-uglify": "^2.0.0",
58+
"istanbul": "^0.4.5",
59+
"jasmine-core": "~2.4.1",
60+
"karma": "^1.3.0",
61+
"karma-chrome-launcher": "^2.0.0",
62+
"karma-coverage": "^1.1.1",
63+
"karma-htmlfile-reporter": "^0.3.4",
64+
"karma-jasmine": "^1.0.2",
65+
"karma-jasmine-html-reporter": "^0.2.2",
66+
"karma-junit-reporter": "^1.1.0",
67+
"karma-remap-istanbul": "^0.2.1",
5868
"pm-mocha-jenkins-reporter": "^0.2.6",
69+
"remap-istanbul": "^0.6.4",
5970
"systemjs-builder": "^0.15.32",
6071
"tslint": "^3.14.0",
6172
"typemoq": "^0.3.2",
6273
"typescript": "^1.8.9",
6374
"uglify-js": "mishoo/UglifyJS2#harmony",
64-
"vscode": "^0.11.0"
75+
"vscode": "^0.11.0",
76+
"yargs": "https://registry.npmjs.org/yargs/-/yargs-3.32.0.tgz"
6577
},
6678
"dependencies": {
6779
"applicationinsights": "^0.15.0",
@@ -223,7 +235,7 @@
223235
"type": "string",
224236
"default": "{{put-username-here}}",
225237
"description": "[Optional] Specify the user name for SQL Server authentication. If user name is not specified, when you connect, you will be asked again."
226-
},
238+
},
227239
"password": {
228240
"type": "string",
229241
"default": "{{put-password-here}}",

src/models/SqlOutputContentProvider.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import StatusView from '../views/statusView';
1212
import VscodeWrapper from './../controllers/vscodeWrapper';
1313
import { ISelectionData } from './interfaces';
1414
const pd = require('pretty-data').pd;
15+
const fs = require('fs');
1516

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

@@ -70,6 +71,13 @@ export class SqlOutputContentProvider implements vscode.TextDocumentContentProvi
7071
let theme: string = req.query.theme;
7172
let backgroundcolor: string = req.query.backgroundcolor;
7273
let color: string = req.query.color;
74+
let prod;
75+
try {
76+
fs.accessSync(path.join(LocalWebService.staticContentPath, Constants.contentProviderMinFile), fs.F_OK);
77+
prod = true;
78+
} catch (e) {
79+
prod = false;
80+
}
7381
let editorConfig = self._vscodeWrapper.getConfiguration('editor');
7482
let fontfamily = editorConfig.get<string>('fontFamily').split('\'').join('').split('"').join('');
7583
let fontsize = editorConfig.get<number>('fontSize') + 'px';
@@ -82,7 +90,8 @@ export class SqlOutputContentProvider implements vscode.TextDocumentContentProvi
8290
color: color,
8391
fontfamily: fontfamily,
8492
fontsize: fontsize,
85-
fontweight: fontweight
93+
fontweight: fontweight,
94+
prod: prod
8695
}
8796
);
8897
});

src/models/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const outputContentTypeShowError = 'showError';
4343
export const outputContentTypeShowWarning = 'showWarning';
4444
export const outputServiceLocalhost = 'http://localhost:';
4545
export const msgContentProviderSqlOutputHtml = 'dist/html/sqlOutput.ejs';
46+
export const contentProviderMinFile = 'dist/js/app.min.js';
4647

4748
export const configLogDebugInfo = 'logDebugInfo';
4849
export const configMyConnections = 'connections';

src/models/interfaces.ts

+5
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ export interface IDbColumn {
229229
isHidden?: boolean;
230230
isIdentity?: boolean;
231231
isKey?: boolean;
232+
isBytes?: boolean;
233+
isChars?: boolean;
234+
isSqlVariant?: boolean;
235+
isUdt?: boolean;
236+
dataType: string;
232237
isXml?: boolean;
233238
isJson?: boolean;
234239
isLong?: boolean;

0 commit comments

Comments
 (0)