Conversation
In retrospect, I'm not sure why I expected that to work.
CredentialStore instances need to be disposed after use to prevent the command registration in its contructor from colliding.
|
@smashwilson this is a really great effort! When we introduced graphql into the project, we separate models and views by putting everything view related into For testing |
…hub into aw/expand-tests
TypeScript 2.x isn't smart enough to follow some of the conditional types in the Builder work I'm preparing.
I needed to enable these to import lodash. Unsure why and open to pushback 😉
smashwilson
left a comment
There was a problem hiding this comment.
Self-review to provide a little more context 😄
| "files.trimTrailingWhitespace": true, | ||
| "editor.insertSpaces": false | ||
| "editor.insertSpaces": false, | ||
| "typescript.tsdk": "node_modules/typescript/lib" |
There was a problem hiding this comment.
It looks like this prompts VS Code to make the version of TypeScript from our own node_modules/ available as a language server in addition to the bundled one. I think this was added automatically when I toggled it in my workspace?
There was a problem hiding this comment.
I would revert this, I don't think we need this setting to be on for everyone developing this project
package.json
Outdated
| "@types/graphql": "^14.0.5", | ||
| "@types/keytar": "^4.0.1", | ||
| "@types/lodash": "^4.14.106", | ||
| "@types/lodash.isequal": "4.5.5", |
There was a problem hiding this comment.
I'm not sure why we depend on @types/lodash but not lodash itself?
I believe @kuychaco found a place where we were requiring lodash directly even though it's a transitive dependency and promoted it to a direct dependency instead. We should be able to replace the places I used lodash.isequal with lodash once that's merged in.
package.json
Outdated
| "tslint-webpack-plugin": "^1.2.2", | ||
| "typescript": "^2.1.4", | ||
| "tty": "1.0.1", | ||
| "typescript": "3.4.5", |
There was a problem hiding this comment.
I needed to upgrade TypeScript because 2.x wasn't able to follow some of the type inference shenanigans used by the builders.
| "dom", | ||
| "esnext.asynciterable", | ||
| "es2017" | ||
| ], |
There was a problem hiding this comment.
For consistency with the root tsconfig.json settings. This was necessary to successfully run tsc on preview-src/ outside of webpack, which I needed to do in order to run tests here.
I'm not sure why this tsconfig has a different target value than the root one, though? I feel like we should be able to have this one inherit from the other to stay consistent.
| import { Event, Disposable } from 'vscode'; | ||
| import { sep } from 'path'; | ||
| import * as moment from 'moment'; | ||
| import moment = require('moment'); |
There was a problem hiding this comment.
It took me a while to figure out the difference between import moment from 'moment', import * as moment from 'moment', and import moment = require('moment').
I believe this one's correct here (and the other places I've updated it) because of this section from the TypeScript docs:
When exporting a module using
export =, TypeScript-specificimport module = require("module")must be used to import the module.
|
|
||
| createGitHubRepository(remote: Remote, credentialStore: CredentialStore): GitHubRepository { | ||
| return new GitHubRepository(remote, credentialStore); | ||
| } |
There was a problem hiding this comment.
I believe sinon has the ability to mock a constructor, but it always feels too invasive for my tastes. (What if there's another instantiation somewhere on the stack that I don't want to mock?)
src/github/pullRequestOverview.ts
Outdated
| } | ||
| }); | ||
| }).catch(e => { | ||
| console.error(e.stack); |
There was a problem hiding this comment.
Oops. I'll delete this one.
| aChildProp: {linked: ChildBuilder}, | ||
| }); | ||
|
|
||
| describe('Builders', function () { |
There was a problem hiding this comment.
Fun fact: almost all of the actual complexity of the Builder tests is in getting them to typecheck. 🌠
| }); | ||
|
|
||
| await addTests(mocha, testsRoot); | ||
| await addTests(mocha, path.resolve(testsRoot, '../../preview-src/dist/preview-src/test')); |
There was a problem hiding this comment.
This needs to be a custom runner primarily so that we can add tests from preview-src/. It's also a convenient place to install the MockWebviewEnvironment.
| if [ ! -f media/extension.js ]; then | ||
| printf "Running webpack\n" | ||
| webpack --env.development | ||
| fi |
There was a problem hiding this comment.
☝️ This bit will be useful when we run in CI.
Fun fact: the tests are loaded from the tsc-compiled JavaScript emitted by this script, but the development extension that's loaded into the extension test host uses media/extension.ts, so they both need to exist.
|
Okay, merged in the changes from #1173 and got everything compiling and green again. Ready for review for reals this time 😄 |
…hub into aw/expand-tests
RMacfarlane
left a comment
There was a problem hiding this comment.
Sorry, I missed the bus in reviewing this!
| "files.trimTrailingWhitespace": true, | ||
| "editor.insertSpaces": false | ||
| "editor.insertSpaces": false, | ||
| "typescript.tsdk": "node_modules/typescript/lib" |
There was a problem hiding this comment.
I would revert this, I don't think we need this setting to be on for everyone developing this project
| }, | ||
| "dependencies": { | ||
| "@octokit/rest": "^16.21.0", | ||
| "@types/glob": "7.1.1", |
There was a problem hiding this comment.
this should be a dev dependency, right
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import * as Octokit from '@octokit/rest'; | ||
| import Octokit = require('@octokit/rest'); |
There was a problem hiding this comment.
For octokit, the module ships with a .d.ts typings file, so I think the normal import syntax is fine
Let's expand the scope of our test suite to cover more of the extension's functionality. I'm starting here to provide us with some immediate benefits:
Backfitting tests to existing code is tedious and time-consuming. My goal here isn't to get us to full coverage - mostly, I'm concerned with introducing a skeleton structure that lowers the barriers to adding tests organically as we work in the future. I'll call this PR "complete" once I have a test suite in place for a set of basis cases that cover the mocking needs of different parts of the codebase.
I'm also doing my best to minimize structural changes to the source. I'll likely need to change some things to make things more easily testable, but I'll endeavor to keep them small and scopes to keep this effort tractable and minimize risk.
Remaining
Modules that use the VSCode API. The primary concern here is being able to avoid collisions with globally-scoped resources like command IDs.
Modules that expect to use the network. Testing these effectively requires a way to succinctly mock GraphQL and REST responses.
Modules that use git operations. These rely on a way to mock git commands performed through the git extension's exported API.
Source that defines React components loaded within a Webview.
Integration tests that exercise the UI components contributed to VSCode, like the tree view and the status bar tiles.
Finally - general support infrastructure work:
*.gqlimports in Mocha tests.MockCommandRegistryduring initialization