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

Ghost testing #2027

Merged
merged 20 commits into from
Aug 19, 2022
Merged

Ghost testing #2027

merged 20 commits into from
Aug 19, 2022

Conversation

cristiano-belloni
Copy link
Contributor

@cristiano-belloni cristiano-belloni commented Aug 11, 2022

Ghost testing

This PR implements three new options for the test command, which:

  • Enable testing only changed workspaces, where "changed" means "containing files that are flagged as changed by Git, compared to a certain branch"
  • Enable testing only changed workspaces as above, plus all their ancestors (i.e. the workspaces that directly or indirectly depend on them)
  • Allow the user to specify the comparison branch (by default it's the default Git branch)

Docs for modular test:

--ancestors

Default: false

Can be used only in combination with changed or the command will fail. If set,
it will additionally execute tests for all the workspaces that (directly or
indirectly) depend on the workspaces selected by changed.

--changed

Default: false

Execute tests only for the workspaces that contain files that have changed.
Files that have changed are calculated comparing the current state of the
repository with the branch specified by compareBranch or, if compareBranch
is not set, with the default git branch.

--compareBranch

Default: undefined

Specify the comparison branch used to determine which files have changed when
using the changed option. If this option is used without changed, the
command will fail.

TODO:

  • --changed <branch> testing only changed workspaces
  • --changed boolean separated from --compareBranch <branch>
  • --ancestors testing only changed workspaces and their ancestors
  • Option validation: --ancestors only with --changed
  • Option validation: --changed without regexes
  • High-level API that takes WorkspaceContents and return WorkspaceContent with ancestors
  • modular-scripts docs
  • workspace-resolver docs (add high level API)
  • Unit tests
  • Integration tests

@changeset-bot
Copy link

changeset-bot bot commented Aug 11, 2022

🦋 Changeset detected

Latest commit: 876b607

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
modular-scripts Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coveralls
Copy link
Collaborator

coveralls commented Aug 11, 2022

Coverage Status

Coverage decreased (-0.09%) to 33.953% when pulling 876b607 on feature/ghost-testing into 18270b1 on main.

);
process.exit(1);
}

const { default: test } = await import('./test');
Copy link
Contributor

Choose a reason for hiding this comment

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

Does importing ./test have side-effects?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case it doesn't need a dynamic import - not something that's part of your PR, but might be easier to follow as a standard import at the top of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@steveukx in program.ts we parse the command line args and we decide which Modular command to execute. If we statically imported all of them at the start (which is translated to sync require in cjs world), it'd be a performance hit proportional to the quantity of commands.

.option(
'--debug',
'Setup node.js debugger on the test process - equivalent of setting --inspect-brk on a node.js process',
false,
)
.option(
'--changed <branch>',
Copy link
Contributor

Choose a reason for hiding this comment

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

To allow for the future state of having --changed on its own to use the default / PR head, should this be a boolean with another option of --compare-branch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, it'd be clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@cristiano-belloni cristiano-belloni marked this pull request as ready for review August 17, 2022 13:10
Copy link
Contributor

@sgb-io sgb-io left a comment

Choose a reason for hiding this comment

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

LGTM

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.

4 participants