-
-
Notifications
You must be signed in to change notification settings - Fork 20
feat(symbol-collector): Add symbol-collector target
#266
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
Changes from all commits
2cb1b15
208575c
205b795
d401e2f
7eaa941
01c98df
6e780f3
e3f4d6d
72488d6
5f3997b
2414f34
fbd8fba
4bf5add
c71ed5a
5a56941
553309f
f6faf72
186f00b
6d44b00
280bfcb
dd2f49d
9125c70
70b5a62
83b3d1b
78bf8d6
4c02ab0
02b125f
831abd0
e7940c1
69d379c
d177cdd
751deba
f6b4789
e0bbb33
872a7d5
06f53f0
58baf81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { stringToRegexp } from '../../utils/filters'; | ||
| import { parseFilterOptions, RawFilterOptions } from '../base'; | ||
|
|
||
| describe('parseFilterOptions', () => { | ||
| test('empty object', () => { | ||
| const rawFilters: RawFilterOptions = {}; | ||
| const parsedFilters = parseFilterOptions(rawFilters); | ||
| expect(parsedFilters).not.toHaveProperty('includeNames'); | ||
| expect(parsedFilters).not.toHaveProperty('excludeNames'); | ||
| }); | ||
|
|
||
| test('undefined properties', () => { | ||
|
iker-barriocanal marked this conversation as resolved.
|
||
| const rawFilters: RawFilterOptions = { | ||
| includeNames: undefined, | ||
| excludeNames: undefined, | ||
| }; | ||
| const parsedFilters = parseFilterOptions(rawFilters); | ||
| expect(parsedFilters).not.toHaveProperty('includeNames'); | ||
| expect(parsedFilters).not.toHaveProperty('excludeNames'); | ||
| }); | ||
|
|
||
| test('string properties', () => { | ||
| const stringFilter = '/testFilter/'; | ||
| const rawFilters: RawFilterOptions = { | ||
| includeNames: stringFilter, | ||
| }; | ||
| const parsedFilters = parseFilterOptions(rawFilters); | ||
| expect(parsedFilters.includeNames).toStrictEqual( | ||
| stringToRegexp(stringFilter) | ||
| ); | ||
| }); | ||
|
|
||
| test('regex properties', () => { | ||
| const regexFilter = stringToRegexp('/testFilter/'); | ||
| const rawFilters: RawFilterOptions = { | ||
| includeNames: regexFilter, | ||
| }; | ||
| const parsedFilters = parseFilterOptions(rawFilters); | ||
| expect(parsedFilters.includeNames).toStrictEqual(regexFilter); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| import { withTempDir } from '../../utils/files'; | ||
| import { NoneArtifactProvider } from '../../artifact_providers/none'; | ||
| import { checkExecutableIsPresent, spawnProcess } from '../../utils/system'; | ||
| import { SymbolCollector, SYM_COLLECTOR_BIN_NAME } from '../symbolCollector'; | ||
|
|
||
| jest.mock('../../utils/files'); | ||
| jest.mock('../../utils/system'); | ||
| jest.mock('fs', () => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may wanna lift the common |
||
| const original = jest.requireActual('fs'); | ||
| return { | ||
| ...original, | ||
| promises: { | ||
| mkdir: jest.fn(() => { | ||
| /** do nothing */ | ||
| }), | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| const customConfig = { | ||
| batchType: 'batchType', | ||
| bundleIdPrefix: 'bundleIdPrefix-', | ||
| }; | ||
|
|
||
| function getSymbolCollectorInstance( | ||
| config: Record<string, unknown> = { testKey: 'testVal' } | ||
| ): SymbolCollector { | ||
| return new SymbolCollector( | ||
| { | ||
| name: 'symbol-collector', | ||
| ...config, | ||
| }, | ||
| new NoneArtifactProvider() | ||
| ); | ||
| } | ||
|
|
||
| describe('target config', () => { | ||
| test('symbol collector not present in path', () => { | ||
| (checkExecutableIsPresent as jest.MockedFunction< | ||
| typeof checkExecutableIsPresent | ||
| >).mockImplementationOnce(() => { | ||
| throw new Error('Checked for executable'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would have been better to make the executable path configurable and make sure we actually throw on a missing file. |
||
| }); | ||
|
|
||
| expect(getSymbolCollectorInstance).toThrowErrorMatchingInlineSnapshot( | ||
| `"Checked for executable"` | ||
| ); | ||
| expect(checkExecutableIsPresent).toHaveBeenCalledTimes(1); | ||
| expect(checkExecutableIsPresent).toHaveBeenCalledWith( | ||
| SYM_COLLECTOR_BIN_NAME | ||
| ); | ||
| }); | ||
|
|
||
| test('config missing', () => { | ||
| (checkExecutableIsPresent as jest.MockedFunction< | ||
| typeof checkExecutableIsPresent | ||
| >) = jest.fn(); | ||
|
|
||
| expect(getSymbolCollectorInstance).toThrowErrorMatchingInlineSnapshot( | ||
| '"The required `batchType` parameter is missing in the configuration file. ' + | ||
| 'See the documentation for more details."' | ||
| ); | ||
| expect(checkExecutableIsPresent).toHaveBeenCalledTimes(1); | ||
| expect(checkExecutableIsPresent).toHaveBeenCalledWith( | ||
| SYM_COLLECTOR_BIN_NAME | ||
| ); | ||
|
iker-barriocanal marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| test('symbol collector present and config ok', () => { | ||
| (checkExecutableIsPresent as jest.MockedFunction< | ||
| typeof checkExecutableIsPresent | ||
| >) = jest.fn(); | ||
|
|
||
| const symCollector = getSymbolCollectorInstance(customConfig); | ||
| const actualConfig = symCollector.symbolCollectorConfig; | ||
| expect(checkExecutableIsPresent).toHaveBeenCalledTimes(1); | ||
| expect(checkExecutableIsPresent).toHaveBeenLastCalledWith( | ||
| SYM_COLLECTOR_BIN_NAME | ||
| ); | ||
| expect(actualConfig).toHaveProperty('serverEndpoint'); | ||
| expect(actualConfig).toHaveProperty('batchType'); | ||
| expect(actualConfig).toHaveProperty('bundleIdPrefix'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('publish', () => { | ||
| test('no artifacts found', () => { | ||
| const symCollector = getSymbolCollectorInstance(customConfig); | ||
| symCollector.getArtifactsForRevision = jest | ||
| .fn() | ||
| .mockReturnValueOnce(() => []); | ||
| expect(spawnProcess).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test('with artifacts', async () => { | ||
| (withTempDir as jest.MockedFunction<typeof withTempDir>).mockImplementation( | ||
| async cb => await cb('tmpDir') | ||
| ); | ||
| (spawnProcess as jest.MockedFunction< | ||
| typeof spawnProcess | ||
| >).mockImplementation(() => Promise.resolve(undefined)); | ||
|
|
||
| const mockedArtifacts = ['artifact1', 'artifact2', 'artifact3']; | ||
|
|
||
| const symCollector = getSymbolCollectorInstance(customConfig); | ||
| symCollector.getArtifactsForRevision = jest | ||
| .fn() | ||
| .mockReturnValueOnce(mockedArtifacts); | ||
| symCollector.artifactProvider.downloadArtifact = jest.fn(); | ||
|
|
||
| await symCollector.publish('version', 'revision'); | ||
|
|
||
| expect(symCollector.getArtifactsForRevision).toHaveBeenCalledTimes(1); | ||
| expect( | ||
| symCollector.artifactProvider.downloadArtifact | ||
| ).toHaveBeenCalledTimes(mockedArtifacts.length); | ||
|
|
||
| expect(spawnProcess).toHaveBeenCalledTimes(1); | ||
| const [cmd, args] = (spawnProcess as jest.MockedFunction< | ||
| typeof spawnProcess | ||
| >).mock.calls[0] as string[]; | ||
| expect(cmd).toBe(SYM_COLLECTOR_BIN_NAME); | ||
| expect(args).toMatchInlineSnapshot(` | ||
|
iker-barriocanal marked this conversation as resolved.
|
||
| Array [ | ||
| "--upload", | ||
| "directory", | ||
| "--path", | ||
| "tmpDir", | ||
| "--batch-type", | ||
| "batchType", | ||
| "--bundle-id", | ||
| "bundleIdPrefix-version", | ||
| "--server-endpoint", | ||
| "https://symbol-collector.services.sentry.io/", | ||
| ] | ||
| `); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.