kefranabg / readme-md-generator

📄 CLI that generates beautiful README.md files
https://www.npmjs.com/package/readme-md-generator
MIT License
10.9k stars 1.37k forks source link

Change test snapshot copyright year to 2021. #217

Closed sehnsucht13 closed 3 years ago

sehnsucht13 commented 3 years ago

Hello!

I wanted to play around with this project for a bit and noticed that some of the tests were failing right after cloning the project. After investigating, I found that 4 tests were failing because the Jest snapshot used to compare the generated readme in the test suite had an outdated year for copyright. I have bumped the year from 2019 to 2021 and now all tests pass.

sehnsucht13 commented 3 years ago

There is also another possibility that seems more sustainable. The problem is with these two lines of the snapshot:

  1. Copyright © 2019 [Franck Abgrall](https://github.com/kefranabg).<br />
  2. Copyright © 2019 [Franck Abgrall](https://github.com/kefranabg).

When the tests are ran, the generated README file has a copyright year of 2021 since it uses the current year and this does not match the snapshot. Take a look at one of the failing tests:

    it('should return readme default template no html content', async () => {
      const result = await buildReadmeContent(
        context,
        defaultNoHtmlTemplatePath
      )

      expect(result).toMatchSnapshot()
    })

The failing tests can instead be change to this:

    it('should return readme default template no html content', async () => {
      const result = await buildReadmeContent(
        context,
        defaultNoHtmlTemplatePath
      )
      const currentDate = new Date()
      expect(
        result.replace(currentDate.getFullYear(), '2019')
      ).toMatchSnapshot()
    })

This approach will let the original snapshot pass the tests and avoid the issue of having to bump the snapshot copyright year every time the year changes.

Let me know what you think.