mirror of
https://github.com/golang/go
synced 2024-09-30 14:18:32 -06:00
cmd/heapview: add karma+jasmine TS unit testing config
Add a configuration that allows unit testing of client Typescript code using Karma and Jasmine. Add a basic test to exercise this. Change-Id: I88af82b68547423efeaafb0fab8214ed39573ee9 Reviewed-on: https://go-review.googlesource.com/25411 Reviewed-by: David Crawshaw <crawshaw@golang.org> Reviewed-by: Evan Martin <evanm@google.com>
This commit is contained in:
parent
bf0c35b6b6
commit
7ef02fdb22
1
cmd/heapview/client/.clang-format
Normal file
1
cmd/heapview/client/.clang-format
Normal file
@ -0,0 +1 @@
|
||||
BasedOnStyle: Google
|
@ -3,6 +3,5 @@
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
export function main() {
|
||||
document.title = "Go Heap Viewer";
|
||||
}
|
||||
|
||||
document.title = 'Go Heap Viewer';
|
||||
}
|
||||
|
12
cmd/heapview/client/main_test.ts
Normal file
12
cmd/heapview/client/main_test.ts
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
import {main} from './main';
|
||||
|
||||
describe("main", () => {
|
||||
it('sets the document\'s title', () => {
|
||||
main();
|
||||
expect(document.title).toBe('Go Heap Viewer');
|
||||
});
|
||||
});
|
@ -12,10 +12,23 @@
|
||||
"If you do have npm installed, use the `npm i` command",
|
||||
"in this directory to install the typings."
|
||||
],
|
||||
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@types/es6-promise": "0.0.28",
|
||||
"@types/whatwg-fetch": "0.0.27"
|
||||
"name": "@golangtools/heapview",
|
||||
"version": "0.0.0",
|
||||
"devDependencies": {
|
||||
"@types/webcomponents.js": "latest",
|
||||
"@types/whatwg-fetch": "latest",
|
||||
"@types/jasmine": "latest",
|
||||
|
||||
"jasmine-core": "latest",
|
||||
"karma": "latest",
|
||||
"karma-jasmine": "latest",
|
||||
"karma-chrome-launcher": "latest",
|
||||
|
||||
"clang-format": "latest"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "karma start testing/karma.conf.js",
|
||||
"format": "find . | grep '\\(test_main\\.js\\|\\.ts\\)$' | xargs clang-format -i"
|
||||
}
|
||||
}
|
||||
|
21
cmd/heapview/client/testing/karma.conf.js
Normal file
21
cmd/heapview/client/testing/karma.conf.js
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
module.exports = config => {
|
||||
config.set({
|
||||
frameworks: ['jasmine'],
|
||||
basePath: '../../../..',
|
||||
files: [
|
||||
'third_party/typescript/typescript.js',
|
||||
'third_party/moduleloader/moduleloader.js',
|
||||
'cmd/heapview/client/testing/test_main.js',
|
||||
{pattern: 'cmd/heapview/client/**/*.ts', included: false},
|
||||
],
|
||||
browsers: ['Chrome'],
|
||||
plugins: [
|
||||
'karma-jasmine',
|
||||
'karma-chrome-launcher'
|
||||
],
|
||||
})
|
||||
}
|
29
cmd/heapview/client/testing/test_main.js
Normal file
29
cmd/heapview/client/testing/test_main.js
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Configure module loader.
|
||||
System.transpiler = 'typescript'
|
||||
System.locate = (load) => load.name + '.ts';
|
||||
|
||||
// Determine set of test files.
|
||||
var tests = [];
|
||||
for (var file in window.__karma__.files) {
|
||||
if (window.__karma__.files.hasOwnProperty(file)) {
|
||||
if (/_test\.ts$/.test(file)) {
|
||||
tests.push(file.slice(0, -3));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Steal loaded callback so we can block until we're
|
||||
// done loading all test modules.
|
||||
var loadedCallback = window.__karma__.loaded.bind(window.__karma__);
|
||||
window.__karma__.loaded = () => {};
|
||||
|
||||
// Load all test modules, and then call loadedCallback.
|
||||
var promises = [];
|
||||
for (var i = 0; i < tests.length; i++) {
|
||||
promises.push(System.import(tests[i]));
|
||||
}
|
||||
Promise.all(promises).then(loadedCallback);
|
40
cmd/heapview/client/tslint.json
Normal file
40
cmd/heapview/client/tslint.json
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// This tslint file is based on a configuration used at
|
||||
// Google.
|
||||
|
||||
{
|
||||
"rules": {
|
||||
"class-name": true,
|
||||
"forin": true,
|
||||
"interface-name": [true, "never-prefix"],
|
||||
"jsdoc-format": true,
|
||||
"label-position": true,
|
||||
"label-undefined": true,
|
||||
"new-parens": true,
|
||||
"no-angle-bracket-type-assertion": true,
|
||||
"no-construct": true,
|
||||
"no-debugger": true,
|
||||
"no-namespace": [true, "allow-declarations"],
|
||||
"no-reference": true,
|
||||
"no-require-imports": true,
|
||||
"no-unused-expression": true,
|
||||
"no-unused-variable": true,
|
||||
"no-use-before-declare": true,
|
||||
"no-var-keyword": true,
|
||||
"semicolon": [true, "always"],
|
||||
"switch-default": true,
|
||||
"triple-equals": [true, "allow-null-check"],
|
||||
"use-isnan": true,
|
||||
"variable-name": [
|
||||
true,
|
||||
"check-format",
|
||||
"ban-keywords",
|
||||
"allow-leading-underscore",
|
||||
"allow-trailing-underscore",
|
||||
"allow-pascal-case"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user