Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/812 cli command to create test files #860

Conversation

fecony
Copy link
Contributor

@fecony fecony commented Jun 8, 2021

Description

CLI command to create example test file.

boost new:test SimpleTest

Will create test file (simple-test.test.ts) with following content in test/ folder:

import { BoosterConfig } from '@boostercloud/framework-types'
import { expect } from 'chai'

const config = new BoosterConfig('test')
config.appName = 'testing-booster-app' // <- app name

describe('[SimpleTestTest]', () => {
  it('should be true', () => {
    expect(true).to.be.true
  })
})

Test files use chai that is not installed by default in new projects.

Maybe it should be included or should print message after test file was created. "Run npm install -D chai @types/chai to install required dependencies" ?

Changes

  • Add new:test command to generate test file
  • Add new template for test files
  • Tests to test simple cases that test file is generated

Checks

  • Project Builds
  • Project passes tests and checks
    - [] Updated documentation accordingly

Additional Information

Closes #812

This command may be expanded to:

  • allow users create tests in subfolders
  • check if user has recommended expect.ts file
  • use another testing tools (as flag ?)

@NickSeagull
Copy link
Member

Thanks for this @fecony ! Actually this is a feature that the core team has been discussing internally, so this pushes it forward!

I'd like to hear more from the @boostercloud/booster-core team. Maybe @juanjoman can shed some light on his thoughts (I believe you were the one working on the draft on testing, right Juanjo?)

Copy link
Contributor

@juanjoman juanjoman left a comment

Choose a reason for hiding this comment

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

Amazing work @fecony!! I would just like to check that we're providing chai as we're importing it on the generated test. Could you check it? 🙏

Comment on lines +44 to +48
{
packagePath: 'chai',
commaSeparatedComponents: 'expect',
},
]
Copy link
Contributor

Choose a reason for hiding this comment

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

Just have a question, does the project's package.json includes chai as a dependency? 😮

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @juanjoman. That is something I mention in PR description "Test files use chai that is not installed by default in new projects." 😄

I think we should include chai as dependency because Booster docs use chai but we don't provide it by default? 😅

  • if chai is not in the project.json dependencies, what we should use as expect assertion instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@juanjoman I though about importing expect from ./expect if it exists, as we might expect it to be here (because it is recommended file)

If not, check if chai exists and import it instead. But if user doesn't have them? 🤔

Copy link
Contributor

@juanjoman juanjoman Jun 15, 2021

Choose a reason for hiding this comment

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

oooh sorry @fecony, I didn't read it 😓. I think it's ok then to import it from ./expect and let the user choose their test library, but we should document that 😄

@fecony fecony marked this pull request as draft June 15, 2021 09:26
@fecony
Copy link
Contributor Author

fecony commented Aug 4, 2022

Closing, as I have no time/knowledge which path to take. 😬

  • We could take the path of creating automated tests, as @ClaytonFarr did investigate, that was mentioned on Discord here
  • Take simple path and assume that user has expect.ts
  • Force user to use [insert testing library here]
  • Create Booster-specific test matchers expect(...).to.registerEvents(...)

@fecony fecony closed this Aug 4, 2022
@fecony fecony deleted the feature/812_cli-command-to-create-test-files branch August 4, 2022 17:43
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.

New CLI command to create test files
3 participants