diff --git a/cmd/heapview/client/.clang-format b/cmd/heapview/client/.clang-format new file mode 100644 index 0000000000..f6cb8ad931 --- /dev/null +++ b/cmd/heapview/client/.clang-format @@ -0,0 +1 @@ +BasedOnStyle: Google diff --git a/cmd/heapview/client/main.ts b/cmd/heapview/client/main.ts index 32b6ebf48d..146eda1b3d 100644 --- a/cmd/heapview/client/main.ts +++ b/cmd/heapview/client/main.ts @@ -3,6 +3,5 @@ // license that can be found in the LICENSE file. export function main() { - document.title = "Go Heap Viewer"; -} - \ No newline at end of file + document.title = 'Go Heap Viewer'; +} diff --git a/cmd/heapview/client/main_test.ts b/cmd/heapview/client/main_test.ts new file mode 100644 index 0000000000..1aa8807dd7 --- /dev/null +++ b/cmd/heapview/client/main_test.ts @@ -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'); + }); +}); \ No newline at end of file diff --git a/cmd/heapview/client/package.json b/cmd/heapview/client/package.json index a23163616d..25b7cc7fc7 100644 --- a/cmd/heapview/client/package.json +++ b/cmd/heapview/client/package.json @@ -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" } } diff --git a/cmd/heapview/client/testing/karma.conf.js b/cmd/heapview/client/testing/karma.conf.js new file mode 100644 index 0000000000..545c624d49 --- /dev/null +++ b/cmd/heapview/client/testing/karma.conf.js @@ -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' + ], + }) +} \ No newline at end of file diff --git a/cmd/heapview/client/testing/test_main.js b/cmd/heapview/client/testing/test_main.js new file mode 100644 index 0000000000..79a49ff215 --- /dev/null +++ b/cmd/heapview/client/testing/test_main.js @@ -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); \ No newline at end of file diff --git a/cmd/heapview/client/tslint.json b/cmd/heapview/client/tslint.json new file mode 100644 index 0000000000..a0f2d15d2f --- /dev/null +++ b/cmd/heapview/client/tslint.json @@ -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" + ] + } +} \ No newline at end of file