Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

exclude test build files from packages #2005

Merged
merged 10 commits into from
Aug 24, 2021
Merged

Conversation

peter-hamilton
Copy link
Contributor

@peter-hamilton peter-hamilton commented Aug 19, 2021

Description

Tests aren't being type checked because they are excluded tsconfig.json files. If this exclusion is removed type-checking is applied, but the resultant test build files need to be excluded from the package.

This PR

  • adds the !build/ts/**/*.test.* file exclusion the to all package.json files. build/* include pattern was changed to build in order for the exclusion pattern to work properly.
  • removes test exclusion from tsconfig.json in cases where there aren't type errors. Most packages have type errors that will be addressed in the future. To check just remove the test patterns from the exclude section of tsconfig.json.
  • Also, renamed test/ directories to tests/ across all packages. This improved consistency removes the need to match multiple patterns for tests.

To test what files are included in a package, use npx npm-packlist from the package directory.

Type of change

  • in all Patch: Bug (non-breaking change which fixes an issue)

Checklist

  • I have added a changelog entry, prefixed by the type of change noted above (Documentation fix and Test update does not need a changelog as we do not publish new version)

@peter-hamilton peter-hamilton requested a review from a team August 19, 2021 23:54
@peter-hamilton peter-hamilton marked this pull request as ready for review August 19, 2021 23:57
"!build/*.tsbuildinfo",
"!build/ts/**/*.test.*",
"index.js",
Copy link
Contributor

@dahukish dahukish Aug 23, 2021

Choose a reason for hiding this comment

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

I think index.js get added but default no?

Copy link
Contributor

Choose a reason for hiding this comment

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

https://docs.npmjs.com/cli/v7/configuring-npm/package-json#files

Unless we are being explicit for clarity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true. Though I'd lean towards keeping it explicit.

"./src/**/*.tsx"
],
"exclude": ["**/*.test.ts", "**/*.test.tsx"]
"include": ["../../config/typescript/*.ts", "./src/**/*.ts", "./src/**/*.tsx"]
Copy link
Contributor

Choose a reason for hiding this comment

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

could these go in the base config if most packages follow the same pattern?

Copy link
Contributor

@dahukish dahukish left a comment

Choose a reason for hiding this comment

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

LGTM

@BPScott
Copy link
Member

BPScott commented Aug 23, 2021

!build/ts/**/*.test.* is good for excluding test files. I wonder if we should exclude the whole test / tests folders, as sometimes those folders contain utility files that are only used within tests: ls -d packages/*/src/**/test{,s}/** | grep -v '\.test\.' give you a list of them. Do you think doing "!build/ts/**/tests/" instead would be worth it?

Annoyingly it seems half of our tests live in folders called test and half live folders called tests (ls -d packages/*/src/**/tests | wc -l vs ls -d packages/*/src/**/test | wc -l). the Shopify convention tends to be naming tests folders tests (3999 usages of tests in web, vs 6 for test). That's pretty annoying as ignoring both folder names in package.json feels rubbish. Renaming all instances for test folders to tests is also gonna be noisy but I'm a sucker for conventions. Reckon it might be worth it?

.eslintignore Outdated
packages/graphql-config-utilities/src/tests/fixtures/**/*.graphql
packages/graphql-typescript-definitions/test/fixtures/**/*.graphql
packages/graphql-validate-fixtures/test/fixtures/**/*.graphql
packages/graphql-config-utilities/src/testss/fixtures/**/*.graphql
Copy link
Member

Choose a reason for hiding this comment

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

Double s here might be the cause of the linting failures

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. This was driving me nuts.

@peter-hamilton
Copy link
Contributor Author

!build/ts/**/*.test.* is good for excluding test files. I wonder if we should exclude the whole test / tests folders, as sometimes those folders contain utility files that are only used within tests: ls -d packages/*/src/**/test{,s}/** | grep -v '\.test\.' give you a list of them. Do you think doing "!build/ts/**/tests/" instead would be worth it?

Annoyingly it seems half of our tests live in folders called test and half live folders called tests (ls -d packages/*/src/**/tests | wc -l vs ls -d packages/*/src/**/test | wc -l). the Shopify convention tends to be naming tests folders tests (3999 usages of tests in web, vs 6 for test). That's pretty annoying as ignoring both folder names in package.json feels rubbish. Renaming all instances for test folders to tests is also gonna be noisy but I'm a sucker for conventions. Reckon it might be worth it?

test folders have been renamed to tests.

Copy link
Member

@BPScott BPScott left a comment

Choose a reason for hiding this comment

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

Looking pretty great!

I think I spotted two little things to tweak inline. fixup those two and I think we're good to go!

I see there's till many mentions of **/test/** in tsconfig files but I guess those are the problematic packages and those entire exclude declarations shall be removed in follow up PRs

packages/csrf-token-fetcher/tsconfig.json Outdated Show resolved Hide resolved
@@ -4,6 +4,5 @@
"outDir": "build/ts",
"rootDir": "src",
"baseUrl": "src"
},
"include": ["./src/**/*.ts"]
Copy link
Member

Choose a reason for hiding this comment

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

i think this needs to stay

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted.

peter-hamilton and others added 2 commits August 24, 2021 12:09
@peter-hamilton peter-hamilton merged commit 72e53fe into main Aug 24, 2021
@peter-hamilton peter-hamilton deleted the exclude-test-files branch August 24, 2021 16:21
@shopify-shipit shopify-shipit bot temporarily deployed to production August 24, 2021 19:46 Inactive
@shopify-shipit shopify-shipit bot temporarily deployed to michenly-beta August 26, 2021 17:50 Inactive
@shopify-shipit shopify-shipit bot temporarily deployed to gem August 30, 2021 18:42 Inactive
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants