New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@servicetitan/component-usage

Package Overview
Dependencies
Maintainers
7
Versions
232
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@servicetitan/component-usage - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

dist/cli.d.ts

217

__tests__/component-usage.test.js
'use strict';
const componentUsage = require('..');
const { initialize } = require('dogapi');
describe('@servicetitan/component-usage', () => {
it('needs tests');
const realProcess = process;
let exitMock;
const realConsole = console;
let errorMock;
let logMock;
beforeEach(() => {
exitMock = jest.fn();
global.process = { ...realProcess, exit: exitMock };
errorMock = jest.fn();
logMock = jest.fn();
global.console = { ...realConsole, error: errorMock, log: logMock };
});
afterEach(() => {
global.process = realProcess;
global.console = realConsole;
jest.resetModules()
});
describe('generateDependencyReport', () => {
it('should process.exit(2) on error', () => {
jest.mock('@segment/dependency-report', () => {
return jest.fn().mockImplementation(() => {
return Promise.reject()
})
});
const { generateDependencyReport } = require('../dist/index.js');
expect.assertions(1);
return generateDependencyReport().catch(() => {
expect(exitMock).toHaveBeenCalledWith(2);
})
});
});
describe('convertReportToTreemap', () => {
it('should convert the report format to a treemap', () => {
const { convertReportToTreemap } = require('../dist/index.js');
const report = {
getPackages: () => {
return [
{
name: 'mockPackageOne',
filepathsForExports: { export1: ['path1'], export2: ['path2'] }
},
{
name: 'mockPackageTwo',
filepathsForExports: { export10: ['path10', 'path20'] }
},
]
}
};
const treemap = {
mockPackageOne: {
export1: {
path1: {},
},
export2: {
path2: {},
},
},
mockPackageTwo: {
export10: {
path10: {},
path20: {},
}
}
};
expect(convertReportToTreemap(report)).toEqual(treemap);
});
});
describe('convertTreeToFoamTree', () => {
it('should convert a simple tree to the right format', () => {
const { convertTreeToFoamTree } = require('../dist/index.js');
const tree = { a: { b: {}, c: {}, } };
const foamTree = {
label: 'root',
weight: 2,
groups: [{
label: 'a',
weight: 2,
groups: [
{
label: 'b',
weight: 1,
groups: [],
},
{
label: 'c',
weight: 1,
groups: [],
}
]
}]
};
expect(convertTreeToFoamTree(tree)).toEqual(foamTree);
});
});
describe('collapseTree', () => {
it('should collapse a simple tree correctly', () => {
const { collapseTree } = require('../dist/index.js');
const tree = {
a: {
b: {
c: {},
d: {},
},
e: {
f: {
g: {}
}
}
}
};
const collapsedTree = {
a: {
b: {
c: {},
d: {},
},
'e/f/g': {}
}
};
expect(collapseTree(tree)).toEqual(collapsedTree);
})
});
describe('generateMetrics', () => {
it('should generate the right metrics and output to TeamCity log', () => {
const { generateMetrics } = require('../dist/index.js');
const report = {
getPackages: () => {
return [
{
name: 'mockPackageOne',
filepathsForExports: { export1: ['path1'], export2: ['path2'] }
},
]
}
};
const options = {
branchName: 'mockBranch'
};
const metrics = [
{
metric: 'far.test.componentUsage.v2',
metric_type: 'count',
points: [[Math.floor(Date.now() / 1000), 1]],
tags: ['branch:mockBranch', 'package:mockPackageOne', 'component:export1']
},
{
metric: 'far.test.componentUsage.v2',
metric_type: 'count',
points: [[Math.floor(Date.now() / 1000), 1]],
tags: ['branch:mockBranch', 'package:mockPackageOne', 'component:export2']
},
{
metric: 'far.test.componentUsage.v2',
metric_type: 'count',
points: [[Math.floor(Date.now() / 1000), 2]],
tags: ['branch:mockBranch', 'package:mockPackageOne', 'component:__all__']
},
];
//test the function output
expect(generateMetrics(report, options)).toEqual(metrics);
//test the console output that writes to TeacmCity's statistics
expect(logMock).toHaveBeenCalledWith("##teamcity[buildStatisticValue key='component-usage-mockPackageOne' value='2']");
});
});
describe('sendMetrics', () => {
it('should initialize the data dog api', () => {
jest.mock('dogapi');
const dogMock = require('dogapi');
const { sendMetrics } = require('../dist/index.js');
sendMetrics([], 'mockApiKey', 'mockAppKey');
expect(dogMock.initialize).toHaveBeenCalledWith({ api_key: 'mockApiKey', app_key: 'mockAppKey' });
})
it('should send the metrics', () => {
jest.mock('dogapi');
const dogMock = require('dogapi');
const { sendMetrics } = require('../dist/index.js');
sendMetrics(['mockMetric'], 'mockApiKey', 'mockAppKey');
// first and only call should have the metrics as the first arg
expect(dogMock.metric.send_all).toHaveBeenCalledTimes(1);
expect(dogMock.metric.send_all.mock.calls[0][0]).toEqual(['mockMetric']);
});
})
});

11

package.json
{
"name": "@servicetitan/component-usage",
"version": "0.0.7",
"version": "0.0.8",
"description": "Usage metrics of @servicetitan components",

@@ -11,6 +11,6 @@ "homepage": "https://docs.st.dev/docs/frontend/component-usage",

},
"main": "src/index.js",
"bin": "src/cli.js",
"main": "dist/index.js",
"bin": "dist/cli.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest"
},

@@ -27,3 +27,6 @@ "author": "Brett Schellenberg",

"access": "restricted"
},
"devDependencies": {
"jest": "^26.4.2"
}
}
#!/usr/bin/env node
const commandLineArgs = require('command-line-args')
const commandLineUsage = require('command-line-usage')
const { run } = require('./index.js');

@@ -40,2 +41,8 @@ const optionDefinitionsTop = [

{
name: 'verbose',
description: "Displays extra information for debugging",
alias: 'v',
type: Boolean
},
{
name: 'help',

@@ -70,3 +77,5 @@ description: "Displays this menu",

console.log(options);
if (options.verbose) {
console.log(options);
}

@@ -84,4 +93,2 @@ if (help ||

const run = require('./index.js');
run(options);
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc