scolladon / sfdx-git-delta

Generate the sfdx content in source format from two git commits
Other
414 stars 112 forks source link

Jest tests copied to output folder when using --generate-delta #744

Closed mmindenhall closed 8 months ago

mmindenhall commented 8 months ago

Issue verification check:

What is the problem?

My employer has been gradually building jest tests for LWCs.

When there are changes in the source of an LWC with jest tests, sgd --generate-delta copies the __tests__ folder (contains the jest test sources) to the output folder, despite the .forceignore passed to sgd specifying that this folder should be ignored.

What is the parameter and the value you used with it?

See reproduction steps below.

What is the expected result?

The expected result is that the output folder would not contain the __tests__ folder for any LWC with jest tests.

What is the actual result?

The output folder contains the __tests__ folder and its contents, which causes the subsequent sf force source deploy -p /tmp/output/folder command to fail due to the jest .js file(s) not being deployable.

Steps to reproduce

  1. Clone my sfdx-git-delta-reproduction-playground fork
  2. Check out the issue/744 branch
  3. Run this command:

    $ sf sgd source delta --from HEAD~1 --to HEAD --source sgd --output output --ignore .forceignore --generate-delta --json
  4. Verify that the __tests__ folder was copied into the tree in the output folder

Execution context


Operating System: … Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:43 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T6000 yarn version: … 1.22.19 node version: … v18.16.0 git version: … git version 2.43.0 sfdx version: … @salesforce/cli/2.21.8 darwin-arm64 node-v18.16.0 sgd plugin version: … sfdx-git-delta 5.31.1

More information (optional)


scolladon commented 8 months ago

Hi @mmindenhall!

Thanks for raising this very well detailed issue and thanks for contributing in making this project better!

What is the content of the .forceignore file used to ignore __tests__ folders please?

Do you reproduce it with any LWC component ? Or some of them have particularities?

mmindenhall commented 8 months ago

Hi @scolladon!

Here's the .forceignore for the package where we encountered this problem.

# List files or directories below to ignore them when running force:source:push, force:source:pull, and force:source:status
# More information: https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_exclude_source.htm
#
package.xml
# LWC configuration files
**/jsconfig.json
**/.eslintrc.json
# LWC Jest
**/__tests__/**
# Profiles
**/force-app/main/default/profiles/**
# Fields
**/Contact/fields/CleanStatus.field-meta.xml
# Custom Index
**/force-app/main/default/customindex/**

**/AppSwitcher.appMenu-meta.xml
**/LightningService_UtilityBar.flexipage-meta.xml
**/profiles/**

I'm pretty sure the behavior will happen with any LWC component when using --generate-delta. The one I used to reproduce the problem in my fork of sfdx-git-delta-reproduction-playground was a simple Hello World LWC, using the .forceignore already in sfdx-git-delta-reproduction-playground.

mmindenhall commented 8 months ago

BTW I took a quick peek at the source code, and I think this is what's happening. The --ignore file is being used to filter files to process out of the git output, but no filtering is being applied in the copy operation to the output folder. I think the --ignore file patterns need to be applied in both places.

scolladon commented 8 months ago

Thank you for spiking a bit @mmindenhall. I see now what is happening here, I'll propose a fix next week hopefully.

Stay tuned!

github-actions[bot] commented 8 months ago

Shipped in release v5.32.0. You can install the new version using the version number or the latest-rc channel

$ sfdx plugins:install sfdx-git-delta@latest-rc
$ sfdx plugins:install sfdx-git-delta@v5.32.0

Happy incremental deployment!