From 44fc8a885d022f870c1679e83aee1b156c5260bd Mon Sep 17 00:00:00 2001 From: Honza Javorek Date: Fri, 10 Aug 2018 18:26:56 +0200 Subject: [PATCH] test: remove redundant tests They test something already tested and they should actually test the interplay between 'prompt' and 'applyAnswers' than the 'applyAnswers' alone. This should be handled by integration tests in the future. --- test/unit/cli-test.js | 121 +++------------------------- test/unit/init/applyAnswers-test.js | 12 --- 2 files changed, 9 insertions(+), 124 deletions(-) diff --git a/test/unit/cli-test.js b/test/unit/cli-test.js index 59cf87988..aee78c011 100644 --- a/test/unit/cli-test.js +++ b/test/unit/cli-test.js @@ -6,7 +6,6 @@ const sinon = require('sinon'); const { assert } = require('chai'); const configUtilsStub = require('../../src/config-utils'); -const interactiveConfigStub = require('../../src/interactive-config'); const loggerStub = require('../../src/logger'); const options = require('../../src/options'); const packageData = require('../../package.json'); @@ -32,11 +31,16 @@ const DreddStub = proxyquire('../../src/dredd', { './logger': loggerStub }); +const initStub = sinon.stub().callsFake((config, save, callback) => { + save(config); + callback(); +}); + const CLIStub = proxyquire('../../src/cli', { './dredd': DreddStub, console: loggerStub, './logger': loggerStub, - './interactive-config': interactiveConfigStub, + './init': initStub, './config-utils': configUtilsStub, fs: fsStub, 'cross-spawn': crossSpawnStub @@ -271,123 +275,17 @@ describe('CLI class', () => { it('prints out version', () => assert.include(stdout, `${packageData.name} v${packageData.version}`)); }); - describe('"init" (nodejs)', () => { - before((done) => { - sinon.stub(interactiveConfigStub, 'run').callsFake((argv, cb) => cb({ language: 'nodejs' })); - sinon.stub(configUtilsStub, 'save'); - execCommand({ argv: ['init'] }, () => done()); - }); - - after(() => { - interactiveConfigStub.run.restore(); - configUtilsStub.save.restore(); - }); - - it('should run interactive config', () => assert.isTrue(interactiveConfigStub.run.called)); - - it('should save configuration', () => assert.isTrue(configUtilsStub.save.called)); - }); - - describe('"init" (python)', () => { - before((done) => { - sinon.stub(interactiveConfigStub, 'run').callsFake((argv, cb) => cb({ language: 'python' })); - sinon.stub(configUtilsStub, 'save'); - execCommand({ argv: ['init'] }, () => done()); - }); - - after(() => { - interactiveConfigStub.run.restore(); - configUtilsStub.save.restore(); - }); - - it('should run interactive config', () => assert.isTrue(interactiveConfigStub.run.called)); - - it('should save configuration', () => assert.isTrue(configUtilsStub.save.called)); - }); - - - describe('"init" (php)', () => { - before((done) => { - sinon.stub(interactiveConfigStub, 'run').callsFake((argv, cb) => cb({ language: 'php' })); - sinon.stub(configUtilsStub, 'save'); - execCommand({ argv: ['init'] }, () => done()); - }); - - after(() => { - interactiveConfigStub.run.restore(); - configUtilsStub.save.restore(); - }); - - it('should run interactive config', () => assert.isTrue(interactiveConfigStub.run.called)); - - it('should save configuration', () => assert.isTrue(configUtilsStub.save.called)); - }); - - describe('"init" (ruby)', () => { + describe('init', () => { before((done) => { - sinon.stub(interactiveConfigStub, 'run').callsFake((argv, cb) => cb({ language: 'ruby' })); sinon.stub(configUtilsStub, 'save'); execCommand({ argv: ['init'] }, () => done()); }); after(() => { - interactiveConfigStub.run.restore(); configUtilsStub.save.restore(); }); - it('should run interactive config', () => assert.isTrue(interactiveConfigStub.run.called)); - - it('should save configuration', () => assert.isTrue(configUtilsStub.save.called)); - }); - - describe('"init" (perl)', () => { - before((done) => { - sinon.stub(interactiveConfigStub, 'run').callsFake((argv, cb) => cb({ language: 'perl' })); - sinon.stub(configUtilsStub, 'save'); - execCommand({ argv: ['init'] }, () => done()); - }); - - after(() => { - interactiveConfigStub.run.restore(); - configUtilsStub.save.restore(); - }); - - it('should run interactive config', () => assert.isTrue(interactiveConfigStub.run.called)); - - it('should save configuration', () => assert.isTrue(configUtilsStub.save.called)); - }); - - describe('"init" (go)', () => { - before((done) => { - sinon.stub(interactiveConfigStub, 'run').callsFake((argv, cb) => cb({ language: 'go' })); - sinon.stub(configUtilsStub, 'save'); - execCommand({ argv: ['init'] }, () => done()); - }); - - after(() => { - interactiveConfigStub.run.restore(); - configUtilsStub.save.restore(); - }); - - it('should run interactive config', () => assert.isTrue(interactiveConfigStub.run.called)); - - it('should save configuration', () => assert.isTrue(configUtilsStub.save.called)); - }); - - describe('"init" (rust)', () => { - before((done) => { - sinon.stub(interactiveConfigStub, 'run').callsFake((argv, cb) => cb({ language: 'rust' })); - sinon.stub(configUtilsStub, 'save'); - execCommand({ argv: ['init'] }, () => done()); - }); - - after(() => { - interactiveConfigStub.run.restore(); - configUtilsStub.save.restore(); - }); - - it('should run interactive config', () => assert.isTrue(interactiveConfigStub.run.called)); - + it('should run interactive config', () => assert.isTrue(initStub.called)); it('should save configuration', () => assert.isTrue(configUtilsStub.save.called)); }); @@ -418,7 +316,7 @@ describe('CLI class', () => { cb(null, stats); }); - sinon.stub(interactiveConfigStub, 'run').callsFake((config, cb) => cb()); + initStub.callsFake((config, cb) => cb()); sinon.stub(fsStub, 'existsSync').callsFake(() => true); @@ -457,7 +355,6 @@ describe('CLI class', () => { after(() => { DreddStub.prototype.run.restore(); DreddStub.prototype.init.restore(); - interactiveConfigStub.run.restore(); configUtilsStub.load.restore(); fsStub.existsSync.restore(); }); diff --git a/test/unit/init/applyAnswers-test.js b/test/unit/init/applyAnswers-test.js index 05e874814..971bcebe3 100644 --- a/test/unit/init/applyAnswers-test.js +++ b/test/unit/init/applyAnswers-test.js @@ -54,22 +54,10 @@ describe('init._applyAnswers()', () => { const config = applyAnswers(createConfig(), { apiaryApiKey: '1234' }); assert.equal(config.custom.apiaryApiKey, '1234'); }); - it('keeps the Apiary API key if already present in the config', () => { - const config = applyAnswers(Object(createConfig()), { - custom: { apiaryApiKey: '1234' } - }); - assert.equal(config.custom.apiaryApiKey, '1234'); - }); it('sets the Apiary API name if provided', () => { const config = applyAnswers(createConfig(), { apiaryApiName: 'myproject' }); assert.equal(config.custom.apiaryApiName, 'myproject'); }); - it('keeps the Apiary API name if already present in the config', () => { - const config = applyAnswers(Object(createConfig()), { - custom: { apiaryApiName: 'myproject' } - }); - assert.equal(config.custom.apiaryApiName, 'myproject'); - }); it('creates selected CI configuration if asked', () => { applyAnswers(createConfig(), { createCI: 'wercker' }, { ci }); assert.isTrue(ci.wercker.calledOnce);