From f91d0d9f251dae75c75c15afcae55da01d120d1e Mon Sep 17 00:00:00 2001 From: sparshithNR Date: Wed, 9 Jun 2021 09:32:53 -0700 Subject: [PATCH 1/9] Add cli option to ignore certain dependencies This will enable project to ignore libraries while running the supported tool --- lib/cli.js | 8 +++++++- lib/help.js | 1 + lib/project/multiple-projects.js | 6 +++--- lib/util.js | 5 +++-- tests/cli-test.js | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 1143583..d6a3824 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -19,6 +19,7 @@ async function main(cli, { policyDetails, setupProjectFn }) { cli.showHelp(1); } else { const currentDate = processDate(cli.flags.currentDate) || undefined; + const ignoredDependencies = cli.flags.ignoredDependencies || []; let policies = { primary: DEFAULT_PRIMARY_POLICY, @@ -52,7 +53,7 @@ async function main(cli, { policyDetails, setupProjectFn }) { let result; let processed = false; try { - result = await processPolicies(projectPaths, setupProjectFn, spinner, currentDate, policies); + result = await processPolicies(projectPaths, setupProjectFn, spinner, currentDate, policies, ignoredDependencies); if (result.isInSupportWindow === false) { process.exitCode = 1; } @@ -121,6 +122,11 @@ async function run( type: 'string', alias: 'f', }, + ignoredDependencies: { + type: 'string', + alias: 'i', + isMultiple: true, + }, }, }), { policyDetails, setupProjectFn }, diff --git a/lib/help.js b/lib/help.js index dea346d..b98c92f 100644 --- a/lib/help.js +++ b/lib/help.js @@ -19,6 +19,7 @@ module.exports = (commandName = 'supported', packageLink = pkg.homepage) => { {cyan --csv} outputs csv file in the project path {cyan --current-date, -c} optional current date to use when calculating support {cyan --config-file, -f} optional config file to override the default setup + {cyan --ignored-dependencies, -i} optional list of dependencies to be ignored while running the policy, ex: -r 'test','tester' {bold Examples} {gray $} {cyan ${commandName} ./path/to/project/} `; diff --git a/lib/project/multiple-projects.js b/lib/project/multiple-projects.js index 6dce394..87517df 100644 --- a/lib/project/multiple-projects.js +++ b/lib/project/multiple-projects.js @@ -10,7 +10,7 @@ const { ProgressLogger } = require('../util'); const DEFAULT_SETUP_FILE = './setup-project'; module.exports.processPolicies = processPolicies; -async function processPolicies(projectPaths, setupProjectFn, spinner, today, policies) { +async function processPolicies(projectPaths, setupProjectFn, spinner, today, policies, ignoredDependencies) { const setupProject = setupProjectFn ? setupProjectFn : require(DEFAULT_SETUP_FILE); let result = { isInSupportWindow: true, @@ -25,14 +25,14 @@ async function processPolicies(projectPaths, setupProjectFn, spinner, today, pol concurrency: os.cpus().length, }); let isMultipleProduct = projectPaths.length > 1; - let progressLogger = new ProgressLogger(spinner, isMultipleProduct); + let progressLogger = new ProgressLogger(spinner, isMultipleProduct, ignoredDependencies.length); for (const projectPath of projectPaths) { work.push( queue.add(async () => { let { dependenciesToCheck, pkg } = await setupProject(projectPath); progressLogger.updateTotalDepCount(dependenciesToCheck.length); let auditResult = await isInSupportWindow( - dependenciesToCheck, + dependenciesToCheck.filter(dep => !ignoredDependencies.includes(dep.name)), pkg.name, { progressLogger, diff --git a/lib/util.js b/lib/util.js index 4f83164..6cb1da3 100644 --- a/lib/util.js +++ b/lib/util.js @@ -91,12 +91,13 @@ function sortLibraries(a, b) { } module.exports.ProgressLogger = class ProgressLogger { - constructor(_spinner = { prefixText: '', text: '' }, _isMultipleProduct) { + constructor(_spinner = { prefixText: '', text: '' }, _isMultipleProduct = false, _ignoredPackages = 0) { this.spinner = _spinner; this.totalPackages = 0; // start from `1` as we have node policy tested all the time this.processedCount = 0; this.semVerLogged = false; this.isMultipleProduct = _isMultipleProduct; + this.ignoredPackages = _ignoredPackages; } getLoggerPrefixText(name, isSupported, isExpiringSoon) { @@ -141,7 +142,7 @@ module.exports.ProgressLogger = class ProgressLogger { } this.spinner.text = `Total Dependencies: ${this.totalPackages}, Verified: ${ this.processedCount - }, Remaining: ${this.totalPackages - this.processedCount}`; + }, Remaining: ${this.totalPackages - this.processedCount - this.ignoredPackages}, Ignored: ${this.ignoredPackages}`; if (this.totalPackages > this.processedCount) { this.processedCount++; } diff --git a/tests/cli-test.js b/tests/cli-test.js index b3407ce..c0639d2 100644 --- a/tests/cli-test.js +++ b/tests/cli-test.js @@ -180,6 +180,38 @@ describe('CLI', function () { }); }); + describe(`--ignore-dependencies`, function() { + it('check console log', async function () { + const child = await runSupportedCmd([ + `${__dirname}/fixtures/supported-project`, + `--ignored-dependencies @stefanpenner/a`, + `-i rsvp`, + ]); + + expect(child).to.exitGracefully(); + expect(child.stderr).to.includes(`Ignored: 2`); + expect(child.stderr).to.includes('✓ SemVer Policy'); + expect(child.stdout).to.includes('Congrats!'); + }); + + it('check if verbose do not incude the entry', async function () { + const child = await runSupportedCmd([ + `${__dirname}/fixtures/supported-project`, + `--ignored-dependencies @stefanpenner/a`, + `-i rsvp`, + '--verbose', + ]); + + expect(child).to.exitGracefully(); + expect(child.stderr).to.includes(`Ignored: 2`); + expect(child.stderr).to.includes('✓ SemVer Policy'); + expect(child.stdout).to.includes('Congrats!'); + expect(child.stdout).not.include( + '@stefanpenner/a 1.0.3 2.0.0 major', + ); + }); + }); + describe('Filter options like --unsupported/expiring/supported', function () { it('works against a unsupported project with --unsupported option', async function () { const child = await runSupportedCmd([ From e3eb2bfa58e18c71d8b6511335df6fa31d12f038 Mon Sep 17 00:00:00 2001 From: sparshithNR Date: Wed, 9 Jun 2021 09:51:02 -0700 Subject: [PATCH 2/9] correct the ignore count when dep is not present. --- lib/project/multiple-projects.js | 6 ++++-- lib/util.js | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/project/multiple-projects.js b/lib/project/multiple-projects.js index 87517df..2409bac 100644 --- a/lib/project/multiple-projects.js +++ b/lib/project/multiple-projects.js @@ -25,14 +25,16 @@ async function processPolicies(projectPaths, setupProjectFn, spinner, today, pol concurrency: os.cpus().length, }); let isMultipleProduct = projectPaths.length > 1; - let progressLogger = new ProgressLogger(spinner, isMultipleProduct, ignoredDependencies.length); + let progressLogger = new ProgressLogger(spinner, isMultipleProduct); for (const projectPath of projectPaths) { work.push( queue.add(async () => { let { dependenciesToCheck, pkg } = await setupProject(projectPath); + let dependenciesToCheckAfterIgnore = dependenciesToCheck.filter(dep => !ignoredDependencies.includes(dep.name)); progressLogger.updateTotalDepCount(dependenciesToCheck.length); + progressLogger.updateIgnoredDepCount(dependenciesToCheck.length - dependenciesToCheckAfterIgnore.length); let auditResult = await isInSupportWindow( - dependenciesToCheck.filter(dep => !ignoredDependencies.includes(dep.name)), + dependenciesToCheckAfterIgnore, pkg.name, { progressLogger, diff --git a/lib/util.js b/lib/util.js index 6cb1da3..32aefaa 100644 --- a/lib/util.js +++ b/lib/util.js @@ -91,13 +91,13 @@ function sortLibraries(a, b) { } module.exports.ProgressLogger = class ProgressLogger { - constructor(_spinner = { prefixText: '', text: '' }, _isMultipleProduct = false, _ignoredPackages = 0) { + constructor(_spinner = { prefixText: '', text: '' }, _isMultipleProduct = false) { this.spinner = _spinner; this.totalPackages = 0; // start from `1` as we have node policy tested all the time this.processedCount = 0; this.semVerLogged = false; this.isMultipleProduct = _isMultipleProduct; - this.ignoredPackages = _ignoredPackages; + this.ignoredPackages = 0; } getLoggerPrefixText(name, isSupported, isExpiringSoon) { @@ -124,6 +124,10 @@ module.exports.ProgressLogger = class ProgressLogger { this.totalPackages += count; } + updateIgnoredDepCount(count) { + this.ignoredPackages = count; + } + updateSpinner(name, isSupported, isExpiringSoon) { if (name && !this.isMultipleProduct) { if (!this.spinner.prefixText) { From 00c1ee23a2b9ffd0ca24a9695c7a48780e928f6b Mon Sep 17 00:00:00 2001 From: sparshithNR Date: Wed, 9 Jun 2021 10:02:47 -0700 Subject: [PATCH 3/9] Fix eslint --- lib/cli.js | 9 ++++++++- lib/project/multiple-projects.js | 8 ++++++-- lib/util.js | 4 +++- tests/cli-test.js | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index d6a3824..6c9da8f 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -53,7 +53,14 @@ async function main(cli, { policyDetails, setupProjectFn }) { let result; let processed = false; try { - result = await processPolicies(projectPaths, setupProjectFn, spinner, currentDate, policies, ignoredDependencies); + result = await processPolicies( + projectPaths, + setupProjectFn, + spinner, + currentDate, + policies, + ignoredDependencies, + ); if (result.isInSupportWindow === false) { process.exitCode = 1; } diff --git a/lib/project/multiple-projects.js b/lib/project/multiple-projects.js index 2409bac..933007e 100644 --- a/lib/project/multiple-projects.js +++ b/lib/project/multiple-projects.js @@ -30,9 +30,13 @@ async function processPolicies(projectPaths, setupProjectFn, spinner, today, pol work.push( queue.add(async () => { let { dependenciesToCheck, pkg } = await setupProject(projectPath); - let dependenciesToCheckAfterIgnore = dependenciesToCheck.filter(dep => !ignoredDependencies.includes(dep.name)); + let dependenciesToCheckAfterIgnore = dependenciesToCheck.filter( + dep => !ignoredDependencies.includes(dep.name), + ); progressLogger.updateTotalDepCount(dependenciesToCheck.length); - progressLogger.updateIgnoredDepCount(dependenciesToCheck.length - dependenciesToCheckAfterIgnore.length); + progressLogger.updateIgnoredDepCount( + dependenciesToCheck.length - dependenciesToCheckAfterIgnore.length, + ); let auditResult = await isInSupportWindow( dependenciesToCheckAfterIgnore, pkg.name, diff --git a/lib/util.js b/lib/util.js index 32aefaa..0dc658c 100644 --- a/lib/util.js +++ b/lib/util.js @@ -146,7 +146,9 @@ module.exports.ProgressLogger = class ProgressLogger { } this.spinner.text = `Total Dependencies: ${this.totalPackages}, Verified: ${ this.processedCount - }, Remaining: ${this.totalPackages - this.processedCount - this.ignoredPackages}, Ignored: ${this.ignoredPackages}`; + }, Remaining: ${this.totalPackages - this.processedCount - this.ignoredPackages}, Ignored: ${ + this.ignoredPackages + }`; if (this.totalPackages > this.processedCount) { this.processedCount++; } diff --git a/tests/cli-test.js b/tests/cli-test.js index c0639d2..8b21496 100644 --- a/tests/cli-test.js +++ b/tests/cli-test.js @@ -180,7 +180,7 @@ describe('CLI', function () { }); }); - describe(`--ignore-dependencies`, function() { + describe(`--ignore-dependencies`, function () { it('check console log', async function () { const child = await runSupportedCmd([ `${__dirname}/fixtures/supported-project`, From 4c8df234dbabf5c9d49414a895173bdddd5d61d8 Mon Sep 17 00:00:00 2001 From: sparshithNR Date: Wed, 23 Jun 2021 10:53:49 -0700 Subject: [PATCH 4/9] Read ignoreDep from config file --- lib/cli.js | 8 +++- tests/cli-test.js | 40 ++++++++++++++----- .../config-ignore-dep.json | 5 +++ 3 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 tests/fixtures/unsupported-project/config-ignore-dep.json diff --git a/lib/cli.js b/lib/cli.js index 6c9da8f..6907ee7 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -19,7 +19,7 @@ async function main(cli, { policyDetails, setupProjectFn }) { cli.showHelp(1); } else { const currentDate = processDate(cli.flags.currentDate) || undefined; - const ignoredDependencies = cli.flags.ignoredDependencies || []; + let ignoredDependencies = cli.flags.ignoredDependencies || []; let policies = { primary: DEFAULT_PRIMARY_POLICY, @@ -29,6 +29,7 @@ async function main(cli, { policyDetails, setupProjectFn }) { let configuredPolicies = JSON.parse(configFile); if (configuredPolicies.primary) { policies.primary = configuredPolicies.primary; + ignoredDependencies = configuredPolicies.primary.ignoredDependencies || ignoredDependencies; } if (configuredPolicies.custom) { policies.custom = {}; @@ -39,6 +40,11 @@ async function main(cli, { policyDetails, setupProjectFn }) { `The dependency ${dep} was found multiple times in the config file. Please refer Rules section in configuration.md`, ); } + if (ignoredDependencies.includes(dep)) { + throw new Error( + `The dependency ${dep} was found in ignoredDependencies and custom configuration. Please refer Rules section in configuration.md`, + ); + } policies.custom[dep] = { upgradeBudget: policy.upgradeBudget, effectiveReleaseDate: diff --git a/tests/cli-test.js b/tests/cli-test.js index 8b21496..1c09051 100644 --- a/tests/cli-test.js +++ b/tests/cli-test.js @@ -210,6 +210,16 @@ describe('CLI', function () { '@stefanpenner/a 1.0.3 2.0.0 major', ); }); + + it('make unsupported to supported project using ignoreDependency config', async function () { + const child = await runSupportedCmd([ + `${__dirname}/fixtures/unsupported-project`, + `-f ${__dirname}/fixtures/unsupported-project/config-ignore-dep.json`, + ]); + + expect(child).to.exitGracefully(); + expect(child.stderr).to.includes('✓ SemVer Policy'); + }); }); describe('Filter options like --unsupported/expiring/supported', function () { @@ -396,6 +406,7 @@ describe('CLI', function () { }); }); }); + describe('--config-file', function () { it('make unsupported to supported project using effectiveReleaseDate', async function () { const child = await runSupportedCmd([ @@ -406,6 +417,7 @@ describe('CLI', function () { expect(child).to.exitGracefully(); expect(child.stderr).to.includes('✓ SemVer Policy'); }); + it('make unsupported to supported project using upgradeBudget', async function () { const child = await runSupportedCmd([ `${__dirname}/fixtures/unsupported-project`, @@ -417,16 +429,24 @@ describe('CLI', function () { }); it('alert user when there is conflicting custom config', async function () { - try { - await runSupportedCmd([ - `${__dirname}/fixtures/unsupported-project`, - `-f ${__dirname}/fixtures/unsupported-project/config-conflict.json`, - ]); - } catch (e) { - expect(e).includes( - `The dependency es6-promise was found multiple times in the config file. Please refer Rules section in configuration.md`, - ); - } + const child = await runSupportedCmd([ + `${__dirname}/fixtures/unsupported-project`, + `-f ${__dirname}/fixtures/unsupported-project/config-conflict.json`, + ]); + expect(child.stderr).includes( + `The dependency es6-promise was found multiple times in the config file. Please refer Rules section in configuration.md`, + ); + }); + + it('alert user when there is conflict in custom config and ignoredDependency', async function () { + const child = await runSupportedCmd([ + `${__dirname}/fixtures/unsupported-project`, + `-f ${__dirname}/fixtures/unsupported-project/config.json`, + `-i es6-promise`, + ]); + expect(child.stderr).includes( + `The dependency es6-promise was found in ignoredDependencies and custom configuration. Please refer Rules section in configuration.md`, + ); }); }); }); diff --git a/tests/fixtures/unsupported-project/config-ignore-dep.json b/tests/fixtures/unsupported-project/config-ignore-dep.json new file mode 100644 index 0000000..d9fd92d --- /dev/null +++ b/tests/fixtures/unsupported-project/config-ignore-dep.json @@ -0,0 +1,5 @@ +{ + "primary": { + "ignoredDependencies": ["es6-promise", "@stefanpenner/a", "rsvp"] + } +} \ No newline at end of file From e93cc64c6b52ca9de1c42256acd2653ad6603f07 Mon Sep 17 00:00:00 2001 From: sparshithNR Date: Wed, 23 Jun 2021 10:56:31 -0700 Subject: [PATCH 5/9] Lint issue fix --- lib/project/multiple-projects.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/project/multiple-projects.js b/lib/project/multiple-projects.js index 933007e..bf20c4f 100644 --- a/lib/project/multiple-projects.js +++ b/lib/project/multiple-projects.js @@ -10,7 +10,14 @@ const { ProgressLogger } = require('../util'); const DEFAULT_SETUP_FILE = './setup-project'; module.exports.processPolicies = processPolicies; -async function processPolicies(projectPaths, setupProjectFn, spinner, today, policies, ignoredDependencies) { +async function processPolicies( + projectPaths, + setupProjectFn, + spinner, + today, + policies, + ignoredDependencies, +) { const setupProject = setupProjectFn ? setupProjectFn : require(DEFAULT_SETUP_FILE); let result = { isInSupportWindow: true, From c8a807a501f8db5ac70b765e8f30cb8a0b019d23 Mon Sep 17 00:00:00 2001 From: sparshithNR Date: Wed, 23 Jun 2021 11:43:32 -0700 Subject: [PATCH 6/9] merge the ignoreDep from cli and config then dedup --- lib/cli.js | 7 ++++++- tests/cli-test.js | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/cli.js b/lib/cli.js index 6907ee7..cc9cf79 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -29,7 +29,9 @@ async function main(cli, { policyDetails, setupProjectFn }) { let configuredPolicies = JSON.parse(configFile); if (configuredPolicies.primary) { policies.primary = configuredPolicies.primary; - ignoredDependencies = configuredPolicies.primary.ignoredDependencies || ignoredDependencies; + if (configuredPolicies.primary.ignoredDependencies) { + ignoredDependencies.push(...configuredPolicies.primary.ignoredDependencies); + } } if (configuredPolicies.custom) { policies.custom = {}; @@ -55,6 +57,9 @@ async function main(cli, { policyDetails, setupProjectFn }) { } } + // dedup ignoredDependencies + ignoredDependencies = [...new Set(ignoredDependencies)]; + const spinner = ora('working').start(); let result; let processed = false; diff --git a/tests/cli-test.js b/tests/cli-test.js index 1c09051..c49976f 100644 --- a/tests/cli-test.js +++ b/tests/cli-test.js @@ -220,6 +220,18 @@ describe('CLI', function () { expect(child).to.exitGracefully(); expect(child.stderr).to.includes('✓ SemVer Policy'); }); + + it('ignoredDependencies merged from cli and config', async function () { + const child = await runSupportedCmd([ + `${__dirname}/fixtures/unsupported-project`, + `-f ${__dirname}/fixtures/unsupported-project/config-ignore-dep.json`, + `-i @eslint-ast/eslint-plugin-graphql`, + `-i es6-promise`, + ]); + + expect(child).to.exitGracefully(); + expect(child.stderr).to.includes('Ignored: 4'); + }); }); describe('Filter options like --unsupported/expiring/supported', function () { From 15e7c773a75731f4a51f7149604434bb9953757b Mon Sep 17 00:00:00 2001 From: sparshithNR Date: Wed, 23 Jun 2021 13:47:02 -0700 Subject: [PATCH 7/9] Remove cli option to ignore dep --- lib/cli.js | 11 +---- lib/help.js | 1 - tests/cli-test.js | 49 ++----------------- ...onfig_2.json => config-custom-budget.json} | 0 .../config-ignore-dep-conflict.json | 11 +++++ 5 files changed, 15 insertions(+), 57 deletions(-) rename tests/fixtures/unsupported-project/{config_2.json => config-custom-budget.json} (100%) create mode 100644 tests/fixtures/unsupported-project/config-ignore-dep-conflict.json diff --git a/lib/cli.js b/lib/cli.js index cc9cf79..1617ac5 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -19,8 +19,7 @@ async function main(cli, { policyDetails, setupProjectFn }) { cli.showHelp(1); } else { const currentDate = processDate(cli.flags.currentDate) || undefined; - let ignoredDependencies = cli.flags.ignoredDependencies || []; - + const ignoredDependencies = []; let policies = { primary: DEFAULT_PRIMARY_POLICY, }; @@ -57,9 +56,6 @@ async function main(cli, { policyDetails, setupProjectFn }) { } } - // dedup ignoredDependencies - ignoredDependencies = [...new Set(ignoredDependencies)]; - const spinner = ora('working').start(); let result; let processed = false; @@ -140,11 +136,6 @@ async function run( type: 'string', alias: 'f', }, - ignoredDependencies: { - type: 'string', - alias: 'i', - isMultiple: true, - }, }, }), { policyDetails, setupProjectFn }, diff --git a/lib/help.js b/lib/help.js index b98c92f..dea346d 100644 --- a/lib/help.js +++ b/lib/help.js @@ -19,7 +19,6 @@ module.exports = (commandName = 'supported', packageLink = pkg.homepage) => { {cyan --csv} outputs csv file in the project path {cyan --current-date, -c} optional current date to use when calculating support {cyan --config-file, -f} optional config file to override the default setup - {cyan --ignored-dependencies, -i} optional list of dependencies to be ignored while running the policy, ex: -r 'test','tester' {bold Examples} {gray $} {cyan ${commandName} ./path/to/project/} `; diff --git a/tests/cli-test.js b/tests/cli-test.js index c49976f..453c25e 100644 --- a/tests/cli-test.js +++ b/tests/cli-test.js @@ -180,37 +180,7 @@ describe('CLI', function () { }); }); - describe(`--ignore-dependencies`, function () { - it('check console log', async function () { - const child = await runSupportedCmd([ - `${__dirname}/fixtures/supported-project`, - `--ignored-dependencies @stefanpenner/a`, - `-i rsvp`, - ]); - - expect(child).to.exitGracefully(); - expect(child.stderr).to.includes(`Ignored: 2`); - expect(child.stderr).to.includes('✓ SemVer Policy'); - expect(child.stdout).to.includes('Congrats!'); - }); - - it('check if verbose do not incude the entry', async function () { - const child = await runSupportedCmd([ - `${__dirname}/fixtures/supported-project`, - `--ignored-dependencies @stefanpenner/a`, - `-i rsvp`, - '--verbose', - ]); - - expect(child).to.exitGracefully(); - expect(child.stderr).to.includes(`Ignored: 2`); - expect(child.stderr).to.includes('✓ SemVer Policy'); - expect(child.stdout).to.includes('Congrats!'); - expect(child.stdout).not.include( - '@stefanpenner/a 1.0.3 2.0.0 major', - ); - }); - + describe(`ignore-dependencies`, function () { it('make unsupported to supported project using ignoreDependency config', async function () { const child = await runSupportedCmd([ `${__dirname}/fixtures/unsupported-project`, @@ -220,18 +190,6 @@ describe('CLI', function () { expect(child).to.exitGracefully(); expect(child.stderr).to.includes('✓ SemVer Policy'); }); - - it('ignoredDependencies merged from cli and config', async function () { - const child = await runSupportedCmd([ - `${__dirname}/fixtures/unsupported-project`, - `-f ${__dirname}/fixtures/unsupported-project/config-ignore-dep.json`, - `-i @eslint-ast/eslint-plugin-graphql`, - `-i es6-promise`, - ]); - - expect(child).to.exitGracefully(); - expect(child.stderr).to.includes('Ignored: 4'); - }); }); describe('Filter options like --unsupported/expiring/supported', function () { @@ -433,7 +391,7 @@ describe('CLI', function () { it('make unsupported to supported project using upgradeBudget', async function () { const child = await runSupportedCmd([ `${__dirname}/fixtures/unsupported-project`, - `--config-file ${__dirname}/fixtures/unsupported-project/config_2.json`, + `--config-file ${__dirname}/fixtures/unsupported-project/config-custom-budget.json`, ]); expect(child).to.exitGracefully(); @@ -453,8 +411,7 @@ describe('CLI', function () { it('alert user when there is conflict in custom config and ignoredDependency', async function () { const child = await runSupportedCmd([ `${__dirname}/fixtures/unsupported-project`, - `-f ${__dirname}/fixtures/unsupported-project/config.json`, - `-i es6-promise`, + `-f ${__dirname}/fixtures/unsupported-project/config-ignore-dep-conflict.json`, ]); expect(child.stderr).includes( `The dependency es6-promise was found in ignoredDependencies and custom configuration. Please refer Rules section in configuration.md`, diff --git a/tests/fixtures/unsupported-project/config_2.json b/tests/fixtures/unsupported-project/config-custom-budget.json similarity index 100% rename from tests/fixtures/unsupported-project/config_2.json rename to tests/fixtures/unsupported-project/config-custom-budget.json diff --git a/tests/fixtures/unsupported-project/config-ignore-dep-conflict.json b/tests/fixtures/unsupported-project/config-ignore-dep-conflict.json new file mode 100644 index 0000000..dcc6aa9 --- /dev/null +++ b/tests/fixtures/unsupported-project/config-ignore-dep-conflict.json @@ -0,0 +1,11 @@ +{ + "primary": { + "ignoredDependencies": ["es6-promise", "@stefanpenner/a", "rsvp"] + }, + "custom": [ + { + "dependencies": ["es6-promise"], + "effectiveReleaseDate": "Dec 10 2022" + } + ] +} \ No newline at end of file From 93c4a36fa737ebeaa66e2f841c330a4b6503ade5 Mon Sep 17 00:00:00 2001 From: sparshithNR Date: Wed, 23 Jun 2021 14:23:54 -0700 Subject: [PATCH 8/9] adding more tests --- tests/cli-test.js | 26 ++++++++++++++++++++ tests/fixtures/supported-project/config.json | 5 ++++ 2 files changed, 31 insertions(+) create mode 100644 tests/fixtures/supported-project/config.json diff --git a/tests/cli-test.js b/tests/cli-test.js index 453c25e..3defe08 100644 --- a/tests/cli-test.js +++ b/tests/cli-test.js @@ -181,6 +181,32 @@ describe('CLI', function () { }); describe(`ignore-dependencies`, function () { + it('check console log', async function () { + const child = await runSupportedCmd([ + `${__dirname}/fixtures/supported-project`, + `-f ${__dirname}/fixtures/supported-project/config.json`, + ]); + + expect(child).to.exitGracefully(); + expect(child.stderr).to.includes(`Ignored: 2`); + expect(child.stderr).to.includes('✓ SemVer Policy'); + expect(child.stdout).to.includes('Congrats!'); + }); + + it('check if verbose do not incude the entry', async function () { + const child = await runSupportedCmd([ + `${__dirname}/fixtures/supported-project`, + `-f ${__dirname}/fixtures/supported-project/config.json`, + '--verbose', + ]); + + expect(child).to.exitGracefully(); + expect(child.stderr).to.includes(`Ignored: 2`); + expect(child.stderr).to.includes('✓ SemVer Policy'); + expect(child.stdout).to.includes('Congrats!'); + expect(child.stdout).not.include('@stefanpenner/a'); + }); + it('make unsupported to supported project using ignoreDependency config', async function () { const child = await runSupportedCmd([ `${__dirname}/fixtures/unsupported-project`, diff --git a/tests/fixtures/supported-project/config.json b/tests/fixtures/supported-project/config.json new file mode 100644 index 0000000..d2b8546 --- /dev/null +++ b/tests/fixtures/supported-project/config.json @@ -0,0 +1,5 @@ +{ + "primary": { + "ignoredDependencies": ["@stefanpenner/a", "rsvp"] + } +} \ No newline at end of file From 087839cf2a8b1c09c1ae2f37a71bcb524c546fb0 Mon Sep 17 00:00:00 2001 From: sparshithNR Date: Wed, 23 Jun 2021 14:43:19 -0700 Subject: [PATCH 9/9] check the exit status. --- tests/cli-test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/cli-test.js b/tests/cli-test.js index 3defe08..51ac2c1 100644 --- a/tests/cli-test.js +++ b/tests/cli-test.js @@ -429,6 +429,7 @@ describe('CLI', function () { `${__dirname}/fixtures/unsupported-project`, `-f ${__dirname}/fixtures/unsupported-project/config-conflict.json`, ]); + expect(child).not.to.exitGracefully(); expect(child.stderr).includes( `The dependency es6-promise was found multiple times in the config file. Please refer Rules section in configuration.md`, ); @@ -439,6 +440,7 @@ describe('CLI', function () { `${__dirname}/fixtures/unsupported-project`, `-f ${__dirname}/fixtures/unsupported-project/config-ignore-dep-conflict.json`, ]); + expect(child).not.to.exitGracefully(); expect(child.stderr).includes( `The dependency es6-promise was found in ignoredDependencies and custom configuration. Please refer Rules section in configuration.md`, );