Skip to content

Refactor to decouple tests - #11812

Closed
sleepwithcoffee wants to merge 1 commit into
serverless:mainfrom
sleepwithcoffee:2582_decouple_tests
Closed

sleepwithcoffee wants to merge 1 commit into
serverless:mainfrom
sleepwithcoffee:2582_decouple_tests

Conversation

@sleepwithcoffee

@sleepwithcoffee sleepwithcoffee commented Mar 14, 2023 •

Copy link
Copy Markdown
Contributor

Addresses: #2582

Refactor tests used in #11796

  • Make sure each test has different set of inputs so that they don't co-dependant
  • Fix/harden some test conditions e.g. check both awsPlugin.options.stage and awsPlugin.provider.getStage()

@codecov

codecov Bot commented Mar 14, 2023

Copy link
Copy Markdown

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.04 🎉

Comparison is base (19c2bb8) 86.56% compared to head (a33ddd6) 86.60%.

❗ Current head a33ddd6 differs from pull request most recent head 98c241e. Consider uploading reports for the commit 98c241e to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11812      +/-   ##
==========================================
+ Coverage   86.56%   86.60%   +0.04%     
==========================================
  Files         314      314              
  Lines       13128    13161      +33     
==========================================
+ Hits        11364    11398      +34     
+ Misses       1764     1763       -1     
Impacted Files Coverage Δ
...kage/compile/events/api-gateway/lib/authorizers.js 100.00% <ø> (ø)
...ile/events/api-gateway/lib/method/authorization.js 100.00% <ø> (ø)
lib/plugins/aws/package/compile/events/activemq.js 100.00% <100.00%> (ø)
...ws/package/compile/events/alb/lib/target-groups.js 100.00% <100.00%> (ø)
.../plugins/aws/package/compile/events/alexa-skill.js 96.29% <100.00%> (ø)
...ins/aws/package/compile/events/alexa-smart-home.js 100.00% <100.00%> (ø)
...age/compile/events/api-gateway/lib/method/index.js 100.00% <100.00%> (ø)
...ns/aws/package/compile/events/cloud-watch-event.js 97.77% <100.00%> (+0.05%) ⬆️
...gins/aws/package/compile/events/cloud-watch-log.js 100.00% <100.00%> (ø)
...ns/aws/package/compile/events/cognito-user-pool.js 100.00% <100.00%> (ø)
... and 14 more

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@medikoo medikoo left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sleepwithcoffee thanks for taking care of that.

Still to ensure best reliability all tests refactor should be done in a way so new tests run with runServerless util. See https://github.com/serverless/serverless/tree/main/test#unit-tests

And as I checked in more detail we can totally remove the validate.test.js file as:

  1. Som tests confirm implementation details (we should not write such tests, and we're ok to remove them
  2. Stage resolution is already well tested here:
    describe('#getStage()', () => {
    it('should default to "dev"', async () => {
    const { serverless } = await runServerless({
    fixture: 'aws',
    command: 'print',
    });
    expect(serverless.getProvider('aws').getStage()).to.equal('dev');
    });
    it('should allow to override via `provider.stage`', async () => {
    const { serverless } = await runServerless({
    fixture: 'aws',
    command: 'print',
    configExt: {
    provider: {
    stage: 'staging',
    },
    },
    });
    expect(serverless.getProvider('aws').getStage()).to.equal('staging');
    });
    it('should allow to override via CLI `--stage` param', async () => {
    const { serverless } = await runServerless({
    fixture: 'aws',
    command: 'print',
    options: { stage: 'production' },
    configExt: {
    provider: {
    stage: 'staging',
    },
    },
    });
    expect(serverless.getProvider('aws').getStage()).to.equal('production');
    });
    });
  3. Region resolution is already tested here:
    describe('#getRegion()', () => {
    it('should default to "us-east-1"', async () => {
    const { serverless } = await runServerless({
    fixture: 'aws',
    command: 'print',
    });
    expect(serverless.getProvider('aws').getRegion()).to.equal('us-east-1');
    });
    it('should allow to override via `provider.region`', async () => {
    const { serverless } = await runServerless({
    fixture: 'aws',
    command: 'print',
    configExt: {
    provider: {
    region: 'eu-central-1',
    },
    },
    });
    expect(serverless.getProvider('aws').getRegion()).to.equal('eu-central-1');
    });
    it('should allow to override via CLI `--region` param', async () => {
    const { serverless } = await runServerless({
    fixture: 'aws',
    command: 'print',
    options: { region: 'us-west-1' },
    configExt: {
    provider: {
    region: 'eu-central-1',
    },
    },
    });
    expect(serverless.getProvider('aws').getRegion()).to.equal('us-west-1');
    });
    });

In light of that, I've just removed this test file from the repository: 2e004eb

So, sorry you've taken an effort on that, but at least it moved us into right direction of removing this test file :)

@medikoo medikoo closed this Mar 15, 2023
@sleepwithcoffee

Copy link
Copy Markdown
Contributor Author

sure @medikoo let me look further into this since I am also not confident about this approach.
Even though the tests are decoupled but they are generated from dynamic code, not with static inputs. So errors can creep in in the tests.

Let me look around and think a bit more if we are ok to remove these tests, or can modify them in a meaningful way given we already have similar tests in other places.

@sleepwithcoffee
sleepwithcoffee deleted the 2582_decouple_tests branch March 15, 2023 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants