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

feat: restructure project with src/ and build/ #307

Merged
merged 1 commit into from
Sep 17, 2019

Conversation

wtho
Copy link
Collaborator

@wtho wtho commented Sep 14, 2019

Problem

More and more js files such as serializers were located in the root of the project separated from ts src files, while these ts files also got transpiled to the root folder. This creates a non-transparent file mix with compiled and source files in the same place.

PR

To keep source files in a single place, most js files are now located in the src folder as well. A build folder will be created on npm run build, yarn build or npm run prepare, as configured in tsconfig.json.

The TypeScript compiler transpiles the ts files and conventiently copies the js files to the build folder. This means the js files are not changed by the tsc.

I kept the index.js and jest-preset.js in the root folder, as otherwise the preset would not be referenceable as just jest-preset-angular from the jest config.

All other js files, such as transformers and serializers have to be referenced as jest-preset-angular/build/... now. This makes this change a breaking change, as many users will have to adjust their configuration.

On the other hand this makes it much more easy for us maintainers and new contributers to work with the source files, as the project setup is more intuitive.

The naming of build was inspired by facebook/jest.

README.md Show resolved Hide resolved
@wtho wtho requested a review from thymikee September 16, 2019 11:09
}
}
}
}
```

If you choose to overide `globals` in order to point at a specific tsconfig, you will need to add `"astTransformers": ["jest-preset-angular/InlineHtmlStripStylesTransformer"]` to the `globals.ts-jest` section too, otherwise you will get parse errors on any html templates.
If you choose to overide `globals` in order to point at a specific tsconfig, you will need to add the `astTransformers` to the `globals.ts-jest` section too, otherwise you will get parse errors on any html templates.
Copy link
Owner

Choose a reason for hiding this comment

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

How about linking to the specific lines in the source file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The Custom tsconfig with the full example part is just right above this line, I think that is easy enough to copy. If we link the full preset, they might copy wrong parts, like "astTransformer": ["./build/Transformer"], so I actually prefer this style.

Plus the configuration is linked on the very top of the README.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

image

@@ -24,21 +24,21 @@ describe('importing ES6 reflect', () => {
jest.mock('core-js/es6/reflect', () => { throw coreJs2Error }, { virtual: true });
jest.mock('core-js/es/reflect', () => { throw coreJs3Error }, { virtual: true });

expect(() => require('../setupJest')).toThrow('core-js es6-reflect not found!');
expect(() => require('../src/setupJest')).toThrow('core-js es6-reflect not found!');
Copy link
Owner

Choose a reason for hiding this comment

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

let's move this test into src/ instead :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just put it inside src/: src/CoreJS-es6-reflect.test.ts, better have a look at the folder structure in this branch.

Is this ok? The __snapshot__ folder also lives inside src/ now. Or do you think we should separate them somewhat from the source files?

IMO with the relative small amount of source files it is ok to keep them in one folder for now.

Copy link
Collaborator

@ahnpnl ahnpnl Sep 17, 2019

Choose a reason for hiding this comment

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

Hmm why don't we leave test files in src/__tests__ ? I think it's better and it's a pattern used by each jest package folder too

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right! I argued with being inspired by the facebook/jest setup!

Would you put the tsconfig.spec.json for the preset tests inside there too?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that makes sense 👍

src/setupJest.ts Outdated Show resolved Hide resolved
@thymikee
Copy link
Owner

👍

To keep source files in a single place, most js files are now located in
the src folder as well. The TypeScript compiler transpiles the ts files
and copies the js files to the build folder.
.npmignore Show resolved Hide resolved
package.json Show resolved Hide resolved
@@ -11,5 +11,5 @@
"types": ["node"]
},
"include": ["src"],
"exclude": []
"exclude": ["**/__tests__"]
Copy link
Owner

Choose a reason for hiding this comment

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

do we need to exclude tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, otherwise tsc will also compile src/__tests__/** to build/

@ahnpnl ahnpnl merged commit 7c72e93 into thymikee:master Sep 17, 2019
@wtho wtho deleted the feat/build-folder branch September 17, 2019 11:49
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.

3 participants