Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more tests, use the Sourcegraph stubs api and improve repo matching. #13

Merged
merged 40 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
4b36175
add more tests, extend the mock API to test activate
vanesa Apr 23, 2019
90bed81
Update dependency @sourcegraph/tslint-config to ^13.1.0
renovate-bot Apr 26, 2019
4d26f4d
WIP: refactor to use extension api stubs
vanesa Apr 26, 2019
3665af2
remove wip
vanesa Apr 29, 2019
94af29b
Merge branch 'master' of github.com:sourcegraph/sourcegraph-sentry
vanesa Apr 29, 2019
2afb581
Update dependency sourcegraph to ^23.0.1
renovate-bot Apr 30, 2019
b28aeea
Add CI badge (#17)
felixfbecker Apr 30, 2019
dbbdb88
add more tests, extend the mock API to test activate
vanesa Apr 23, 2019
1a3dbc7
WIP: refactor to use extension api stubs
vanesa Apr 26, 2019
07a3693
add more tests, extend the mock API to test activate
vanesa Apr 23, 2019
f1a5fd0
WIP: refactor to use extension api stubs
vanesa Apr 26, 2019
b13e934
Merge branch 'vo/increase-test-coverage' of github.com:sourcegraph/so…
vanesa Apr 30, 2019
a40c7ca
fix tests
vanesa Apr 30, 2019
accbf41
update extension stubs package and tests
vanesa Apr 30, 2019
011c6ad
fix tests
vanesa May 1, 2019
0a0739b
refactor code, increase text coverage to 88%
vanesa May 8, 2019
c780656
improve repo matching with better repoMatch param, update tests
vanesa May 9, 2019
c58b093
update package.json and combineLatest implementation
vanesa May 9, 2019
d76f9cf
handle promises with beforeEach and await
vanesa May 9, 2019
d6b86c8
use URLSearchParams instead of encodeURIComponent
vanesa May 9, 2019
0c328e3
Update src/test/handler.test.ts wording
vanesa May 13, 2019
dfb48aa
Update src/test/handler.test.ts wording
vanesa May 13, 2019
c126f17
Update src/test/handler.test.ts wording
vanesa May 13, 2019
c089c03
Update src/test/extension.test.ts wording
vanesa May 13, 2019
6e27835
Update src/test/handler.test.ts wording
vanesa May 13, 2019
f00abd6
refactor based on code review
vanesa May 13, 2019
4480b93
refactor for better config structure and based on code review
vanesa May 15, 2019
9dc20f0
update test name, improve missing configs hover message
vanesa May 15, 2019
9294264
improve matching and add more tests
vanesa May 16, 2019
b959cf6
capture group after # in fileMatch regexp pattern
vanesa May 16, 2019
8fd14dc
improve hover messages
vanesa May 16, 2019
aa93c7a
update test and clean code
vanesa May 16, 2019
870178f
fix hover message matching
vanesa May 16, 2019
9c44d15
simplify repo matching, add tests, restructure configs
vanesa May 21, 2019
7a63ea7
update ReadMe
vanesa May 21, 2019
ddf84b1
fix prettier
vanesa May 21, 2019
e44aea3
Fix type of regexp properties in SentryProject
May 21, 2019
e8aca8a
Update src/handler.ts
lguychard May 21, 2019
d165eee
Use array.some, rename variables
May 21, 2019
622bf92
Add a return, remove a return
May 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 75 additions & 5 deletions src/test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ const sourcegraph = createMockSourcegraphAPI()
// For modules importing Range/Location/URI/etc
mock('sourcegraph', sourcegraph)
vanesa marked this conversation as resolved.
Show resolved Hide resolved

import { decorateEditor, decorateLine, getDecorations } from '../extension'
import { activate, decorateEditor, decorateLine, getDecorations } from '../extension'

describe('extension', () => {
it('works', () => void 0)
})
vanesa marked this conversation as resolved.
Show resolved Hide resolved

describe('check for extension activation', () => {
it('activate extension', () => expect(activate(sourcegraph.ExtensionContext)).toEqual(void 0))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works in that it checks that the extension's activate function does not crash when called. However it doesn't test much beyond that. I would add more comprehensive tests for the actual functionality, for instance:

  • The extension reacts to windows/editor changes and decorates editors accordingly
  • The extension reacts to configuration changes and decorates editors accordingly

vanesa marked this conversation as resolved.
Show resolved Hide resolved
})

const data = [
{
goal: 'render complete Sentry link',
Expand Down Expand Up @@ -41,6 +45,14 @@ const data = [
missingConfigData: ['repoMatch', 'fileMatch'],
sentryProjectId: undefined,
},
{
goal:
'match line based on common pattern, render warning link hinting to add projectId and render link to general issues page',
index: 1,
match: '',
missingConfigData: ['repoMatch', 'fileMatch'],
sentryProjectId: undefined,
},
]

const decorationsList = [
Expand Down Expand Up @@ -92,6 +104,17 @@ const decorationsList = [
linkURL: 'https://sentry.io/organizations/sourcegraph/issues/',
},
},
{
range: new sourcegraph.Range(1, 0, 1, 0),
isWholeLine: true,
after: {
backgroundColor: '#f2736d',
color: 'rgba(255, 255, 255, 0.8)',
contentText: ' View logs in Sentry (❕)» ',
hoverMessage: ' Add Sentry projects to your Sentry extension settings for project matching.',
linkURL: 'https://sentry.io/organizations/sourcegraph/issues/',
},
},
]

describe('decorate line', () => {
vanesa marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -144,13 +167,29 @@ const decorationsData = [
{
goal: 'receive no decoration due to no line matches',
documentUri:
'git://github.com/sourcegraph/sourcegraph?c436567c152bf40668c75815ed3ce62983af942d#client/browser/src/libs/github/file_info.php',
'git://github.com/sourcegraph/sourcegraph?c436567c152bf40668c75815ed3ce62983af942d#client/browser/src/libs/github/empty.ts',
documentText: `export const resolveDiffFileInfo = (codeView: HTMLElement): Observable<FileInfo> =>
of(codeView).pipe(
map(({ codeView, ...rest }) => {
const { headFilePath, baseFilePath } = getDeltaFileName(codeView)
}),`,
},
{
goal: 'receive no decoration due to empty textdocument',
documentUri:
'git://github.com/sourcegraph/sourcegraph?c436567c152bf40668c75815ed3ce62983af942d#client/browser/src/libs/github/file_info.php',
documentText: ``,
},
{
goal: 'receive one decoration on GitLab',
documentUri:
'git://gitlab.com/sourcegraph/sourcegraph?92a448bdda22fea9a422f37cf83d99edeaa7fe4c#client/browser/src/e2e/chrome.e2e.test.ts',
documentText: `if (!headFilePath) {
throw new Error('cannot determine file path')
}
return { ...rest, codeView, headFilePath, baseFilePath }
}),`,
},
]

const expectedDecorations = [
Expand Down Expand Up @@ -200,6 +239,23 @@ const expectedDecorations = [
[],
// receive no decoration due to no line matches
[],
// receive no decoration due to no textdocument
[],
// receive on decoration from GitLab
[
{
range: new sourcegraph.Range(1, 0, 1, 0),
isWholeLine: true,
after: {
backgroundColor: '#e03e2f',
color: 'rgba(255, 255, 255, 0.8)',
contentText: ' View logs in Sentry » ',
hoverMessage: ' View logs in Sentry » ',
linkURL:
'https://sentry.io/organizations/sourcegraph/issues/?project=1334031&query=is%3Aunresolved+cannot%20determine%20file%20path&statsPeriod=14d',
},
},
],
]

describe('get Decorations', () => {
Expand Down Expand Up @@ -235,14 +291,28 @@ const languageCode = [
logger.debug("failed to build URL");
err.printStackTrace();`,
},
{
lang: 'C++',
code: ` {
log_error("Exception occurred!");
throw;
}`,
},
]

describe('decorate Editor', () => {
vanesa marked this conversation as resolved.
Show resolved Hide resolved
projects[0].patternProperties.lineMatches = []
for (const [i, codeExample] of languageCode.entries()) {
it('check common pattern matching for ' + languageCode[i].lang, () =>
expect(decorateEditor([], codeExample.code)).toEqual([decorationsList[3]])
)
if (i < 4) {
vanesa marked this conversation as resolved.
Show resolved Hide resolved
it('check common pattern matching for ' + languageCode[i].lang, () =>
expect(decorateEditor([], codeExample.code)).toEqual([decorationsList[3]])
)
} else {
console.log(languageCode[i].lang)
it('should not render due to unsupported language ' + languageCode[i].lang, () =>
expect(decorateEditor([], codeExample.code)).toEqual([])
)
}
}
// set lineMatches back to original state for the other tests
projects[0].patternProperties.lineMatches = [
Expand Down
10 changes: 10 additions & 0 deletions src/test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class Range {
class Location {
constructor(public uri: URI, public range: Range) {}
}
export interface Unsubscribable {
vanesa marked this conversation as resolved.
Show resolved Hide resolved
unsubscribe(): void
}

/**
* Creates an object that (mostly) implements the Sourcegraph API,
* with all methods being Sinon spys and all Subscribables being Subjects.
Expand All @@ -40,9 +44,15 @@ export const createMockSourcegraphAPI = () => ({
projects,
},
}),
subscribe: (next: () => void) => void 0,
},
search: {},
commands: {},
ExtensionContext: {
subscriptions: {
add: () => createMockSourcegraphAPI().configuration.subscribe(() => void 0),
},
},
})

export let projects: SentryProject[] = [
Expand Down