Skip to content

Commit

Permalink
Update when we inject git data
Browse files Browse the repository at this point in the history
  • Loading branch information
yoannmoinet committed Jun 24, 2024
1 parent fb56bc8 commit e824eef
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/plugins/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const getGitPlugin = (options: Options, context: GlobalContext): Unplugin
enforce: 'pre',
async buildStart() {
// Verify that we should get the git information based on the options.
// Only get git information if git is not disabled.
const shouldGetGitInfo = options.disableGit !== true;
// Only get git information if sourcemaps are enabled and git is not disabled.
const shouldGetGitInfo = options.rum?.sourcemaps && options.disableGit !== true;

if (!shouldGetGitInfo) {
return;
Expand Down
29 changes: 27 additions & 2 deletions packages/tests/src/core/plugins/git/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { getRepositoryData } from '@dd/core/plugins/git/helpers';
import { getPlugins } from '@dd/telemetry-plugins';
import { defaultPluginOptions, getFetchMock, runBundlers } from '@dd/tests/helpers';
import { getSourcemapsConfiguration } from '@dd/tests/plugins/rum/testHelpers';

jest.mock('@dd/telemetry-plugins', () => {
const originalModule = jest.requireActual('@dd/telemetry-plugins');
Expand Down Expand Up @@ -35,13 +36,27 @@ const getRepositoryDataMocked = jest.mocked(getRepositoryData);

describe('Git Plugin', () => {
describe('It should run', () => {
test('by default and add the relevant data to the context.', async () => {
test('by default with sourcemaps.', async () => {
const pluginConfig = {
...defaultPluginOptions,
telemetry: {},
rum: {
sourcemaps: getSourcemapsConfiguration(),
},
};
const results = await runBundlers(pluginConfig);
expect(getRepositoryDataMocked).toHaveBeenCalledTimes(results.length);
});

test('and add the relevant data to the context.', async () => {
const pluginConfig = {
...defaultPluginOptions,
telemetry: {},
rum: {
sourcemaps: getSourcemapsConfiguration(),
},
};

await runBundlers(pluginConfig);

// Confirm every call gets the git data in the context.
for (const call of getPluginsMocked.mock.calls) {
Expand All @@ -52,9 +67,19 @@ describe('Git Plugin', () => {
});
});
describe('It should not run', () => {
test('by default without sourcemaps.', async () => {
const pluginConfig = {
...defaultPluginOptions,
};
await runBundlers(pluginConfig);
expect(getRepositoryDataMocked).not.toHaveBeenCalled();
});
test('if we disable it from the configuration', async () => {
const pluginConfig = {
...defaultPluginOptions,
rum: {
sourcemaps: getSourcemapsConfiguration(),
},
disableGit: true,
};
await runBundlers(pluginConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe('Global Context Plugin', () => {
config: expect.any(Object),
},
cwd: expect.any(String),
git: expect.any(Object),
version: expect.any(String),
});
}
Expand Down

0 comments on commit e824eef

Please sign in to comment.